Skip to content

Commit 23250ae

Browse files
authored
refactor: config settings types (#2417)
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent 65c7d67 commit 23250ae

File tree

4 files changed

+72
-22
lines changed

4 files changed

+72
-22
lines changed

src/renderer/components/filters/FilterSection.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import type { Icon } from '@primer/octicons-react';
44
import { Stack, Text } from '@primer/react';
55

66
import { AppContext } from '../../context/App';
7-
import type { FilterSettingsState, FilterValue } from '../../types';
7+
import type { FilterSettingsState, FilterSettingsValue } from '../../types';
88
import type { Filter } from '../../utils/notifications/filters';
99
import { Checkbox } from '../fields/Checkbox';
1010
import { Title } from '../primitives/Title';
1111
import { RequiresDetailedNotificationWarning } from './RequiresDetailedNotificationsWarning';
1212

13-
export interface FilterSectionProps<T extends FilterValue> {
13+
export interface FilterSectionProps<T extends FilterSettingsValue> {
1414
id: string;
1515
title: string;
1616
icon: Icon;
@@ -20,7 +20,7 @@ export interface FilterSectionProps<T extends FilterValue> {
2020
layout?: 'horizontal' | 'vertical';
2121
}
2222

23-
export const FilterSection = <T extends FilterValue>({
23+
export const FilterSection = <T extends FilterSettingsValue>({
2424
id,
2525
title,
2626
icon,

src/renderer/context/App.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import type {
1717
Account,
1818
AccountNotifications,
1919
AuthState,
20+
ConfigSettingsState,
21+
ConfigSettingsValue,
2022
FilterSettingsState,
21-
FilterValue,
23+
FilterSettingsValue,
2224
GitifyError,
2325
SettingsState,
2426
SettingsValue,
@@ -60,7 +62,11 @@ import {
6062
} from '../utils/theme';
6163
import { setTrayIconColorAndTitle } from '../utils/tray';
6264
import { zoomLevelToPercentage, zoomPercentageToLevel } from '../utils/zoom';
63-
import { defaultAuth, defaultFilters, defaultSettings } from './defaults';
65+
import {
66+
defaultAuth,
67+
defaultFilterSettings,
68+
defaultSettings,
69+
} from './defaults';
6470

6571
export interface AppContextState {
6672
auth: AuthState;
@@ -91,10 +97,13 @@ export interface AppContextState {
9197
settings: SettingsState;
9298
clearFilters: () => void;
9399
resetSettings: () => void;
94-
updateSetting: (name: keyof SettingsState, value: SettingsValue) => void;
100+
updateSetting: (
101+
name: keyof ConfigSettingsState,
102+
value: ConfigSettingsValue,
103+
) => void;
95104
updateFilter: (
96105
name: keyof FilterSettingsState,
97-
value: FilterValue,
106+
value: FilterSettingsValue,
98107
checked: boolean,
99108
) => void;
100109
}
@@ -239,7 +248,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
239248

240249
const clearFilters = useCallback(() => {
241250
setSettings((prevSettings) => {
242-
const newSettings = { ...prevSettings, ...defaultFilters };
251+
const newSettings = { ...prevSettings, ...defaultFilterSettings };
243252
saveState({ auth, settings: newSettings });
244253
return newSettings;
245254
});
@@ -264,7 +273,11 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
264273
);
265274

266275
const updateFilter = useCallback(
267-
(name: keyof FilterSettingsState, value: FilterValue, checked: boolean) => {
276+
(
277+
name: keyof FilterSettingsState,
278+
value: FilterSettingsValue,
279+
checked: boolean,
280+
) => {
268281
const updatedFilters = checked
269282
? [...settings[name], value]
270283
: settings[name].filter((item) => item !== value);

src/renderer/context/defaults.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Constants } from '../constants';
22
import {
33
type AppearanceSettingsState,
44
type AuthState,
5+
type ConfigSettingsState,
56
FetchType,
67
type FilterSettingsState,
78
GroupBy,
@@ -55,7 +56,7 @@ const defaultSystemSettings: SystemSettingsState = {
5556
openAtStartup: false,
5657
};
5758

58-
export const defaultFilters: FilterSettingsState = {
59+
export const defaultFilterSettings: FilterSettingsState = {
5960
filterUserTypes: [],
6061
filterIncludeSearchTokens: [],
6162
filterExcludeSearchTokens: [],
@@ -64,10 +65,14 @@ export const defaultFilters: FilterSettingsState = {
6465
filterReasons: [],
6566
};
6667

67-
export const defaultSettings: SettingsState = {
68+
export const defaultConfigSettings: ConfigSettingsState = {
6869
...defaultAppearanceSettings,
6970
...defaultNotificationSettings,
7071
...defaultTraySettings,
7172
...defaultSystemSettings,
72-
...defaultFilters,
73+
};
74+
75+
export const defaultSettings: SettingsState = {
76+
...defaultConfigSettings,
77+
...defaultFilterSettings,
7378
};

src/renderer/types.ts

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ declare const __brand: unique symbol;
1414

1515
type Brand<B> = { [__brand]: B };
1616

17-
export interface AuthState {
18-
accounts: Account[];
19-
}
20-
2117
export type Branded<T, B> = T & Brand<B>;
2218

2319
export type AuthCode = Branded<string, 'AuthCode'>;
@@ -48,29 +44,49 @@ export interface Account {
4844
hasRequiredScopes?: boolean;
4945
}
5046

51-
export type SettingsValue =
47+
/**
48+
* All allowed Config and Filter Settings values to be stored in the application.
49+
*/
50+
export type SettingsValue = ConfigSettingsValue | FilterSettingsValue[];
51+
52+
/**
53+
* All Config Settings values to be stored in the application.
54+
*/
55+
export type ConfigSettingsValue =
5256
| boolean
5357
| number
5458
| FetchType
55-
| FilterValue[]
5659
| GroupBy
5760
| OpenPreference
5861
| Percentage
5962
| Theme;
6063

61-
export type FilterValue =
64+
/**
65+
* All Filter Settings values to be stored in the application.
66+
*/
67+
export type FilterSettingsValue =
6268
| FilterStateType
6369
| Reason
6470
| SearchToken
6571
| SubjectType
6672
| UserType;
6773

68-
export type SettingsState = AppearanceSettingsState &
74+
/**
75+
* All allowed Config and Filter Settings keys to be stored in the application.
76+
*/
77+
export type SettingsState = ConfigSettingsState & FilterSettingsState;
78+
79+
/**
80+
* All Config Settings keys to be stored in the application.
81+
*/
82+
export type ConfigSettingsState = AppearanceSettingsState &
6983
NotificationSettingsState &
7084
TraySettingsState &
71-
SystemSettingsState &
72-
FilterSettingsState;
85+
SystemSettingsState;
7386

87+
/**
88+
* Settings related to the appearance of the application.
89+
*/
7490
export interface AppearanceSettingsState {
7591
theme: Theme;
7692
increaseContrast: boolean;
@@ -79,6 +95,9 @@ export interface AppearanceSettingsState {
7995
wrapNotificationTitle: boolean;
8096
}
8197

98+
/**
99+
* Settings related to the notifications within the application.
100+
*/
82101
export interface NotificationSettingsState {
83102
groupBy: GroupBy;
84103
fetchType: FetchType;
@@ -93,12 +112,18 @@ export interface NotificationSettingsState {
93112
delayNotificationState: boolean;
94113
}
95114

115+
/**
116+
* Settings related to the tray / menu bar behavior.
117+
*/
96118
export interface TraySettingsState {
97119
showNotificationsCountInTray: boolean;
98120
useUnreadActiveIcon: boolean;
99121
useAlternateIdleIcon: boolean;
100122
}
101123

124+
/**
125+
* Settings related to the system behavior of the application.
126+
*/
102127
export interface SystemSettingsState {
103128
openLinks: OpenPreference;
104129
keyboardShortcut: boolean;
@@ -108,6 +133,9 @@ export interface SystemSettingsState {
108133
openAtStartup: boolean;
109134
}
110135

136+
/**
137+
* Settings related to the filtering of notifications within the application.
138+
*/
111139
export interface FilterSettingsState {
112140
filterIncludeSearchTokens: SearchToken[];
113141
filterExcludeSearchTokens: SearchToken[];
@@ -117,6 +145,10 @@ export interface FilterSettingsState {
117145
filterReasons: Reason[];
118146
}
119147

148+
export interface AuthState {
149+
accounts: Account[];
150+
}
151+
120152
export interface GitifyState {
121153
auth?: AuthState;
122154
settings?: SettingsState;

0 commit comments

Comments
 (0)