Files
readest/apps/readest-app/src/store/settingsStore.ts
T
Mohammed Efaz a52d9e3a2b feat: add fuzzy search for searching across all settings (#3085)
* feat: enable linking to settings items

* feat: integrate command palette with global state and styles

* feat: add command pallete ui and fuzzy search

* feat: add command palette with global state and styles

* feat: add command registry and search dependencies

* fix: open command palette with shortcuts in reader page

---------

Co-authored-by: Huang Xin <chrox.huang@gmail.com>
2026-01-26 18:32:04 +01:00

51 lines
1.9 KiB
TypeScript

import i18n from '@/i18n/i18n';
import { create } from 'zustand';
import { SystemSettings } from '@/types/settings';
import { EnvConfigType } from '@/services/environment';
import { initDayjs } from '@/utils/time';
export type FontPanelView = 'main-fonts' | 'custom-fonts';
interface SettingsState {
settings: SystemSettings;
settingsDialogBookKey: string;
isSettingsDialogOpen: boolean;
isSettingsGlobal: boolean;
fontPanelView: FontPanelView;
activeSettingsItemId: string | null;
setSettings: (settings: SystemSettings) => void;
saveSettings: (envConfig: EnvConfigType, settings: SystemSettings) => void;
setSettingsDialogBookKey: (bookKey: string) => void;
setSettingsDialogOpen: (open: boolean) => void;
setSettingsGlobal: (global: boolean) => void;
setFontPanelView: (view: FontPanelView) => void;
setActiveSettingsItemId: (id: string | null) => void;
applyUILanguage: (uiLanguage?: string) => void;
}
export const useSettingsStore = create<SettingsState>((set) => ({
settings: {} as SystemSettings,
settingsDialogBookKey: '',
isSettingsDialogOpen: false,
isSettingsGlobal: true,
fontPanelView: 'main-fonts',
activeSettingsItemId: null,
setSettings: (settings) => set({ settings }),
saveSettings: async (envConfig: EnvConfigType, settings: SystemSettings) => {
const appService = await envConfig.getAppService();
await appService.saveSettings(settings);
},
setSettingsDialogBookKey: (bookKey) => set({ settingsDialogBookKey: bookKey }),
setSettingsDialogOpen: (open) => set({ isSettingsDialogOpen: open }),
setSettingsGlobal: (global) => set({ isSettingsGlobal: global }),
setFontPanelView: (view) => set({ fontPanelView: view }),
setActiveSettingsItemId: (id) => set({ activeSettingsItemId: id }),
applyUILanguage: (uiLanguage?: string) => {
const locale = uiLanguage ? uiLanguage : navigator.language;
i18n.changeLanguage(locale);
initDayjs(locale);
},
}));