-
Joel Jeremy Marquez authored
* Hooks for frequently made operations * Release notes * Fix typecheck errors * Remove useGlobalPrefs * Add null checks * Fix showCleared pref * Add loaded flag for categories, accounts and payees state * Refactor to reduce unnecessary states * Fix eslint errors * Fix hooks deps * Add useEffect * Fix typecheck error * Set local and global pref hooks * Fix lint error * VRT * Fix typecheck error * Remove eager loading * Fix typecheck error * Fix typo * Fix typecheck error * Update useTheme * Typecheck errors * Typecheck error * defaultValue * Explicitly check undefined * Remove useGlobalPref and useLocalPref defaults * Fix default prefs * Default value * Fix lint error * Set default theme * Default date format in Account * Update packages/desktop-client/src/style/theme.tsx Co-authored-by:
Matiss Janis Aboltins <matiss@mja.lv> --------- Co-authored-by:
Matiss Janis Aboltins <matiss@mja.lv>
Joel Jeremy Marquez authored* Hooks for frequently made operations * Release notes * Fix typecheck errors * Remove useGlobalPrefs * Add null checks * Fix showCleared pref * Add loaded flag for categories, accounts and payees state * Refactor to reduce unnecessary states * Fix eslint errors * Fix hooks deps * Add useEffect * Fix typecheck error * Set local and global pref hooks * Fix lint error * VRT * Fix typecheck error * Remove eager loading * Fix typecheck error * Fix typo * Fix typecheck error * Update useTheme * Typecheck errors * Typecheck error * defaultValue * Explicitly check undefined * Remove useGlobalPref and useLocalPref defaults * Fix default prefs * Default value * Fix lint error * Set default theme * Default date format in Account * Update packages/desktop-client/src/style/theme.tsx Co-authored-by:
Matiss Janis Aboltins <matiss@mja.lv> --------- Co-authored-by:
Matiss Janis Aboltins <matiss@mja.lv>
prefs.ts 1.45 KiB
// @ts-strict-ignore
import { send } from '../../platform/client/fetch';
import type * as prefs from '../../types/prefs';
import * as constants from '../constants';
import { closeModal } from './modals';
import type { Dispatch, GetState } from './types';
export function loadPrefs() {
return async (dispatch: Dispatch, getState: GetState) => {
const prefs = await send('load-prefs');
// Remove any modal state if switching between budgets
const currentPrefs = getState().prefs.local;
if (prefs && prefs.id && !currentPrefs) {
dispatch(closeModal());
}
dispatch({
type: constants.SET_PREFS,
prefs,
globalPrefs: await send('load-global-prefs'),
});
return prefs;
};
}
export function savePrefs(prefs: prefs.LocalPrefs) {
return async (dispatch: Dispatch) => {
await send('save-prefs', prefs);
dispatch({
type: constants.MERGE_LOCAL_PREFS,
prefs,
});
};
}
export function loadGlobalPrefs() {
return async (dispatch: Dispatch, getState: GetState) => {
const globalPrefs = await send('load-global-prefs');
dispatch({
type: constants.SET_PREFS,
prefs: getState().prefs.local,
globalPrefs,
});
return globalPrefs;
};
}
export function saveGlobalPrefs(prefs: prefs.GlobalPrefs) {
return async (dispatch: Dispatch) => {
await send('save-global-prefs', prefs);
dispatch({
type: constants.MERGE_GLOBAL_PREFS,
globalPrefs: prefs,
});
};
}