Prefs managing mostly done

This commit is contained in:
Magnus Åhall 2026-06-21 10:59:38 +02:00
parent 81d02b82dc
commit 74851b9c4d
6 changed files with 344 additions and 51 deletions

View file

@ -2,6 +2,7 @@ import { ROOT_NODE } from 'node_store'
import { CustomHTMLElement } from './lib/custom_html_element.mjs'
import { N2Sidebar } from 'sidebar'
import { Node } from 'node'
import { N2PreferenceSet } from './page_preferences.mjs'
export class App {
static PAGES = ['node', 'history', 'storage']
@ -14,6 +15,8 @@ export class App {
this.nodeUI = document.getElementById('note')
this.dragIcon = new N2DragIcon()
this.preferences = this.getPreferences()
this.sidebar.render().then(sidebar => {
document.getElementById('tree').append(sidebar)
document.getElementById('tree-nodes')?.focus()
@ -61,6 +64,11 @@ export class App {
classList.add('page-' + page)
})
_mbus.subscribe('DEVICE_PREFERENCE_SET_UPDATED', ()=>{
this.preferences = this.getPreferences()
console.log(this.preferences.data)
})
window.addEventListener('keydown', event => this.keyHandler(event))
window.addEventListener('popstate', event => this.popState(event))
document.getElementById('notes2').addEventListener('click', event => {
@ -211,6 +219,12 @@ export class App {
let classList = document.querySelector('#main-page').classList
return classList.contains(page)
}// }}}
getPreferences() {// {{{
const devPrefSet = localStorage.getItem('device_preference_set') || 'default'
const userData = localStorage.getItem('user') || '{"default": {}}'
const user = JSON.parse(userData)
return new N2PreferenceSet(devPrefSet, user.Preferences[devPrefSet])
}// }}}
}
class N2Crumbs extends CustomHTMLElement {