fix: vuex mutation error in edit list #813

Merged
konrad merged 1 commits from dpschen/frontend:feature/fix-mutation-error-in-edit-list into main 2021-10-02 18:51:55 +00:00

View File

@ -71,7 +71,6 @@ import ListService from '@/services/list'
import ColorPicker from '@/components/input/colorPicker.vue'
import LoadingComponent from '@/components/misc/loading.vue'
import ErrorComponent from '@/components/misc/error.vue'
import ListDuplicateService from '@/services/listDuplicateService'
import {CURRENT_LIST} from '@/store/mutation-types'
import CreateEdit from '@/components/misc/create-edit.vue'
@ -81,7 +80,6 @@ export default {
return {
list: ListModel,
listService: new ListService(),
listDuplicateService: new ListDuplicateService(),
}
},
components: {
@ -106,9 +104,7 @@ export default {
this.listService.get(list)
.then(r => {
this.$set(this, 'list', r)
this.$store.commit(CURRENT_LIST, r)
Review

By settings the return value of listService to the store the list in the store was identical to this.list.
Because of that a change of e.g. list.title throws a vuex mutation error because it changes the title of that bucket in the store.

By settings the return value of listService to the store the list in the store was identical to `this.list`. Because of that a change of e.g. list.title throws a vuex mutation error because it changes the title of that bucket in the store.
Review

Ohh really nice catch

Ohh really nice catch
this.setTitle(this.$t('list.edit.title', {list: this.list.title}))
this.list = { ...r }
})
.catch(e => {
this.$message.error(e)
@ -117,6 +113,8 @@ export default {
save() {
this.$store.dispatch('lists/updateList', this.list)
.then(() => {
this.$store.commit(CURRENT_LIST, this.list)
Review

Since we don't want to change the store value until we are finished I commit the changed value only in the save function and only if the updateList was successfull.

Since we don't want to change the store value until we are finished I commit the changed value only in the save function and only if the updateList was successfull.
Review

Since we don't want to change the store value until we are finished I commit the changed value only in the save function and only if the updateList was successfull.

Now that I think of it again, I'm not sure if that makes sense. But it seems to work! :P And in the vue3 branch it removes the mutation error (I didn't check this pull request, waiting for the pipeline here).

> Since we don't want to change the store value until we are finished I commit the changed value only in the save function and only if the updateList was successfull. Now that I think of it again, I'm not sure if that makes sense. But it seems to work! :P And in the vue3 branch it removes the mutation error (I didn't check this pull request, waiting for the pipeline here).
this.setTitle(this.$t('list.edit.title', {list: this.list.title}))
this.$message.success({message: this.$t('list.edit.success')})
this.$router.back()
})