Fix objective mutation update

This commit is contained in:
Ramon Wenger 2022-04-12 15:56:41 +02:00
parent 3045da7491
commit 1de6ee8657
3 changed files with 25 additions and 24 deletions

View File

@ -51,7 +51,7 @@
methods: {
addContent() {
if (this.isObjectiveGroup) {
this.$store.dispatch('addObjective', this.parent.id);
this.$modal.open('new-objective-wizard', {parent: this.parent.id});
} else {
let route;
if (this.after && this.after.id) {

View File

@ -1,5 +1,8 @@
<template>
<modal :hide-header="true">
<modal
:hide-header="true"
:small="true"
>
<modal-input
:placeholder="'Lernziel'"
:value="text"
@ -30,7 +33,6 @@
import NEW_OBJECTIVE_MUTATION from '@/graphql/gql/mutations/addObjective.gql';
import OBJECTIVE_GROUP_QUERY from '@/graphql/gql/queries/objectiveGroupQuery.gql';
import {mapGetters} from 'vuex';
export default {
components: {
@ -46,9 +48,9 @@
},
computed: {
...mapGetters({
objectiveGroup: 'currentObjectiveGroup',
}),
objectiveGroup() {
return this.$modal.state.payload.parent;
},
disableSave() {
return this.saving;
},
@ -71,12 +73,21 @@
try {
const query = OBJECTIVE_GROUP_QUERY;
const variables = {id: this.objectiveGroup};
const data = store.readQuery({query, variables});
if (data.objectiveGroup && data.objectiveGroup.objectives) {
data.objectiveGroup.objectives.push({
...objective,
__typename: 'ObjectiveNode',
});
const {objectiveGroup} = store.readQuery({query, variables});
if (objectiveGroup && objectiveGroup.objectives) {
const objectives = [
...objectiveGroup.objectives,
{
...objective,
__typename: 'ObjectiveNode',
},
];
const data = {
objectiveGroup: {
...objectiveGroup,
objectives,
},
};
store.writeQuery({query, variables, data});
}
} catch (e) {
@ -85,11 +96,11 @@
},
}).then(() => {
this.saving = false;
this.hide();
this.$modal.confirm();
});
},
hide() {
this.$store.dispatch('hideModal');
this.$modal.cancel();
},
},
};

View File

@ -19,7 +19,6 @@ export default new Vuex.Store({
currentRoomEntry: '',
parentRoom: null,
parentModule: '',
currentObjectiveGroup: '',
parentProject: null,
currentNote: null,
currentProjectEntry: null,
@ -46,7 +45,6 @@ export default new Vuex.Store({
scrollToAssignmentReady: state => state.scrollToAssignmentReady,
scrollingToAssignment: state => state.scrollingToAssignment,
currentProjectEntry: state => state.currentProjectEntry,
currentObjectiveGroup: state => state.currentObjectiveGroup,
currentContent: state => state.currentContent,
currentNoteBlock: state => state.currentNoteBlock,
currentNote: state => state.currentNote,
@ -81,7 +79,6 @@ export default new Vuex.Store({
commit('setContentBlockPosition', {});
commit('setParentRoom', null);
commit('setParentModule', '');
commit('setCurrentObjectiveGroup', '');
commit('setParentProject', null);
commit('setCurrentProjectEntry', null);
commit('setImageUrl', '');
@ -108,10 +105,6 @@ export default new Vuex.Store({
commit('setContentBlockPosition', payload);
dispatch('showModal', 'new-content-block-wizard');
},
addObjective({commit, dispatch}, payload) {
commit('setCurrentObjectiveGroup', payload);
dispatch('showModal', 'new-objective-wizard');
},
addRoomEntry({commit, dispatch}, payload) {
commit('setParentRoom', payload);
dispatch('showModal', 'new-room-entry-wizard');
@ -230,9 +223,6 @@ export default new Vuex.Store({
setParentModule(state, payload) {
state.parentModule = payload;
},
setCurrentObjectiveGroup(state, payload) {
state.currentObjectiveGroup = payload;
},
setParentProject(state, payload) {
state.parentProject = payload;
},