Unset edit mode when leaving route subtree
This commit is contained in:
parent
1660b1aa33
commit
b1505e3868
|
|
@ -11,6 +11,7 @@
|
||||||
import Toggle from '@/components/ui/Toggle';
|
import Toggle from '@/components/ui/Toggle';
|
||||||
// import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
|
// import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
|
||||||
import {gql} from '@apollo/client/core';
|
import {gql} from '@apollo/client/core';
|
||||||
|
import {setModuleEditMode} from '@/graphql/cache-operations';
|
||||||
|
|
||||||
const QUERY = gql`
|
const QUERY = gql`
|
||||||
query ModuleEditModeQuery ($slug: String) {
|
query ModuleEditModeQuery ($slug: String) {
|
||||||
|
|
@ -56,19 +57,7 @@
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
toggle(newChecked){
|
toggle(newChecked){
|
||||||
const cache = this.$apollo.provider.defaultClient.cache;
|
setModuleEditMode(this.slug, newChecked);
|
||||||
const id = cache.identify({
|
|
||||||
__typename: 'ModuleNode',
|
|
||||||
slug: this.slug
|
|
||||||
});
|
|
||||||
cache.modify({
|
|
||||||
id,
|
|
||||||
fields: {
|
|
||||||
inEditMode() {
|
|
||||||
return newChecked;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
import meMixin from '@/mixins/me';
|
import meMixin from '@/mixins/me';
|
||||||
import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
|
import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
|
||||||
import ME_QUERY from '@/graphql/gql/queries/meQuery.gql';
|
import ME_QUERY from '@/graphql/gql/queries/meQuery.gql';
|
||||||
|
import {setModuleEditMode} from '@/graphql/cache-operations';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mixins: [meMixin],
|
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: {
|
apollo: {
|
||||||
module() {
|
module() {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue