Skip to content

Commit

Permalink
use LocalPreferences
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-411 committed Nov 12, 2024
1 parent ea03be7 commit 6e222cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
9 changes: 9 additions & 0 deletions packages/services/src/Domain/Preferences/LocalPrefKey.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { EditorFontSize, EditorLineHeight, EditorLineWidth } from '@standardnotes/models'

export enum LocalPrefKey {
ListPaneCollapsed = 'listPaneCollapsed',
NavigationPaneCollapsed = 'navigationPaneCollapsed',
ActiveThemes = 'activeThemes',
UseSystemColorScheme = 'useSystemColorScheme',
UseTranslucentUI = 'useTranslucentUI',
Expand All @@ -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
Expand All @@ -25,3 +29,8 @@ export type LocalPrefValue = {
[LocalPrefKey.EditorLineWidth]: EditorLineWidth
[LocalPrefKey.EditorFontSize]: EditorFontSize
}

export const LocalPrefDefaults = {
listPaneCollapsed: false,
navigationPaneCollapsed: false
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { PanesForLayout } from './../../Application/UseCase/PanesForLayout'
import {
InternalEventHandlerInterface,
InternalEventInterface,
LocalPrefDefaults,
LocalPrefKey,
PreferenceServiceInterface,
} from '@standardnotes/services'
import {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 6e222cf

Please sign in to comment.