Fix not updating list name in store when changing it
continuous-integration/drone/push Build is failing Details

This commit is contained in:
kolaente 2021-05-26 16:46:16 +02:00
parent 912cb66970
commit 9d818921a7
Signed by: konrad
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.
state: () => ({}),
mutations: {
addList(state, list) {
setList(state, list) {
Vue.set(state, list.id, list)
},
addLists(state, lists) {
setLists(state, lists) {
lists.forEach(l => {
Vue.set(state, l.id, l)
})
@ -28,16 +28,34 @@ export default {
actions: {
toggleListFavorite(ctx, list) {
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()
return listService.update(list)
.then(r => {
ctx.commit('setList', r)
ctx.commit('namespaces/setListInNamespaceById', r, {root: true})
if (r.isFavorite) {
ctx.commit('addList', r)
r.namespaceId = FavoriteListsNamespace
ctx.commit('namespaces/addListToNamespace', r, {root: true})
} else {
ctx.commit('namespaces/setListInNamespaceById', r, {root: true})
r.namespaceId = FavoriteListsNamespace
ctx.commit('namespaces/removeListFromNamespaceById', r, {root: true})
}
@ -48,23 +66,9 @@ export default {
.catch(e => {
// Reset the list state to the initial one to avoid confusion for the user
list.isFavorite = !list.isFavorite
ctx.commit('addList', list)
ctx.commit('setList', list)
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)
})

View File

@ -45,7 +45,7 @@ export default {
this.listDuplicateService.create(listDuplicate)
.then(r => {
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.$router.push({name: 'list.index', params: {listId: r.list.id}})
})

View File

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