From 6e222cf758d264bfe701ae4c889d8e03d151464d Mon Sep 17 00:00:00 2001 From: Luis Kriner Date: Tue, 12 Nov 2024 18:16:13 +0100 Subject: [PATCH] use LocalPreferences --- .../src/Domain/Preferences/LocalPrefKey.ts | 9 ++++++++ .../PaneController/PaneController.ts | 23 +++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/services/src/Domain/Preferences/LocalPrefKey.ts b/packages/services/src/Domain/Preferences/LocalPrefKey.ts index af2e438a3f1..be841d1578c 100644 --- a/packages/services/src/Domain/Preferences/LocalPrefKey.ts +++ b/packages/services/src/Domain/Preferences/LocalPrefKey.ts @@ -1,6 +1,8 @@ import { EditorFontSize, EditorLineHeight, EditorLineWidth } from '@standardnotes/models' export enum LocalPrefKey { + ListPaneCollapsed = 'listPaneCollapsed', + NavigationPaneCollapsed = 'navigationPaneCollapsed', ActiveThemes = 'activeThemes', UseSystemColorScheme = 'useSystemColorScheme', UseTranslucentUI = 'useTranslucentUI', @@ -14,6 +16,8 @@ export enum LocalPrefKey { } export type LocalPrefValue = { + [LocalPrefKey.ListPaneCollapsed]: boolean + [LocalPrefKey.NavigationPaneCollapsed]: boolean [LocalPrefKey.ActiveThemes]: string[] [LocalPrefKey.UseSystemColorScheme]: boolean [LocalPrefKey.UseTranslucentUI]: boolean @@ -25,3 +29,8 @@ export type LocalPrefValue = { [LocalPrefKey.EditorLineWidth]: EditorLineWidth [LocalPrefKey.EditorFontSize]: EditorFontSize } + +export const LocalPrefDefaults = { + listPaneCollapsed: false, + navigationPaneCollapsed: false +} \ No newline at end of file diff --git a/packages/web/src/javascripts/Controllers/PaneController/PaneController.ts b/packages/web/src/javascripts/Controllers/PaneController/PaneController.ts index c26e23f8111..04f93afc287 100644 --- a/packages/web/src/javascripts/Controllers/PaneController/PaneController.ts +++ b/packages/web/src/javascripts/Controllers/PaneController/PaneController.ts @@ -2,6 +2,8 @@ import { PanesForLayout } from './../../Application/UseCase/PanesForLayout' import { InternalEventHandlerInterface, InternalEventInterface, + LocalPrefDefaults, + LocalPrefKey, PreferenceServiceInterface, } from '@standardnotes/services' import { @@ -42,8 +44,8 @@ export class PaneController extends AbstractViewController implements InternalEv currentItemsPanelWidth = 0 focusModeEnabled = false - listPaneExplicitelyCollapsed = localStorage.getItem("listPaneCollapsed")=="true" - navigationPaneExplicitelyCollapsed = localStorage.getItem("navPaneCollapsed")=="true" + listPaneExplicitelyCollapsed = this.preferences.getLocalValue(LocalPrefKey.ListPaneCollapsed, LocalPrefDefaults[LocalPrefKey.ListPaneCollapsed]) + navigationPaneExplicitelyCollapsed = this.preferences.getLocalValue(LocalPrefKey.NavigationPaneCollapsed, LocalPrefDefaults[LocalPrefKey.NavigationPaneCollapsed]) constructor( private preferences: PreferenceServiceInterface, @@ -106,6 +108,7 @@ export class PaneController extends AbstractViewController implements InternalEv } eventBus.addEventHandler(this, ApplicationEvent.PreferencesChanged) + eventBus.addEventHandler(this, ApplicationEvent.LocalPreferencesChanged) this.disposers.push( keyboardService.addCommandHandler({ @@ -144,6 +147,10 @@ export class PaneController extends AbstractViewController implements InternalEv this.setCurrentNavPanelWidth(this.preferences.getValue(PrefKey.TagsPanelWidth, MinimumNavPanelWidth)) this.setCurrentItemsPanelWidth(this.preferences.getValue(PrefKey.NotesPanelWidth, MinimumNotesPanelWidth)) } + if(event.type === ApplicationEvent.LocalPreferencesChanged){ + this.listPaneExplicitelyCollapsed = this.preferences.getLocalValue(LocalPrefKey.ListPaneCollapsed, LocalPrefDefaults[LocalPrefKey.ListPaneCollapsed]) + this.navigationPaneExplicitelyCollapsed = this.preferences.getLocalValue(LocalPrefKey.NavigationPaneCollapsed, LocalPrefDefaults[LocalPrefKey.NavigationPaneCollapsed]) + } } setCurrentNavPanelWidth(width: number) { @@ -258,28 +265,24 @@ export class PaneController extends AbstractViewController implements InternalEv toggleListPane = () => { if (this.panes.includes(AppPaneId.Items)) { this.removePane(AppPaneId.Items) - this.listPaneExplicitelyCollapsed = true - localStorage.setItem("listPaneCollapsed", "true") + this.preferences.setLocalValue(LocalPrefKey.ListPaneCollapsed, true) } else { if (this.panes.includes(AppPaneId.Navigation)) { this.insertPaneAtIndex(AppPaneId.Items, 1) } else { this.insertPaneAtIndex(AppPaneId.Items, 0) } - this.listPaneExplicitelyCollapsed = false - localStorage.setItem("listPaneCollapsed", "false") + this.preferences.setLocalValue(LocalPrefKey.ListPaneCollapsed, false) } } toggleNavigationPane = () => { if (this.panes.includes(AppPaneId.Navigation)) { this.removePane(AppPaneId.Navigation) - this.navigationPaneExplicitelyCollapsed = true - localStorage.setItem("navPaneCollapsed", "true") + this.preferences.setLocalValue(LocalPrefKey.NavigationPaneCollapsed, true) } else { this.insertPaneAtIndex(AppPaneId.Navigation, 0) - this.navigationPaneExplicitelyCollapsed = false - localStorage.setItem("navPaneCollapsed", "false") + this.preferences.setLocalValue(LocalPrefKey.NavigationPaneCollapsed, false) } }