Fix not updating list name in store when changing it

This commit is contained in:
kolaente 2021-05-26 16:46:16 +02:00
parent 912cb66970
commit 9d818921a7
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
4 changed files with 28 additions and 25 deletions

View file

@ -8,10 +8,10 @@ export default {
// The state is an object which has the list ids as keys. // The state is an object which has the list ids as keys.
state: () => ({}), state: () => ({}),
mutations: { mutations: {
addList(state, list) { setList(state, list) {
Vue.set(state, list.id, list) Vue.set(state, list.id, list)
}, },
addLists(state, lists) { setLists(state, lists) {
lists.forEach(l => { lists.forEach(l => {
Vue.set(state, l.id, l) Vue.set(state, l.id, l)
}) })
@ -28,16 +28,34 @@ export default {
actions: { actions: {
toggleListFavorite(ctx, list) { toggleListFavorite(ctx, list) {
list.isFavorite = !list.isFavorite list.isFavorite = !list.isFavorite
return ctx.dispatch('updateList', list)
},
createList(ctx, list) {
const listService = new ListService()
return listService.create(list)
.then(r => {
r.namespaceId = list.namespaceId
ctx.commit('namespaces/addListToNamespace', r, {root: true})
ctx.commit('setList', r)
return Promise.resolve(r)
})
.catch(e => {
return Promise.reject(e)
})
},
updateList(ctx, list) {
const listService = new ListService() const listService = new ListService()
return listService.update(list) return listService.update(list)
.then(r => { .then(r => {
ctx.commit('setList', r)
ctx.commit('namespaces/setListInNamespaceById', r, {root: true})
if (r.isFavorite) { if (r.isFavorite) {
ctx.commit('addList', r)
r.namespaceId = FavoriteListsNamespace r.namespaceId = FavoriteListsNamespace
ctx.commit('namespaces/addListToNamespace', r, {root: true}) ctx.commit('namespaces/addListToNamespace', r, {root: true})
} else { } else {
ctx.commit('namespaces/setListInNamespaceById', r, {root: true})
r.namespaceId = FavoriteListsNamespace r.namespaceId = FavoriteListsNamespace
ctx.commit('namespaces/removeListFromNamespaceById', r, {root: true}) ctx.commit('namespaces/removeListFromNamespaceById', r, {root: true})
} }
@ -48,23 +66,9 @@ export default {
.catch(e => { .catch(e => {
// Reset the list state to the initial one to avoid confusion for the user // Reset the list state to the initial one to avoid confusion for the user
list.isFavorite = !list.isFavorite list.isFavorite = !list.isFavorite
ctx.commit('addList', list) ctx.commit('setList', list)
return Promise.reject(e) return Promise.reject(e)
}) })
}, }
createList(ctx, list) {
const listService = new ListService()
return listService.create(list)
.then(r => {
r.namespaceId = list.namespaceId
ctx.commit('namespaces/addListToNamespace', r, {root: true})
ctx.commit('addList', r)
return Promise.resolve(r)
})
.catch(e => {
return Promise.reject(e)
})
},
}, },
} }

View file

@ -112,7 +112,7 @@ export default {
}) })
}) })
ctx.commit('lists/addLists', lists, {root: true}) ctx.commit('lists/setLists', lists, {root: true})
return Promise.resolve(r) return Promise.resolve(r)
}) })

View file

@ -45,7 +45,7 @@ export default {
this.listDuplicateService.create(listDuplicate) this.listDuplicateService.create(listDuplicate)
.then(r => { .then(r => {
this.$store.commit('namespaces/addListToNamespace', r.list) this.$store.commit('namespaces/addListToNamespace', r.list)
this.$store.commit('lists/addList', r.list) this.$store.commit('lists/setList', r.list)
this.success({message: 'The list was successfully duplicated.'}, this) this.success({message: 'The list was successfully duplicated.'}, this)
this.$router.push({name: 'list.index', params: {listId: r.list.id}}) this.$router.push({name: 'list.index', params: {listId: r.list.id}})
}) })

View file

@ -113,9 +113,8 @@ export default {
}) })
}, },
save() { save() {
this.listService.update(this.list) this.$store.dispatch('lists/updateList', this.list)
.then(r => { .then(() => {
this.$store.commit('namespaces/setListInNamespaceById', r)
this.success({message: 'The list was successfully updated.'}, this) this.success({message: 'The list was successfully updated.'}, this)
this.$router.back() this.$router.back()
}) })