import { CustomHTMLElement } from "./lib/custom_html_element.mjs"
import { API } from 'api'
export class N2PageStorage extends CustomHTMLElement {
static {// {{{
this.tmpl = document.createElement('template')
this.tmpl.innerHTML = `
Local storage
Notes
Local notes
History notes
Notes to send
Files
Files on server
Files on device
Files to send
Clear storage
Remove all data from this device (not server) and logout the session.
This ensures that no notes or files is left on the browser.
`
}// }}}
constructor() {// {{{
super(true)
.elBtnClearAll.addEventListener('click', ()=>this.clearAll())
window._mbus.subscribe('SHOW_PAGE', event => {
if (event.detail.data?.page == 'storage')
this.render()
})
}// }}}
async render() {// {{{
API.query('GET', '/file/count')
.then(res => {
this.elCountFilesOnServer.innerText = res.Count
})
.catch(err => {
this.elCountFilesOnServer.classList.add('error')
console.error(err)
this.elCountFilesOnServer.innerText = err.message
})
this.elCountNodes.innerText = await globalThis.nodeStore.nodeCount()
this.elCountQueuedNodes.innerText = await globalThis.nodeStore.sendQueue.count()
this.elCountHistoryNodes.innerText = await globalThis.nodeStore.nodesHistory.count()
this.elCountQueuedFiles.innerText = await globalThis.nodeStore.filesMetadata.countToUpload()
this.elCountFilesOnDevice.innerText = await globalThis.nodeStore.filesMetadata.count()
}// }}}
clearAll() {// {{{
if (!confirm('Do you want to remove ALL data from this device and logout?'))
return
globalThis.nodeStore.deleteAll()
}// }}}
}
customElements.define('n2-pagestorage', N2PageStorage)