Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ransome1 committed Jan 13, 2024
1 parent 4ae30f5 commit a668c94
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 112 deletions.
53 changes: 26 additions & 27 deletions src/main/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const configStorage: Store<Settings> = new Store<Settings>({
},
migrations: {
'2.0.0': store => {
store.set('sorting', [
store.setConfig('sorting', [
{ id: '1', value: 'priority', invert: false },
{ id: '2', value: 'projects', invert: false },
{ id: '3', value: 'contexts', invert: false },
Expand All @@ -42,7 +42,7 @@ const configStorage: Store<Settings> = new Store<Settings>({
{ id: '8', value: 'rec', invert: false },
{ id: '9', value: 'pm', invert: false },
]);
store.set('accordionOpenState', [
store.setConfig('accordionOpenState', [
true,
true,
true,
Expand All @@ -53,44 +53,43 @@ const configStorage: Store<Settings> = new Store<Settings>({
false,
false
]);
store.set('files', []);
store.set('appendCreationDate', false);
store.set('showCompleted', true);
store.set('showHidden', false);
store.set('windowMaximized', false);
store.set('fileSorting', false);
store.set('convertRelativeToAbsoluteDates', true);
store.set('thresholdDateInTheFuture', true);
store.set('colorTheme', 'system');
store.set('shouldUseDarkColors', false);
store.set('notificationsAllowed', true);
store.set('notificationThreshold', 2);
store.set('showFileTabs', true);
store.set('isNavigationOpen', true);
store.set('customStylesPath', customStylesPath);
store.set('tray', false);
store.set('zoom', 100);
store.set('multilineTextField', false);
store.set('useMultilineForBulkTodoCreation', false);
store.set('matomo', true);
store.setConfig('files', []);
store.setConfig('appendCreationDate', false);
store.setConfig('showCompleted', true);
store.setConfig('showHidden', false);
store.setConfig('windowMaximized', false);
store.setConfig('fileSorting', false);
store.setConfig('convertRelativeToAbsoluteDates', true);
store.setConfig('thresholdDateInTheFuture', true);
store.setConfig('colorTheme', 'system');
store.setConfig('shouldUseDarkColors', false);
store.setConfig('notificationsAllowed', true);
store.setConfig('notificationThreshold', 2);
store.setConfig('showFileTabs', true);
store.setConfig('isNavigationOpen', true);
store.setConfig('customStylesPath', customStylesPath);
store.setConfig('tray', false);
store.setConfig('zoom', 100);
store.setConfig('multilineTextField', false);
store.setConfig('useMultilineForBulkTodoCreation', false);
store.setConfig('matomo', true);
},
'2.0.1': store => {
store.set('anonymousUserId', anonymousUserId);
store.setConfig('anonymousUserId', anonymousUserId);
},
'2.0.2': store => {
store.set('dueDateInTheFuture', true);
store.setConfig('dueDateInTheFuture', true);
},
'2.0.4': store => {
store.delete('multilineTextField');
store.delete('isDrawerOpen');
store.delete('useMultilineForBulkTodoCreation');
store.set('bulkTodoCreation', false);
store.set('disableAnimations', false);
store.setConfig('bulkTodoCreation', false);
store.setConfig('disableAnimations', false);
},
}
});

const filtersPath = path.join(userDataDirectory, 'filters.json');
const filterStorage = new Store<Filters>({ cwd: userDataDirectory, name: 'filters' });

if(!filterStorage.has('search')) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/modules/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function createMenu(files: FileObject[]) {
label: 'Reset filters',
accelerator: 'CmdOrCtrl+0',
click: async () => {
filterStorage.set('filters', {});
filterStorage.set('attributes', {});
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { contextBridge, ipcRenderer } from 'electron';

contextBridge.exposeInMainWorld('api', {
store: {
get(key) {
getConfig(key) {
return ipcRenderer.sendSync('storeGetConfig', key);
},
set(property, value) {
setConfig(property, value) {
ipcRenderer.send('storeSetConfig', property, value);
},
setFilters(property, value) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const translatedAttributes = (t: typeof i18n.t) => ({
});

const App = () => {
const [settings, setSettings] = useState<Settings>(store.get());
const [settings, setSettings] = useState<Settings>(store.getConfig());
const [snackBarOpen, setSnackBarOpen] = useState<boolean>(false);
const [snackBarContent, setSnackBarContent] = useState<string | null>(null);
const [snackBarSeverity, setSnackBarSeverity] = useState<AlertColor | undefined>();
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogContent from '@mui/material/DialogContent';
import DialogActions from '@mui/material/DialogActions';
import AlertColor from '@mui/material/AlertColor';
import { AlertColor } from '@mui/material/Alert';
import { withTranslation, WithTranslation } from 'react-i18next';
import dayjs from 'dayjs';
import AutoSuggest from './AutoSuggest';
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/Drawer/Attributes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const DrawerAttributes: React.FC<Props> = memo(({
const handleAccordionToggle = (index: number) => {
const updatedAccordionOpenState = settings.accordionOpenState;
updatedAccordionOpenState[index] = !updatedAccordionOpenState[index];
store.set('accordionOpenState', updatedAccordionOpenState);
store.setConfig('accordionOpenState', updatedAccordionOpenState);
};

useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const DrawerComponent: React.FC<Props> = memo(({
t
}) => {
const [activeTab, setActiveTab] = useState<string>('attributes');
const [drawerWidth, setDrawerWidth] = useState<number>(store.get('drawerWidth') || 500);
const [drawerWidth, setDrawerWidth] = useState<number>(store.getConfig('drawerWidth') || 500);
const containerRef = useRef<HTMLDivElement | null>(null);
const startXRef = useRef<number>(0);

Expand Down Expand Up @@ -60,7 +60,7 @@ const DrawerComponent: React.FC<Props> = memo(({
const handleKeyDown = (event: KeyboardEvent) => {
const isSearchFocused = document.activeElement === searchFieldRef.current;
if(!isSearchFocused && event.key === 'Escape') {
store.set('isDrawerOpen', false);
store.setConfig('isDrawerOpen', false);
}
};

Expand All @@ -76,7 +76,7 @@ const DrawerComponent: React.FC<Props> = memo(({
}, [settings.isDrawerOpen]);

useEffect(() => {
store.set('drawerWidth', drawerWidth);
store.setConfig('drawerWidth', drawerWidth);
}, [drawerWidth]);

return (
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/Drawer/Filters.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { MouseEvent } from 'react';
import Link from '@mui/material/Link';
import FormGroup from '@mui/material/FormGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
Expand Down Expand Up @@ -26,24 +26,24 @@ const visibleSettings = {
},
};

const handleHelpClick = (event, url) => {
const handleHelpClick = (event: MouseEvent, url: string) => {
event.preventDefault();
event.stopPropagation();
if(url) {
ipcRenderer.send('openInBrowser', url)
}
};

const handleChange = (event, settingName, value) => {
store.set(settingName, value);
const handleChange = (settingName: string, value: string | boolean) => {
store.setConfig(settingName, value);
};

interface Props extends WithTranslation {
interface DrawerFiltersProps extends WithTranslation {
settings: Settings;
t: typeof i18n.t;
}

const DrawerFilters: React.FC<Props> = ({
const DrawerFilters: React.FC<DrawerFiltersProps> = ({
settings,
t
}) => {
Expand All @@ -58,7 +58,7 @@ const DrawerFilters: React.FC<Props> = ({
<Switch
data-testid={`setting-toggle-${settingName}`}
checked={settings[settingName as keyof Settings]}
onChange={(event) => handleChange(event, settingName, event.target.checked)}
onChange={(event) => handleChange(settingName, event.target.checked)}
name={settingName}
/>
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/Drawer/Sorting/DraggableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const DraggableList: React.FC<DraggableListProps> = ({
};

useEffect(() => {
store.set('sorting', accordionOrder);
store.setConfig('sorting', accordionOrder);
}, [accordionOrder]);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/Drawer/Sorting/Sorting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const DrawerSorting: React.FC<Props> = ({
control={
<Switch
checked={settings[settingName as keyof Settings]}
onChange={(event) => store.set(settingName, event.target.checked)}
onChange={(event) => store.setConfig(settingName, event.target.checked)}
name={settingName}
/>
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const HeaderComponent: React.FC<Props> = memo(({
);

const handleOnClick = () => {
store.set('isSearchOpen', !settings.isSearchOpen);
store.setConfig('isSearchOpen', !settings.isSearchOpen);
}

useEffect(() => {
Expand Down
Loading

0 comments on commit a668c94

Please sign in to comment.