Make cache update immutable

This commit is contained in:
Ramon Wenger 2022-06-28 12:30:25 +02:00
parent 35b0094670
commit 6ce2f297d7
2 changed files with 18 additions and 5 deletions

View File

@ -1,5 +1,8 @@
<template>
<div class="room-entry">
<div
class="room-entry"
data-cy="room-entry"
>
<router-link
:to="{name: 'article', params: { slug: slug }}"
class="room-entry__router-link"

View File

@ -3,6 +3,7 @@
<popover-link
icon="trash-icon"
text="Eintrag löschen"
data-cy="delete-room-entry"
@link-action="deleteRoomEntry(slug)"
/>
<popover-link
@ -20,6 +21,7 @@
import DELETE_ROOM_ENTRY_MUTATION from 'gql/mutations/rooms/deleteRoomEntry';
import ROOM_ENTRIES_QUERY from 'gql/queries/roomEntriesQuery';
import {UPDATE_ROOM_ENTRY_PAGE} from '@/router/room.names';
import {removeAtIndex} from '@/graphql/immutable-operations';
export default {
props: {
@ -53,10 +55,18 @@
if (success) {
const query = ROOM_ENTRIES_QUERY;
const variables = {slug: roomSlug};
const data = store.readQuery({query, variables});
if (data) {
// todo: make immutable
data.room.roomEntries.edges.splice(data.room.roomEntries.edges.findIndex(edge => edge.node.slug === slug), 1);
const {room} = store.readQuery({query, variables});
if (room) {
const index = room.roomEntries.edges.findIndex(edge => edge.node.slug === slug);
const edges = removeAtIndex(room.roomEntries.edges, index);
const data = {
room: {
...room,
roomEntries: {
edges
}
}
};
store.writeQuery({query, data, variables});
}
}