Better progress updates on sync
This commit is contained in:
parent
3453dffb53
commit
02a8e10d11
1 changed files with 19 additions and 4 deletions
|
@ -9,7 +9,6 @@ const SYNC_HANDLED = 2
|
||||||
const SYNC_DONE = 3
|
const SYNC_DONE = 3
|
||||||
|
|
||||||
export class Sync {
|
export class Sync {
|
||||||
|
|
||||||
constructor() {//{{{
|
constructor() {//{{{
|
||||||
this.listeners = []
|
this.listeners = []
|
||||||
this.messagesReceived = []
|
this.messagesReceived = []
|
||||||
|
@ -50,7 +49,7 @@ export class Sync {
|
||||||
|
|
||||||
await this.nodesToServer()
|
await this.nodesToServer()
|
||||||
} finally {
|
} finally {
|
||||||
this.pushMessage({ op: SYNC_DONE, })
|
this.pushMessage({ op: SYNC_DONE })
|
||||||
}
|
}
|
||||||
}//}}}
|
}//}}}
|
||||||
async getNodeCount(oldMax) {//{{{
|
async getNodeCount(oldMax) {//{{{
|
||||||
|
@ -157,7 +156,7 @@ export class Sync {
|
||||||
|
|
||||||
// Nodes are archived on server and can now be deleted from the send queue.
|
// Nodes are archived on server and can now be deleted from the send queue.
|
||||||
const keys = nodesToSend.map(node => node.ClientSequence)
|
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 })
|
this.pushMessage({ op: SYNC_HANDLED, count: nodesToSend.length })
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -172,6 +171,9 @@ export class Sync {
|
||||||
export class SyncProgress extends Component {
|
export class SyncProgress extends Component {
|
||||||
constructor() {//{{{
|
constructor() {//{{{
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
this.forceUpdateRequest = null
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
nodesToSync: 0,
|
nodesToSync: 0,
|
||||||
nodesSynced: 0,
|
nodesSynced: 0,
|
||||||
|
@ -185,6 +187,19 @@ export class SyncProgress extends Component {
|
||||||
if (!prevState.syncedDone && this.state.syncedDone)
|
if (!prevState.syncedDone && this.state.syncedDone)
|
||||||
setTimeout(() => document.getElementById('sync-progress')?.classList.add('hidden'), 750)
|
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) {//{{{
|
progressHandler(msg) {//{{{
|
||||||
switch (msg.op) {
|
switch (msg.op) {
|
||||||
case SYNC_COUNT:
|
case SYNC_COUNT:
|
||||||
|
@ -192,7 +207,7 @@ export class SyncProgress extends Component {
|
||||||
break
|
break
|
||||||
|
|
||||||
case SYNC_HANDLED:
|
case SYNC_HANDLED:
|
||||||
this.setState({ nodesSynced: this.state.nodesSynced + msg.count })
|
this.state.nodesSynced += msg.count
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue