From 3677ffd585e0d3ac4e4e1e3515e41b852b93c73f Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 12 Nov 2020 19:59:32 +0100 Subject: [PATCH] Create list through store to make sure it is updated everywhere --- src/store/modules/lists.js | 14 ++++++++++++++ src/views/list/NewList.vue | 8 +++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/store/modules/lists.js b/src/store/modules/lists.js index 21d6d076..abce934a 100644 --- a/src/store/modules/lists.js +++ b/src/store/modules/lists.js @@ -52,5 +52,19 @@ export default { 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) + }) + }, }, } \ No newline at end of file diff --git a/src/views/list/NewList.vue b/src/views/list/NewList.vue index 3a132f4a..d0889857 100644 --- a/src/views/list/NewList.vue +++ b/src/views/list/NewList.vue @@ -64,12 +64,10 @@ export default { this.showError = false this.list.namespaceId = this.$route.params.id - this.listService.create(this.list) - .then(response => { - response.namespaceId = this.list.namespaceId - this.$store.commit('namespaces/addListToNamespace', response) + this.$store.dispatch('lists/createList', this.list) + .then(r => { this.success({message: 'The list was successfully created.'}, this) - router.push({name: 'list.index', params: {listId: response.id}}) + router.push({name: 'list.index', params: {listId: r.id}}) }) .catch(e => { this.error(e, this)