Add new helper functions
This commit is contained in:
parent
82aa04bf90
commit
3403c2db3d
|
|
@ -54,6 +54,16 @@
|
||||||
import {dateFilter, dateTimeFilter} from '@/filters/date-filter';
|
import {dateFilter, dateTimeFilter} from '@/filters/date-filter';
|
||||||
const DocumentBlock = () => import(/* webpackChunkName: "content-components" */'@/components/content-blocks/DocumentBlock');
|
const DocumentBlock = () => import(/* webpackChunkName: "content-components" */'@/components/content-blocks/DocumentBlock');
|
||||||
|
|
||||||
|
const insertAtIndexImmutably = (arr, el, idx) => {
|
||||||
|
|
||||||
|
};
|
||||||
|
const removeAtIndexImmutably = (arr, idx) => {
|
||||||
|
return [
|
||||||
|
...arr.slice(0, idx),
|
||||||
|
...arr.slice(idx + 1) ,
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ['description', 'documentUrl', 'created', 'id', 'readOnly'],
|
props: ['description', 'documentUrl', 'created', 'id', 'readOnly'],
|
||||||
components: {
|
components: {
|
||||||
|
|
@ -89,9 +99,16 @@
|
||||||
const variables = {
|
const variables = {
|
||||||
slug: projectEntry.$route.params.slug,
|
slug: projectEntry.$route.params.slug,
|
||||||
};
|
};
|
||||||
const data = store.readQuery({query, variables});
|
const {project} = store.readQuery({query, variables});
|
||||||
if (data) {
|
if (project) {
|
||||||
data.project.entries.splice(data.project.entries.findIndex(entry => entry.id === projectEntry.id), 1);
|
const index = project.entries.findIndex(entry => entry.id === projectEntry.id);
|
||||||
|
const entries = removeAtIndexImmutably(project.entries, index);
|
||||||
|
const data = {
|
||||||
|
project: {
|
||||||
|
...project,
|
||||||
|
entries
|
||||||
|
}
|
||||||
|
};
|
||||||
store.writeQuery({query, variables, data});
|
store.writeQuery({query, variables, data});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue