Skip to content

Commit 6e222cf

Browse files
committed
use LocalPreferences
1 parent ea03be7 commit 6e222cf

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

packages/services/src/Domain/Preferences/LocalPrefKey.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { EditorFontSize, EditorLineHeight, EditorLineWidth } from '@standardnotes/models'
22

33
export enum LocalPrefKey {
4+
ListPaneCollapsed = 'listPaneCollapsed',
5+
NavigationPaneCollapsed = 'navigationPaneCollapsed',
46
ActiveThemes = 'activeThemes',
57
UseSystemColorScheme = 'useSystemColorScheme',
68
UseTranslucentUI = 'useTranslucentUI',
@@ -14,6 +16,8 @@ export enum LocalPrefKey {
1416
}
1517

1618
export type LocalPrefValue = {
19+
[LocalPrefKey.ListPaneCollapsed]: boolean
20+
[LocalPrefKey.NavigationPaneCollapsed]: boolean
1721
[LocalPrefKey.ActiveThemes]: string[]
1822
[LocalPrefKey.UseSystemColorScheme]: boolean
1923
[LocalPrefKey.UseTranslucentUI]: boolean
@@ -25,3 +29,8 @@ export type LocalPrefValue = {
2529
[LocalPrefKey.EditorLineWidth]: EditorLineWidth
2630
[LocalPrefKey.EditorFontSize]: EditorFontSize
2731
}
32+
33+
export const LocalPrefDefaults = {
34+
listPaneCollapsed: false,
35+
navigationPaneCollapsed: false
36+
}

packages/web/src/javascripts/Controllers/PaneController/PaneController.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { PanesForLayout } from './../../Application/UseCase/PanesForLayout'
22
import {
33
InternalEventHandlerInterface,
44
InternalEventInterface,
5+
LocalPrefDefaults,
6+
LocalPrefKey,
57
PreferenceServiceInterface,
68
} from '@standardnotes/services'
79
import {
@@ -42,8 +44,8 @@ export class PaneController extends AbstractViewController implements InternalEv
4244
currentItemsPanelWidth = 0
4345
focusModeEnabled = false
4446

45-
listPaneExplicitelyCollapsed = localStorage.getItem("listPaneCollapsed")=="true"
46-
navigationPaneExplicitelyCollapsed = localStorage.getItem("navPaneCollapsed")=="true"
47+
listPaneExplicitelyCollapsed = this.preferences.getLocalValue(LocalPrefKey.ListPaneCollapsed, LocalPrefDefaults[LocalPrefKey.ListPaneCollapsed])
48+
navigationPaneExplicitelyCollapsed = this.preferences.getLocalValue(LocalPrefKey.NavigationPaneCollapsed, LocalPrefDefaults[LocalPrefKey.NavigationPaneCollapsed])
4749

4850
constructor(
4951
private preferences: PreferenceServiceInterface,
@@ -106,6 +108,7 @@ export class PaneController extends AbstractViewController implements InternalEv
106108
}
107109

108110
eventBus.addEventHandler(this, ApplicationEvent.PreferencesChanged)
111+
eventBus.addEventHandler(this, ApplicationEvent.LocalPreferencesChanged)
109112

110113
this.disposers.push(
111114
keyboardService.addCommandHandler({
@@ -144,6 +147,10 @@ export class PaneController extends AbstractViewController implements InternalEv
144147
this.setCurrentNavPanelWidth(this.preferences.getValue(PrefKey.TagsPanelWidth, MinimumNavPanelWidth))
145148
this.setCurrentItemsPanelWidth(this.preferences.getValue(PrefKey.NotesPanelWidth, MinimumNotesPanelWidth))
146149
}
150+
if(event.type === ApplicationEvent.LocalPreferencesChanged){
151+
this.listPaneExplicitelyCollapsed = this.preferences.getLocalValue(LocalPrefKey.ListPaneCollapsed, LocalPrefDefaults[LocalPrefKey.ListPaneCollapsed])
152+
this.navigationPaneExplicitelyCollapsed = this.preferences.getLocalValue(LocalPrefKey.NavigationPaneCollapsed, LocalPrefDefaults[LocalPrefKey.NavigationPaneCollapsed])
153+
}
147154
}
148155

149156
setCurrentNavPanelWidth(width: number) {
@@ -258,28 +265,24 @@ export class PaneController extends AbstractViewController implements InternalEv
258265
toggleListPane = () => {
259266
if (this.panes.includes(AppPaneId.Items)) {
260267
this.removePane(AppPaneId.Items)
261-
this.listPaneExplicitelyCollapsed = true
262-
localStorage.setItem("listPaneCollapsed", "true")
268+
this.preferences.setLocalValue(LocalPrefKey.ListPaneCollapsed, true)
263269
} else {
264270
if (this.panes.includes(AppPaneId.Navigation)) {
265271
this.insertPaneAtIndex(AppPaneId.Items, 1)
266272
} else {
267273
this.insertPaneAtIndex(AppPaneId.Items, 0)
268274
}
269-
this.listPaneExplicitelyCollapsed = false
270-
localStorage.setItem("listPaneCollapsed", "false")
275+
this.preferences.setLocalValue(LocalPrefKey.ListPaneCollapsed, false)
271276
}
272277
}
273278

274279
toggleNavigationPane = () => {
275280
if (this.panes.includes(AppPaneId.Navigation)) {
276281
this.removePane(AppPaneId.Navigation)
277-
this.navigationPaneExplicitelyCollapsed = true
278-
localStorage.setItem("navPaneCollapsed", "true")
282+
this.preferences.setLocalValue(LocalPrefKey.NavigationPaneCollapsed, true)
279283
} else {
280284
this.insertPaneAtIndex(AppPaneId.Navigation, 0)
281-
this.navigationPaneExplicitelyCollapsed = false
282-
localStorage.setItem("navPaneCollapsed", "false")
285+
this.preferences.setLocalValue(LocalPrefKey.NavigationPaneCollapsed, false)
283286
}
284287
}
285288

0 commit comments

Comments
 (0)