Better progress updates on sync

This commit is contained in:
Magnus Åhall 2025-01-21 18:46:00 +01:00
parent 3453dffb53
commit 02a8e10d11

View file

@ -9,7 +9,6 @@ const SYNC_HANDLED = 2
const SYNC_DONE = 3
export class Sync {
constructor() {//{{{
this.listeners = []
this.messagesReceived = []
@ -50,7 +49,7 @@ export class Sync {
await this.nodesToServer()
} finally {
this.pushMessage({ op: SYNC_DONE, })
this.pushMessage({ op: SYNC_DONE })
}
}//}}}
async getNodeCount(oldMax) {//{{{
@ -157,7 +156,7 @@ export class Sync {
// Nodes are archived on server and can now be deleted from the send queue.
const keys = nodesToSend.map(node => node.ClientSequence)
console.log(await nodeStore.sendQueue.delete(keys))
await nodeStore.sendQueue.delete(keys)
this.pushMessage({ op: SYNC_HANDLED, count: nodesToSend.length })
} catch (e) {
@ -172,6 +171,9 @@ export class Sync {
export class SyncProgress extends Component {
constructor() {//{{{
super()
this.forceUpdateRequest = null
this.state = {
nodesToSync: 0,
nodesSynced: 0,
@ -185,6 +187,19 @@ export class SyncProgress extends Component {
if (!prevState.syncedDone && this.state.syncedDone)
setTimeout(() => document.getElementById('sync-progress')?.classList.add('hidden'), 750)
}//}}}
componentDidUpdate() {//{{{
if (!this.state.syncedDone) {
if (this.forceUpdateRequest !== null)
clearTimeout(this.forceUpdateRequest)
this.forceUpdateRequest = setTimeout(
() => {
this.forceUpdateRequest = null
this.forceUpdate()
},
50
)
}
}//}}}
progressHandler(msg) {//{{{
switch (msg.op) {
case SYNC_COUNT:
@ -192,7 +207,7 @@ export class SyncProgress extends Component {
break
case SYNC_HANDLED:
this.setState({ nodesSynced: this.state.nodesSynced + msg.count })
this.state.nodesSynced += msg.count
break