From 744984fc4627f1591055b10bd0e3280656e92370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Tue, 9 Jun 2026 10:27:16 +0200 Subject: [PATCH] Better sync --- static/css/notes2.css | 4 ++-- static/js/sync.mjs | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/static/css/notes2.css b/static/css/notes2.css index 9805b82..f55e1a1 100644 --- a/static/css/notes2.css +++ b/static/css/notes2.css @@ -308,8 +308,8 @@ button { n2-syncprogress { position: absolute; - top: 16px; - right: 16px; + top: 8px; + right: 8px; padding: 8px 16px; z-index: 16384; border-radius: 6px; diff --git a/static/js/sync.mjs b/static/js/sync.mjs index 47777f5..4db4473 100644 --- a/static/js/sync.mjs +++ b/static/js/sync.mjs @@ -17,10 +17,12 @@ export class Sync { const state = await nodeStore.getAppState('latest_sync_node') const oldMax = (state?.value ? state.value : 0) - let nodeCount = await this.getNodeCount(oldMax) - nodeCount += await nodeStore.sendQueue.count() + let nodeCountDownload = await this.getNodeCount(oldMax) + let nodeCountUpload = await nodeStore.sendQueue.count() + console.log(nodeCountUpload) - _mbus.dispatch('SYNC_COUNT', { count: nodeCount }) + _mbus.dispatch('SYNC_DOWNLOAD_COUNT', { count: nodeCountDownload }) + _mbus.dispatch('SYNC_UPLOAD_COUNT', { count: nodeCountUpload }) await this.nodesFromServer(oldMax) .then(durationNodes => { @@ -28,6 +30,7 @@ export class Sync { console.log(`Total time: ${Math.round(1000 * durationNodes) / 1000}s`) }) + // Uploads of modified nodes to server. await this.nodesToServer() } finally { _mbus.dispatch('SYNC_DONE') @@ -175,25 +178,35 @@ export class N2SyncProgress extends CustomHTMLElement { super() this.reset() - _mbus.subscribe('SYNC_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_HANDLED', event => this.progressHandler(event)) _mbus.subscribe('SYNC_DONE', event => this.progressHandler(event)) + _mbus.subscribe('SYNC_UPLOADED', event => this.progressHandler(event)) }//}}} reset() {//{{{ this.state = { - nodesToSync: 0, + nodesToDownload: 0, + nodesToUpload: 0, nodesSynced: 0, + nodesUploaded: 0, } }//}}} progressHandler(event) {//{{{ const eventData = event.detail.data switch (event.type) { - case 'SYNC_COUNT': - this.state.nodesToSync = eventData.count + case 'SYNC_DOWNLOAD_COUNT': + this.state.nodesToDownload = eventData.count + this.setSyncState(true) + break + + case 'SYNC_UPLOAD_COUNT': + this.state.nodesToUpload = eventData.count this.setSyncState(true) break case 'SYNC_HANDLED': + console.log('SYNC_HANDLED', eventData.handled) this.state.nodesSynced = eventData.handled break @@ -208,12 +221,19 @@ export class N2SyncProgress extends CustomHTMLElement { // Reload the tree nodes to reflect the new/updated nodes. window._app.tree.reset() break + + case 'SYNC_UPLOADED': + this.state.nodesUploaded += eventData.count + break } this.render() }//}}} render() {//{{{ this.elDownloadTransferred.innerText = this.state.nodesSynced - this.elDownloadTotal.innerText = this.state.nodesToSync + this.elDownloadTotal.innerText = this.state.nodesToDownload + + this.elUploadTransferred.innerText = this.state.nodesUploaded + this.elUploadTotal.innerText = this.state.nodesToUpload }//}}} setSyncState(state) {// {{{ if (state)