Make cache update immutable
This commit is contained in:
parent
35b0094670
commit
6ce2f297d7
|
|
@ -1,5 +1,8 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="room-entry">
|
<div
|
||||||
|
class="room-entry"
|
||||||
|
data-cy="room-entry"
|
||||||
|
>
|
||||||
<router-link
|
<router-link
|
||||||
:to="{name: 'article', params: { slug: slug }}"
|
:to="{name: 'article', params: { slug: slug }}"
|
||||||
class="room-entry__router-link"
|
class="room-entry__router-link"
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
<popover-link
|
<popover-link
|
||||||
icon="trash-icon"
|
icon="trash-icon"
|
||||||
text="Eintrag löschen"
|
text="Eintrag löschen"
|
||||||
|
data-cy="delete-room-entry"
|
||||||
@link-action="deleteRoomEntry(slug)"
|
@link-action="deleteRoomEntry(slug)"
|
||||||
/>
|
/>
|
||||||
<popover-link
|
<popover-link
|
||||||
|
|
@ -20,6 +21,7 @@
|
||||||
import DELETE_ROOM_ENTRY_MUTATION from 'gql/mutations/rooms/deleteRoomEntry';
|
import DELETE_ROOM_ENTRY_MUTATION from 'gql/mutations/rooms/deleteRoomEntry';
|
||||||
import ROOM_ENTRIES_QUERY from 'gql/queries/roomEntriesQuery';
|
import ROOM_ENTRIES_QUERY from 'gql/queries/roomEntriesQuery';
|
||||||
import {UPDATE_ROOM_ENTRY_PAGE} from '@/router/room.names';
|
import {UPDATE_ROOM_ENTRY_PAGE} from '@/router/room.names';
|
||||||
|
import {removeAtIndex} from '@/graphql/immutable-operations';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
|
|
@ -53,10 +55,18 @@
|
||||||
if (success) {
|
if (success) {
|
||||||
const query = ROOM_ENTRIES_QUERY;
|
const query = ROOM_ENTRIES_QUERY;
|
||||||
const variables = {slug: roomSlug};
|
const variables = {slug: roomSlug};
|
||||||
const data = store.readQuery({query, variables});
|
const {room} = store.readQuery({query, variables});
|
||||||
if (data) {
|
if (room) {
|
||||||
// todo: make immutable
|
const index = room.roomEntries.edges.findIndex(edge => edge.node.slug === slug);
|
||||||
data.room.roomEntries.edges.splice(data.room.roomEntries.edges.findIndex(edge => edge.node.slug === slug), 1);
|
const edges = removeAtIndex(room.roomEntries.edges, index);
|
||||||
|
const data = {
|
||||||
|
room: {
|
||||||
|
...room,
|
||||||
|
roomEntries: {
|
||||||
|
edges
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
store.writeQuery({query, data, variables});
|
store.writeQuery({query, data, variables});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue