Skip to content

Commit

Permalink
use local preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-411 committed Nov 11, 2024
1 parent ea03be7 commit 7eb2e62
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
53 changes: 53 additions & 0 deletions packages/models/dist/Domain/Syncable/UserPrefs/PrefDefaults.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { EditorFontSize } from './EditorFontSize';
import { EditorLineHeight } from './EditorLineHeight';
import { EditorLineWidth } from './EditorLineWidth';
import { NewNoteTitleFormat } from './NewNoteTitleFormat';
export declare const PrefDefaults: {
listPaneCollapsed: false,
navigationPaneCollapsed: false,
tagsPanelWidth: number;
notesPanelWidth: number;
editorWidth: null;
editorLeft: null;
monospaceFont: false;
spellcheck: true;
marginResizersEnabled: false;
editorLineHeight: EditorLineHeight.Normal;
editorLineWidth: EditorLineWidth.FullWidth;
editorFontSize: EditorFontSize.Normal;
sortBy: keyof import("../../Runtime/Collection/CollectionSort").SortableItem;
sortReverse: false;
showArchived: false;
showTrashed: false;
hidePinned: false;
hideProtected: false;
hideNotePreview: false;
hideDate: false;
hideTags: false;
hideEditorIcon: false;
useSystemColorScheme: false;
useTranslucentUI: true;
autoLightThemeIdentifier: string;
autoDarkThemeIdentifier: string;
noteAddToParentFolders: true;
newNoteTitleFormat: NewNoteTitleFormat.CurrentDateAndTime;
customNoteTitleFormat: string;
updateSavingStatusIndicator: true;
paneGesturesEnabled: true;
momentsDefaultTagUuid: undefined;
clipperDefaultTagUuid: undefined;
defaultEditorIdentifier: string;
superNoteExportFormat: "json";
superNoteExportEmbedBehavior: "reference";
superNoteExportUseMDFrontmatter: true;
superNoteExportPDFPageSize: "A4";
systemViewPreferences: {};
authenticatorNames: string;
componentPreferences: {};
activeThemes: never[];
activeComponents: never[];
alwaysShowSuperToolbar: true;
addImportsToTag: true;
alwaysCreateNewTagForImports: true;
existingTagForImports: undefined;
};
4 changes: 4 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PanesForLayout } from './../../Application/UseCase/PanesForLayout'
import {
InternalEventHandlerInterface,
InternalEventInterface,
LocalPrefKey,
PreferenceServiceInterface,
} from '@standardnotes/services'
import {
Expand Down Expand Up @@ -42,8 +43,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, PrefDefaults[LocalPrefKey.ListPaneCollapsed])
navigationPaneExplicitelyCollapsed = this.preferences.getLocalValue(LocalPrefKey.NavigationPaneCollapsed, PrefDefaults[LocalPrefKey.NavigationPaneCollapsed])

constructor(
private preferences: PreferenceServiceInterface,
Expand Down Expand Up @@ -106,6 +107,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 +146,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, PrefDefaults[LocalPrefKey.ListPaneCollapsed])
this.navigationPaneExplicitelyCollapsed = this.preferences.getLocalValue(LocalPrefKey.NavigationPaneCollapsed, PrefDefaults[LocalPrefKey.NavigationPaneCollapsed])
}
}

setCurrentNavPanelWidth(width: number) {
Expand Down Expand Up @@ -258,28 +264,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 7eb2e62

Please sign in to comment.