Sync better

This commit is contained in:
Magnus Åhall 2026-06-09 17:23:44 +02:00
parent 1f24f1f2f2
commit be7f5dbf30
5 changed files with 24 additions and 22 deletions

View file

@ -54,10 +54,6 @@ type Node struct {
Content string Content string
ContentEncrypted string `db:"content_encrypted" json:"-"` ContentEncrypted string `db:"content_encrypted" json:"-"`
Markdown bool Markdown bool
// CryptoKeyID int `db:"crypto_key_id"`
//Files []File
//ChecklistGroups []ChecklistGroup
} }
func NodeTree(userID, offset int, synced uint64) (nodes []TreeNode, maxSeq uint64, moreRowsExist bool, err error) { // {{{ func NodeTree(userID, offset int, synced uint64) (nodes []TreeNode, maxSeq uint64, moreRowsExist bool, err error) { // {{{

View file

@ -22,6 +22,7 @@
&[data-heading="1"] { &[data-heading="1"] {
margin-top: 64px; margin-top: 64px;
margin-bottom: 32px;
} }
&[data-heading="2"], &[data-heading="2"],
@ -33,6 +34,10 @@
} }
} }
h1, h2, h3 {
margin: 0;
}
h1 { h1 {
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
@ -45,21 +50,14 @@
background-color: var(--color1); background-color: var(--color1);
padding: 4px 24px 4px 16px; padding: 4px 24px 4px 16px;
margin-top: 0px;
margin-bottom: 0px;
} }
h2 { h2 {
font-size: 1.25em; font-size: 1.25em;
margin-top: 16px;
margin-bottom: 0px;
color: var(--color1); color: var(--color1);
} }
h3 { h3 {
margin: 0;
&:before { &:before {
font-size: 1.0em; font-size: 1.0em;
content: "> "; content: "> ";
@ -85,7 +83,7 @@
table { table {
border: 1px solid #ccc; border: 1px solid #ccc;
border-collapse: collapse; border-collapse: collapse;
margin-top: 14px; margin-top: 16px;
th { th {
text-align: left; text-align: left;

View file

@ -326,6 +326,10 @@ n2-syncprogress {
opacity: 1; opacity: 1;
} }
&.ok {
background-color: #5aa02c;
}
grid-template-columns: min-content repeat(3, min-content); grid-template-columns: min-content repeat(3, min-content);
grid-gap: 8px 8px; grid-gap: 8px 8px;
white-space: nowrap; white-space: nowrap;

View file

@ -117,7 +117,6 @@ export class N2Sidebar extends CustomHTMLElement {
this.tabIndex = 0 this.tabIndex = 0
this.treeNodeComponents = {} this.treeNodeComponents = {}
this.treeTrunk = []
this.expandedNodes = {} // keyed on UUID this.expandedNodes = {} // keyed on UUID
this.selectedNode = null this.selectedNode = null
this.rendered = false this.rendered = false
@ -170,10 +169,9 @@ export class N2Sidebar extends CustomHTMLElement {
}// }}} }// }}}
reset() {// {{{ reset() {// {{{
this.treeNodeComponents = {} this.treeNodeComponents = {}
this.treeTrunk = []
this.rendered = false this.rendered = false
this.elTreenodes.replaceChildren() this.elTreenodes.replaceChildren()
this.populateFirstLevel() this.render()
}// }}} }// }}}
getNodeExpanded(UUID) {//{{{ getNodeExpanded(UUID) {//{{{
if (this.expandedNodes[UUID] === undefined) if (this.expandedNodes[UUID] === undefined)

View file

@ -20,6 +20,7 @@ export class Sync {
let nodeCountDownload = await this.getNodeCount(oldMax) let nodeCountDownload = await this.getNodeCount(oldMax)
let nodeCountUpload = await nodeStore.sendQueue.count() let nodeCountUpload = await nodeStore.sendQueue.count()
_mbus.dispatch('SYNC_START')
_mbus.dispatch('SYNC_DOWNLOAD_COUNT', { count: nodeCountDownload }) _mbus.dispatch('SYNC_DOWNLOAD_COUNT', { count: nodeCountDownload })
_mbus.dispatch('SYNC_UPLOAD_COUNT', { count: nodeCountUpload }) _mbus.dispatch('SYNC_UPLOAD_COUNT', { count: nodeCountUpload })
@ -175,9 +176,8 @@ export class N2SyncProgress extends CustomHTMLElement {
}// }}} }// }}}
constructor() {//{{{ constructor() {//{{{
super() super()
this.reset() this.reset()
_mbus.subscribe('SYNC_START', () => this.reset())
_mbus.subscribe('SYNC_DOWNLOAD_COUNT', event => this.progressHandler(event)) _mbus.subscribe('SYNC_DOWNLOAD_COUNT', event => this.progressHandler(event))
_mbus.subscribe('SYNC_UPLOAD_COUNT', event => this.progressHandler(event)) _mbus.subscribe('SYNC_UPLOAD_COUNT', event => this.progressHandler(event))
_mbus.subscribe('SYNC_DOWNLOADED', event => this.progressHandler(event)) _mbus.subscribe('SYNC_DOWNLOADED', event => this.progressHandler(event))
@ -185,12 +185,14 @@ export class N2SyncProgress extends CustomHTMLElement {
_mbus.subscribe('SYNC_DONE', event => this.progressHandler(event)) _mbus.subscribe('SYNC_DONE', event => this.progressHandler(event))
}//}}} }//}}}
reset() {//{{{ reset() {//{{{
this.classList.remove('ok')
this.state = { this.state = {
nodesToDownload: 0, nodesToDownload: 0,
nodesToUpload: 0, nodesToUpload: 0,
nodesSynced: 0, nodesDowloaded: 0,
nodesUploaded: 0, nodesUploaded: 0,
} }
this.render()
}//}}} }//}}}
progressHandler(event) {//{{{ progressHandler(event) {//{{{
const eventData = event.detail.data const eventData = event.detail.data
@ -206,7 +208,7 @@ export class N2SyncProgress extends CustomHTMLElement {
break break
case 'SYNC_DOWNLOADED': case 'SYNC_DOWNLOADED':
this.state.nodesSynced = eventData.handled this.state.nodesDowloaded = eventData.handled
break break
case 'SYNC_UPLOADED': case 'SYNC_UPLOADED':
@ -214,23 +216,26 @@ export class N2SyncProgress extends CustomHTMLElement {
break break
case 'SYNC_DONE': case 'SYNC_DONE':
this.classList.add('ok')
// Hides the progress bar. // Hides the progress bar.
this.setSyncState(false) this.setSyncState(false)
// Don't update anything if nothing was synced. // Don't update anything if nothing was synced.
if (this.state.nodesSynced === 0) if (this.state.nodesDowloaded === 0)
break break
// Reload the tree nodes to reflect the new/updated nodes. // Reload the tree nodes to reflect the new/updated nodes.
window._app.tree.reset() window._app.sidebar.reset()
break break
} }
this.render() this.render()
}//}}} }//}}}
render() {//{{{ render() {//{{{
this.elDownloadTransferred.innerText = this.state.nodesSynced this.elDownloadTransferred.innerText = this.state.nodesDowloaded
this.elDownloadTotal.innerText = this.state.nodesToDownload this.elDownloadTotal.innerText = this.state.nodesToDownload
console.log('setting elUploadTransferred', this.state.nodesUploaded)
this.elUploadTransferred.innerText = this.state.nodesUploaded this.elUploadTransferred.innerText = this.state.nodesUploaded
this.elUploadTotal.innerText = this.state.nodesToUpload this.elUploadTotal.innerText = this.state.nodesToUpload
}//}}} }//}}}
@ -238,6 +243,7 @@ export class N2SyncProgress extends CustomHTMLElement {
if (state) if (state)
this.classList.add('show') this.classList.add('show')
else else
// Give the user a chance to see what it ended on.
setTimeout(() => this.classList.remove('show'), 1500) setTimeout(() => this.classList.remove('show'), 1500)
}// }}} }// }}}
} }