Unset edit mode when leaving route subtree

This commit is contained in:
Ramon Wenger 2022-02-01 15:45:54 +01:00
parent 1660b1aa33
commit b1505e3868
3 changed files with 26 additions and 13 deletions

View File

@ -11,6 +11,7 @@
import Toggle from '@/components/ui/Toggle';
// import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
import {gql} from '@apollo/client/core';
import {setModuleEditMode} from '@/graphql/cache-operations';
const QUERY = gql`
query ModuleEditModeQuery ($slug: String) {
@ -56,19 +57,7 @@
methods: {
toggle(newChecked){
const cache = this.$apollo.provider.defaultClient.cache;
const id = cache.identify({
__typename: 'ModuleNode',
slug: this.slug
});
cache.modify({
id,
fields: {
inEditMode() {
return newChecked;
},
}
});
setModuleEditMode(this.slug, newChecked);
}
},
};

View File

@ -0,0 +1,15 @@
import cache from '@/graphql/cache';
export const setModuleEditMode = (slug, newEditMode) => {
const id = cache.identify({
__typename: 'ModuleNode',
slug
});
cache.modify({
id,
fields: {
inEditMode() {
return newEditMode;
}
}
});
};

View File

@ -20,6 +20,7 @@
import meMixin from '@/mixins/me';
import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
import ME_QUERY from '@/graphql/gql/queries/meQuery.gql';
import {setModuleEditMode} from '@/graphql/cache-operations';
export default {
mixins: [meMixin],
@ -35,6 +36,14 @@
};
},
beforeRouteLeave(to, from, next) {
// toggle edit mode if leavind the module subtree
if(this.module.inEditMode && to.path.indexOf('/module/') === -1) {
setModuleEditMode(this.module.slug, false);
}
next();
},
apollo: {
module() {
return {