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: { methods: {
addContent() { addContent() {
if (this.isObjectiveGroup) { if (this.isObjectiveGroup) {
this.$store.dispatch('addObjective', this.parent.id); this.$modal.open('new-objective-wizard', {parent: this.parent.id});
} else { } else {
let route; let route;
if (this.after && this.after.id) { if (this.after && this.after.id) {

View File

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

View File

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