Skip to content

Commit

Permalink
Fix wrong draft counter and config set
Browse files Browse the repository at this point in the history
  • Loading branch information
Corentin Mors committed Jun 16, 2024
1 parent 5701feb commit 215c00f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
16 changes: 11 additions & 5 deletions src/background/endpoints/getLatestDataFromGitLab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,17 @@ export const getLatestDataFromGitLab = async (): Promise<void> => {
(merge) => merge.author.id !== currentUser.id
);

const mrReceivedDetails = await fetchMRExtraInfo({
gitlabApi,
mrList: requests,
gitlabCE: settings.accounts[0].gitlabCE
});
const mrReceivedDetails = (
await fetchMRExtraInfo({
gitlabApi,
mrList: requests,
gitlabCE: settings.accounts[0].gitlabCE
})
).filter(
(mr) =>
settings.accounts[0].draftInToReviewTab ||
(!settings.accounts[0].draftInToReviewTab && !mr.work_in_progress)
);

let mrToReview = 0;
mrReceivedDetails.forEach((mr) => {
Expand Down
11 changes: 10 additions & 1 deletion src/common/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import * as browser from 'webextension-polyfill';
import { TabId } from '../common/types';
import { Configuration, TabId } from '../common/types';
import { config } from '../config/config';

export const updateConfiguration = async (objectToStore: Record<string, any>): Promise<void> => {
await browser.storage.local.set(objectToStore);
console.log('Configuration Updated');
};

export const updateAccountConfiguration = async (
accountIndex: number,
objectToStore: Record<string, any>
): Promise<void> => {
const settings = await readConfiguration<Configuration>(['accounts']);
settings.accounts[accountIndex] = { ...settings.accounts[accountIndex], ...objectToStore };
await updateConfiguration({ accounts: settings.accounts });
};

export const readConfiguration = async <T>(keys: string[]): Promise<T> => {
return browser.storage.local.get(keys).then((settings) => {
if (typeof settings.defaultTab === 'number') {
Expand Down
12 changes: 6 additions & 6 deletions src/options/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
FileDirectoryIcon
} from '@primer/octicons-react';
import './style.css';
import { updateConfiguration, readConfiguration } from '../common/configuration';
import { updateConfiguration, readConfiguration, updateAccountConfiguration } from '../common/configuration';
import { Account, TabId } from '../common/types';

const getSettings = readConfiguration<{
Expand Down Expand Up @@ -72,18 +72,18 @@ export const App = () => {

const updateGitlabCE = async (event: any) => {
setGitlabCE(event.target.checked);
await updateConfiguration({ gitlabCE: event.target.checked });
await updateAccountConfiguration(0, { gitlabCE: event.target.checked });
};

const updateGitlabToken = async (event: any) => {
setGitlabToken(event.target.value);
await updateConfiguration({ gitlabToken: event.target.value });
await updateAccountConfiguration(0, { gitlabToken: event.target.value });
setIsGitlabTokenInLocalStorage(true);
};

const updateGitlabAddress = async (event: any) => {
setGitlabAddress(event.target.value);
await updateConfiguration({ gitlabAddress: event.target.value });
await updateAccountConfiguration(0, { gitlabAddress: event.target.value });
setIsGitlabAddressInLocalStorage(true);
};

Expand All @@ -107,12 +107,12 @@ export const App = () => {

const updateDraftInToReviewTab = async (event: any) => {
setDraftInToReviewTab(event.target.checked);
await updateConfiguration({ draftInToReviewTab: event.target.checked });
await updateAccountConfiguration(0, { draftInToReviewTab: event.target.checked });
};

const updateProjectDirectoryPrefix = async (event: any) => {
setProjectDirectoryPrefix(event.target.value);
await updateConfiguration({ projectDirectoryPrefix: event.target.value });
await updateAccountConfiguration(0, { projectDirectoryPrefix: event.target.value });
};

const testConnection = useCallback(() => {
Expand Down

0 comments on commit 215c00f

Please sign in to comment.