diff --git a/src/renderer/components/filters/FilterSection.tsx b/src/renderer/components/filters/FilterSection.tsx index fdd0221b7..6b3986b16 100644 --- a/src/renderer/components/filters/FilterSection.tsx +++ b/src/renderer/components/filters/FilterSection.tsx @@ -4,13 +4,13 @@ import type { Icon } from '@primer/octicons-react'; import { Stack, Text } from '@primer/react'; import { AppContext } from '../../context/App'; -import type { FilterSettingsState, FilterValue } from '../../types'; +import type { FilterSettingsState, FilterSettingsValue } from '../../types'; import type { Filter } from '../../utils/notifications/filters'; import { Checkbox } from '../fields/Checkbox'; import { Title } from '../primitives/Title'; import { RequiresDetailedNotificationWarning } from './RequiresDetailedNotificationsWarning'; -export interface FilterSectionProps { +export interface FilterSectionProps { id: string; title: string; icon: Icon; @@ -20,7 +20,7 @@ export interface FilterSectionProps { layout?: 'horizontal' | 'vertical'; } -export const FilterSection = ({ +export const FilterSection = ({ id, title, icon, diff --git a/src/renderer/context/App.tsx b/src/renderer/context/App.tsx index 542644aed..5d88e58fd 100644 --- a/src/renderer/context/App.tsx +++ b/src/renderer/context/App.tsx @@ -17,8 +17,10 @@ import type { Account, AccountNotifications, AuthState, + ConfigSettingsState, + ConfigSettingsValue, FilterSettingsState, - FilterValue, + FilterSettingsValue, GitifyError, SettingsState, SettingsValue, @@ -60,7 +62,11 @@ import { } from '../utils/theme'; import { setTrayIconColorAndTitle } from '../utils/tray'; import { zoomLevelToPercentage, zoomPercentageToLevel } from '../utils/zoom'; -import { defaultAuth, defaultFilters, defaultSettings } from './defaults'; +import { + defaultAuth, + defaultFilterSettings, + defaultSettings, +} from './defaults'; export interface AppContextState { auth: AuthState; @@ -91,10 +97,13 @@ export interface AppContextState { settings: SettingsState; clearFilters: () => void; resetSettings: () => void; - updateSetting: (name: keyof SettingsState, value: SettingsValue) => void; + updateSetting: ( + name: keyof ConfigSettingsState, + value: ConfigSettingsValue, + ) => void; updateFilter: ( name: keyof FilterSettingsState, - value: FilterValue, + value: FilterSettingsValue, checked: boolean, ) => void; } @@ -239,7 +248,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { const clearFilters = useCallback(() => { setSettings((prevSettings) => { - const newSettings = { ...prevSettings, ...defaultFilters }; + const newSettings = { ...prevSettings, ...defaultFilterSettings }; saveState({ auth, settings: newSettings }); return newSettings; }); @@ -264,7 +273,11 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { ); const updateFilter = useCallback( - (name: keyof FilterSettingsState, value: FilterValue, checked: boolean) => { + ( + name: keyof FilterSettingsState, + value: FilterSettingsValue, + checked: boolean, + ) => { const updatedFilters = checked ? [...settings[name], value] : settings[name].filter((item) => item !== value); diff --git a/src/renderer/context/defaults.ts b/src/renderer/context/defaults.ts index 5b831ac78..b37fc260a 100644 --- a/src/renderer/context/defaults.ts +++ b/src/renderer/context/defaults.ts @@ -2,6 +2,7 @@ import { Constants } from '../constants'; import { type AppearanceSettingsState, type AuthState, + type ConfigSettingsState, FetchType, type FilterSettingsState, GroupBy, @@ -55,7 +56,7 @@ const defaultSystemSettings: SystemSettingsState = { openAtStartup: false, }; -export const defaultFilters: FilterSettingsState = { +export const defaultFilterSettings: FilterSettingsState = { filterUserTypes: [], filterIncludeSearchTokens: [], filterExcludeSearchTokens: [], @@ -64,10 +65,14 @@ export const defaultFilters: FilterSettingsState = { filterReasons: [], }; -export const defaultSettings: SettingsState = { +export const defaultConfigSettings: ConfigSettingsState = { ...defaultAppearanceSettings, ...defaultNotificationSettings, ...defaultTraySettings, ...defaultSystemSettings, - ...defaultFilters, +}; + +export const defaultSettings: SettingsState = { + ...defaultConfigSettings, + ...defaultFilterSettings, }; diff --git a/src/renderer/types.ts b/src/renderer/types.ts index 956bfdb50..3ce20b6ea 100644 --- a/src/renderer/types.ts +++ b/src/renderer/types.ts @@ -14,10 +14,6 @@ declare const __brand: unique symbol; type Brand = { [__brand]: B }; -export interface AuthState { - accounts: Account[]; -} - export type Branded = T & Brand; export type AuthCode = Branded; @@ -48,29 +44,49 @@ export interface Account { hasRequiredScopes?: boolean; } -export type SettingsValue = +/** + * All allowed Config and Filter Settings values to be stored in the application. + */ +export type SettingsValue = ConfigSettingsValue | FilterSettingsValue[]; + +/** + * All Config Settings values to be stored in the application. + */ +export type ConfigSettingsValue = | boolean | number | FetchType - | FilterValue[] | GroupBy | OpenPreference | Percentage | Theme; -export type FilterValue = +/** + * All Filter Settings values to be stored in the application. + */ +export type FilterSettingsValue = | FilterStateType | Reason | SearchToken | SubjectType | UserType; -export type SettingsState = AppearanceSettingsState & +/** + * All allowed Config and Filter Settings keys to be stored in the application. + */ +export type SettingsState = ConfigSettingsState & FilterSettingsState; + +/** + * All Config Settings keys to be stored in the application. + */ +export type ConfigSettingsState = AppearanceSettingsState & NotificationSettingsState & TraySettingsState & - SystemSettingsState & - FilterSettingsState; + SystemSettingsState; +/** + * Settings related to the appearance of the application. + */ export interface AppearanceSettingsState { theme: Theme; increaseContrast: boolean; @@ -79,6 +95,9 @@ export interface AppearanceSettingsState { wrapNotificationTitle: boolean; } +/** + * Settings related to the notifications within the application. + */ export interface NotificationSettingsState { groupBy: GroupBy; fetchType: FetchType; @@ -93,12 +112,18 @@ export interface NotificationSettingsState { delayNotificationState: boolean; } +/** + * Settings related to the tray / menu bar behavior. + */ export interface TraySettingsState { showNotificationsCountInTray: boolean; useUnreadActiveIcon: boolean; useAlternateIdleIcon: boolean; } +/** + * Settings related to the system behavior of the application. + */ export interface SystemSettingsState { openLinks: OpenPreference; keyboardShortcut: boolean; @@ -108,6 +133,9 @@ export interface SystemSettingsState { openAtStartup: boolean; } +/** + * Settings related to the filtering of notifications within the application. + */ export interface FilterSettingsState { filterIncludeSearchTokens: SearchToken[]; filterExcludeSearchTokens: SearchToken[]; @@ -117,6 +145,10 @@ export interface FilterSettingsState { filterReasons: Reason[]; } +export interface AuthState { + accounts: Account[]; +} + export interface GitifyState { auth?: AuthState; settings?: SettingsState;