From b91bd123bcb8f457c3628d8c42540106efa2542e Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 24 Nov 2025 09:12:32 -0500 Subject: [PATCH] refactor: config settings Signed-off-by: Adam Setch --- .../components/filters/FilterSection.tsx | 6 ++--- src/renderer/context/App.tsx | 25 +++++++++++++----- src/renderer/context/defaults.ts | 11 +++++--- src/renderer/types.ts | 26 ++++++++++++------- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/renderer/components/filters/FilterSection.tsx b/src/renderer/components/filters/FilterSection.tsx index 13f908ae..ebab517b 100644 --- a/src/renderer/components/filters/FilterSection.tsx +++ b/src/renderer/components/filters/FilterSection.tsx @@ -7,18 +7,18 @@ import { IconTile } from '@atlaskit/icon'; import { Box, Inline, Stack } from '@atlaskit/primitives'; import { AppContext } from '../../context/App'; -import type { FilterSettingsState, FilterValue } from '../../types'; +import type { FilterSettingsState, FilterSettingsValue } from '../../types'; import { cn } from '../../utils/cn'; import { formatProperCase } from '../../utils/helpers'; import type { Filter } from '../../utils/notifications/filters'; -export interface FilterSectionProps { +export interface FilterSectionProps { title: string; filter: Filter; filterSetting: keyof FilterSettingsState; } -export const FilterSection = ({ +export const FilterSection = ({ title, filter, filterSetting, diff --git a/src/renderer/context/App.tsx b/src/renderer/context/App.tsx index 88292615..60a82f71 100644 --- a/src/renderer/context/App.tsx +++ b/src/renderer/context/App.tsx @@ -16,8 +16,10 @@ import type { AtlassifyError, AtlassifyNotification, AuthState, + ConfigSettingsState, + ConfigSettingsValue, FilterSettingsState, - FilterValue, + FilterSettingsValue, SettingsState, SettingsValue, Status, @@ -43,7 +45,11 @@ import { clearState, loadState, saveState } from '../utils/storage'; import { setTheme } 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; @@ -72,10 +78,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; } @@ -191,7 +200,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; }); @@ -216,7 +225,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 8c25392b..e9b31e78 100644 --- a/src/renderer/context/defaults.ts +++ b/src/renderer/context/defaults.ts @@ -4,6 +4,7 @@ import { DEFAULT_LANGUAGE } from '../i18n'; import { type AppearanceSettingsState, type AuthState, + type ConfigSettingsState, type FilterSettingsState, type NotificationSettingsState, OpenPreference, @@ -47,7 +48,7 @@ const defaultSystemSettings: SystemSettingsState = { openAtStartup: true, }; -export const defaultFilters: FilterSettingsState = { +export const defaultFilterSettings: FilterSettingsState = { filterEngagementStates: [], filterCategories: [], filterReadStates: [], @@ -55,10 +56,14 @@ export const defaultFilters: FilterSettingsState = { filterActors: [], }; -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 555768ab..e7252dfd 100644 --- a/src/renderer/types.ts +++ b/src/renderer/types.ts @@ -89,20 +89,24 @@ export interface Account { } /** - * The different types of allowed Settings values to be stored in the application. + * All allowed Config and Filter Settings values to be stored in the application. */ -export type SettingsValue = +export type SettingsValue = ConfigSettingsValue | FilterSettingsValue[]; + +/** + * All Config Settings values to be stored in the application. + */ +export type ConfigSettingsValue = | boolean | number - | FilterValue[] | OpenPreference | Percentage | Theme; /** - * The different types of allowed Filter values to be stored in the application. + * All Filter Settings values to be stored in the application. */ -export type FilterValue = +export type FilterSettingsValue = | ActorType | CategoryType | EngagementStateType @@ -110,13 +114,17 @@ export type FilterValue = | ReadStateType; /** - * The different types of allowed Settings keys to be stored in the application. + * 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 SettingsState = AppearanceSettingsState & +export type ConfigSettingsState = AppearanceSettingsState & NotificationSettingsState & TraySettingsState & - SystemSettingsState & - FilterSettingsState; + SystemSettingsState; /** * Settings related to the appearance of the application.