Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/renderer/components/filters/FilterSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends FilterValue> {
export interface FilterSectionProps<T extends FilterSettingsValue> {
id: string;
title: string;
icon: Icon;
Expand All @@ -20,7 +20,7 @@ export interface FilterSectionProps<T extends FilterValue> {
layout?: 'horizontal' | 'vertical';
}

export const FilterSection = <T extends FilterValue>({
export const FilterSection = <T extends FilterSettingsValue>({
id,
title,
icon,
Expand Down
25 changes: 19 additions & 6 deletions src/renderer/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import type {
Account,
AccountNotifications,
AuthState,
ConfigSettingsState,
ConfigSettingsValue,
FilterSettingsState,
FilterValue,
FilterSettingsValue,
GitifyError,
SettingsState,
SettingsValue,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
});
Expand All @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions src/renderer/context/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Constants } from '../constants';
import {
type AppearanceSettingsState,
type AuthState,
type ConfigSettingsState,
FetchType,
type FilterSettingsState,
GroupBy,
Expand Down Expand Up @@ -55,7 +56,7 @@ const defaultSystemSettings: SystemSettingsState = {
openAtStartup: false,
};

export const defaultFilters: FilterSettingsState = {
export const defaultFilterSettings: FilterSettingsState = {
filterUserTypes: [],
filterIncludeSearchTokens: [],
filterExcludeSearchTokens: [],
Expand All @@ -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,
};
52 changes: 42 additions & 10 deletions src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ declare const __brand: unique symbol;

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

export interface AuthState {
accounts: Account[];
}

export type Branded<T, B> = T & Brand<B>;

export type AuthCode = Branded<string, 'AuthCode'>;
Expand Down Expand Up @@ -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;
Expand All @@ -79,6 +95,9 @@ export interface AppearanceSettingsState {
wrapNotificationTitle: boolean;
}

/**
* Settings related to the notifications within the application.
*/
export interface NotificationSettingsState {
groupBy: GroupBy;
fetchType: FetchType;
Expand All @@ -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;
Expand All @@ -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[];
Expand All @@ -117,6 +145,10 @@ export interface FilterSettingsState {
filterReasons: Reason[];
}

export interface AuthState {
accounts: Account[];
}

export interface GitifyState {
auth?: AuthState;
settings?: SettingsState;
Expand Down