From 03c3d6c94c6f6c582d6f0a41ae8367aa704e6a3b Mon Sep 17 00:00:00 2001 From: Luis Kriner Date: Wed, 13 Nov 2024 11:19:28 +0100 Subject: [PATCH] LocalPrefKey implementation --- .../src/Domain/Preferences/LocalPrefKey.ts | 19 ++++++++++++++++--- .../src/javascripts/Hooks/usePreference.tsx | 6 +++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/services/src/Domain/Preferences/LocalPrefKey.ts b/packages/services/src/Domain/Preferences/LocalPrefKey.ts index be841d1578c..1703a39eae2 100644 --- a/packages/services/src/Domain/Preferences/LocalPrefKey.ts +++ b/packages/services/src/Domain/Preferences/LocalPrefKey.ts @@ -1,4 +1,5 @@ import { EditorFontSize, EditorLineHeight, EditorLineWidth } from '@standardnotes/models' +import { NativeFeatureIdentifier } from '@standardnotes/features' export enum LocalPrefKey { ListPaneCollapsed = 'listPaneCollapsed', @@ -31,6 +32,18 @@ export type LocalPrefValue = { } export const LocalPrefDefaults = { - listPaneCollapsed: false, - navigationPaneCollapsed: false -} \ No newline at end of file + [LocalPrefKey.ListPaneCollapsed]: false, + [LocalPrefKey.NavigationPaneCollapsed]: false, + [LocalPrefKey.ActiveThemes]: [], + [LocalPrefKey.UseSystemColorScheme]: false, + [LocalPrefKey.UseTranslucentUI]: true, + [LocalPrefKey.AutoLightThemeIdentifier]: 'Default', + [LocalPrefKey.AutoDarkThemeIdentifier]: NativeFeatureIdentifier.TYPES.DarkTheme, + + [LocalPrefKey.EditorMonospaceEnabled]: false, + [LocalPrefKey.EditorLineHeight]: EditorLineHeight.Normal, + [LocalPrefKey.EditorLineWidth]: EditorLineWidth.FullWidth, + [LocalPrefKey.EditorFontSize]: EditorFontSize.Normal +} satisfies { + [key in LocalPrefKey]: LocalPrefValue[key] +} diff --git a/packages/web/src/javascripts/Hooks/usePreference.tsx b/packages/web/src/javascripts/Hooks/usePreference.tsx index 9402aab9ec4..1936c828b87 100644 --- a/packages/web/src/javascripts/Hooks/usePreference.tsx +++ b/packages/web/src/javascripts/Hooks/usePreference.tsx @@ -1,11 +1,11 @@ import { useApplication } from '@/Components/ApplicationProvider' -import { ApplicationEvent, PrefKey, PrefDefaults, LocalPrefKey, LocalPrefValue } from '@standardnotes/snjs' +import { ApplicationEvent, PrefKey, PrefDefaults, LocalPrefKey, LocalPrefValue, LocalPrefDefaults } from '@standardnotes/snjs' import { useCallback, useEffect, useState } from 'react' export function useLocalPreference(preference: Key) { const application = useApplication() - const [value, setValue] = useState(application.preferences.getLocalValue(preference, PrefDefaults[preference])) + const [value, setValue] = useState(application.preferences.getLocalValue(preference, LocalPrefDefaults[preference])) const setNewValue = useCallback( (newValue: LocalPrefValue[Key]) => { @@ -16,7 +16,7 @@ export function useLocalPreference(preference: Key) { useEffect(() => { return application.addEventObserver(async () => { - const latestValue = application.preferences.getLocalValue(preference, PrefDefaults[preference]) + const latestValue = application.preferences.getLocalValue(preference, LocalPrefDefaults[preference]) setValue(latestValue) }, ApplicationEvent.LocalPreferencesChanged)