Sync better
This commit is contained in:
parent
1f24f1f2f2
commit
be7f5dbf30
5 changed files with 24 additions and 22 deletions
|
|
@ -20,6 +20,7 @@ export class Sync {
|
|||
let nodeCountDownload = await this.getNodeCount(oldMax)
|
||||
let nodeCountUpload = await nodeStore.sendQueue.count()
|
||||
|
||||
_mbus.dispatch('SYNC_START')
|
||||
_mbus.dispatch('SYNC_DOWNLOAD_COUNT', { count: nodeCountDownload })
|
||||
_mbus.dispatch('SYNC_UPLOAD_COUNT', { count: nodeCountUpload })
|
||||
|
||||
|
|
@ -175,9 +176,8 @@ export class N2SyncProgress extends CustomHTMLElement {
|
|||
}// }}}
|
||||
constructor() {//{{{
|
||||
super()
|
||||
|
||||
this.reset()
|
||||
|
||||
_mbus.subscribe('SYNC_START', () => this.reset())
|
||||
_mbus.subscribe('SYNC_DOWNLOAD_COUNT', event => this.progressHandler(event))
|
||||
_mbus.subscribe('SYNC_UPLOAD_COUNT', 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))
|
||||
}//}}}
|
||||
reset() {//{{{
|
||||
this.classList.remove('ok')
|
||||
this.state = {
|
||||
nodesToDownload: 0,
|
||||
nodesToUpload: 0,
|
||||
nodesSynced: 0,
|
||||
nodesDowloaded: 0,
|
||||
nodesUploaded: 0,
|
||||
}
|
||||
this.render()
|
||||
}//}}}
|
||||
progressHandler(event) {//{{{
|
||||
const eventData = event.detail.data
|
||||
|
|
@ -206,7 +208,7 @@ export class N2SyncProgress extends CustomHTMLElement {
|
|||
break
|
||||
|
||||
case 'SYNC_DOWNLOADED':
|
||||
this.state.nodesSynced = eventData.handled
|
||||
this.state.nodesDowloaded = eventData.handled
|
||||
break
|
||||
|
||||
case 'SYNC_UPLOADED':
|
||||
|
|
@ -214,23 +216,26 @@ export class N2SyncProgress extends CustomHTMLElement {
|
|||
break
|
||||
|
||||
case 'SYNC_DONE':
|
||||
this.classList.add('ok')
|
||||
|
||||
// Hides the progress bar.
|
||||
this.setSyncState(false)
|
||||
|
||||
// Don't update anything if nothing was synced.
|
||||
if (this.state.nodesSynced === 0)
|
||||
if (this.state.nodesDowloaded === 0)
|
||||
break
|
||||
|
||||
// Reload the tree nodes to reflect the new/updated nodes.
|
||||
window._app.tree.reset()
|
||||
window._app.sidebar.reset()
|
||||
break
|
||||
}
|
||||
this.render()
|
||||
}//}}}
|
||||
render() {//{{{
|
||||
this.elDownloadTransferred.innerText = this.state.nodesSynced
|
||||
this.elDownloadTransferred.innerText = this.state.nodesDowloaded
|
||||
this.elDownloadTotal.innerText = this.state.nodesToDownload
|
||||
|
||||
console.log('setting elUploadTransferred', this.state.nodesUploaded)
|
||||
this.elUploadTransferred.innerText = this.state.nodesUploaded
|
||||
this.elUploadTotal.innerText = this.state.nodesToUpload
|
||||
}//}}}
|
||||
|
|
@ -238,6 +243,7 @@ export class N2SyncProgress extends CustomHTMLElement {
|
|||
if (state)
|
||||
this.classList.add('show')
|
||||
else
|
||||
// Give the user a chance to see what it ended on.
|
||||
setTimeout(() => this.classList.remove('show'), 1500)
|
||||
}// }}}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue