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 @@ -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<T extends FilterValue> {
export interface FilterSectionProps<T extends FilterSettingsValue> {
title: string;
filter: Filter<T>;
filterSetting: keyof FilterSettingsState;
}

export const FilterSection = <T extends FilterValue>({
export const FilterSection = <T extends FilterSettingsValue>({
title,
filter,
filterSetting,
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 @@ -16,8 +16,10 @@ import type {
AtlassifyError,
AtlassifyNotification,
AuthState,
ConfigSettingsState,
ConfigSettingsValue,
FilterSettingsState,
FilterValue,
FilterSettingsValue,
SettingsState,
SettingsValue,
Status,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
});
Expand All @@ -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);
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 @@ -4,6 +4,7 @@ import { DEFAULT_LANGUAGE } from '../i18n';
import {
type AppearanceSettingsState,
type AuthState,
type ConfigSettingsState,
type FilterSettingsState,
type NotificationSettingsState,
OpenPreference,
Expand Down Expand Up @@ -47,18 +48,22 @@ const defaultSystemSettings: SystemSettingsState = {
openAtStartup: true,
};

export const defaultFilters: FilterSettingsState = {
export const defaultFilterSettings: FilterSettingsState = {
filterEngagementStates: [],
filterCategories: [],
filterReadStates: [],
filterProducts: [],
filterActors: [],
};

export const defaultSettings: SettingsState = {
export const defaultConfigSettings: ConfigSettingsState = {
...defaultAppearanceSettings,
...defaultNotificationSettings,
...defaultTraySettings,
...defaultSystemSettings,
...defaultFilters,
};

export const defaultSettings: SettingsState = {
...defaultConfigSettings,
...defaultFilterSettings,
};
26 changes: 17 additions & 9 deletions src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,42 @@ 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
| ProductType
| 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.
Expand Down