forked from platypush/platypush
A less blocking implementation of the entities loading UI logic.
This commit is contained in:
parent
62d846ddda
commit
d4f8e51caf
1 changed files with 19 additions and 10 deletions
|
@ -249,10 +249,11 @@ export default {
|
|||
return obj
|
||||
}, {})
|
||||
|
||||
await this.request('entities.scan', args)
|
||||
this.request('entities.scan', args)
|
||||
},
|
||||
|
||||
async sync() {
|
||||
async sync(setLoading=true) {
|
||||
if (setLoading)
|
||||
this.loading = true
|
||||
|
||||
try {
|
||||
|
@ -272,6 +273,7 @@ export default {
|
|||
this.selector.selectedEntities = this.entityGroups.id
|
||||
this.refreshEntitiesCache()
|
||||
} finally {
|
||||
if (setLoading)
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
|
@ -367,13 +369,19 @@ export default {
|
|||
loadCachedEntities() {
|
||||
const cachedEntities = window.localStorage.getItem('entities')
|
||||
if (cachedEntities) {
|
||||
try {
|
||||
this.entities = JSON.parse(cachedEntities)
|
||||
if (this.entities) {
|
||||
if (!this.entities)
|
||||
throw Error('The list of cached entities is null')
|
||||
} catch (e) {
|
||||
console.warning('Could not parse cached entities', e)
|
||||
return false
|
||||
}
|
||||
|
||||
Object.values(this.entities).forEach((entity) => this.onEntityUpdate({entity: entity}))
|
||||
this.selector.selectedEntities = this.entityGroups.id
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
|
@ -401,9 +409,10 @@ export default {
|
|||
|
||||
if (!this.loadCachedEntities()) {
|
||||
await this.sync()
|
||||
await this.refresh()
|
||||
this.refresh()
|
||||
} else {
|
||||
await this.request('entities.scan')
|
||||
this.sync()
|
||||
}
|
||||
|
||||
setInterval(() => this.refreshEntitiesCache(), 10000)
|
||||
|
|
Loading…
Reference in a new issue