Fix the All group shifting in localstorage

This commit is contained in:
Bubka 2020-11-27 13:54:54 +01:00
parent ea2ebc91d3
commit 049394ccff

View File

@ -51,6 +51,7 @@
data() { data() {
return { return {
groups : [], groups : [],
TheAllGroup : null,
} }
}, },
@ -58,7 +59,13 @@
// Load groups for localstorage at first to avoid latency // Load groups for localstorage at first to avoid latency
const groups = this.$storage.get('groups', null) // use null as fallback if localstorage is empty const groups = this.$storage.get('groups', null) // use null as fallback if localstorage is empty
if( groups ) this.groups = groups // We don't want the pseudo group 'All' to be managed so we shift it
if( groups ) {
this.groups = groups
this.TheAllGroup = this.groups.shift()
}
// we refresh the collection whatever
this.fetchGroups() this.fetchGroups()
}, },
@ -77,11 +84,11 @@
}) })
}) })
// Remove the pseudo 'All' group
this.TheAllGroup = groups.shift()
this.groups = groups this.groups = groups
}) })
// Remove the pseudo 'All' group
this.groups.shift()
}, },
deleteGroup(id) { deleteGroup(id) {
@ -96,6 +103,7 @@
}, },
beforeRouteLeave(to, from, next) { beforeRouteLeave(to, from, next) {
this.groups.unshift(this.TheAllGroup)
// Refresh localstorage // Refresh localstorage
this.$storage.set('groups', this.groups) this.$storage.set('groups', this.groups)