Add new helper functions
This commit is contained in:
parent
82aa04bf90
commit
3403c2db3d
|
|
@ -54,6 +54,16 @@
|
|||
import {dateFilter, dateTimeFilter} from '@/filters/date-filter';
|
||||
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 {
|
||||
props: ['description', 'documentUrl', 'created', 'id', 'readOnly'],
|
||||
components: {
|
||||
|
|
@ -89,9 +99,16 @@
|
|||
const variables = {
|
||||
slug: projectEntry.$route.params.slug,
|
||||
};
|
||||
const data = store.readQuery({query, variables});
|
||||
if (data) {
|
||||
data.project.entries.splice(data.project.entries.findIndex(entry => entry.id === projectEntry.id), 1);
|
||||
const {project} = store.readQuery({query, variables});
|
||||
if (project) {
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue