From cfd10ea96078f03ad3b4f5682e37078ffae16ee4 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 20 Apr 2023 16:57:23 +0200 Subject: [PATCH] fix(front): Fix behaviour when deleting an event from event list Signed-off-by: Thomas Citharel --- js/src/views/Event/MyEventsView.vue | 78 +++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 10 deletions(-) diff --git a/js/src/views/Event/MyEventsView.vue b/js/src/views/Event/MyEventsView.vue index 65b30ead9..3c0528198 100644 --- a/js/src/views/Event/MyEventsView.vue +++ b/js/src/views/Event/MyEventsView.vue @@ -226,7 +226,7 @@ import { LOGGED_USER_PARTICIPATIONS, LOGGED_USER_UPCOMING_EVENTS, } from "@/graphql/participant"; -import { useQuery } from "@vue/apollo-composable"; +import { useApolloClient, useQuery } from "@vue/apollo-composable"; import { computed, inject, ref, defineAsyncComponent } from "vue"; import { IUser } from "@/types/current-user.model"; import { @@ -414,16 +414,74 @@ const loadMorePastParticipations = (): void => { } }; +const apollo = useApolloClient(); + const eventDeleted = (eventid: string): void => { - futureParticipations.value = futureParticipations.value.filter( - (participation) => participation.event.id !== eventid - ); - pastParticipations.value = { - elements: pastParticipations.value.elements.filter( - (participation) => participation.event.id !== eventid - ), - total: pastParticipations.value.total - 1, - }; + /** + * Remove event from upcoming event participations + */ + const upcomingEventsData = apollo.client.cache.readQuery<{ + loggedUser: IUser; + }>({ + query: LOGGED_USER_UPCOMING_EVENTS, + variables: () => ({ + page: 1, + limit: 10, + afterDateTime: dateFilter.value, + }), + }); + if (!upcomingEventsData) return; + let loggedUser = upcomingEventsData?.loggedUser; + let participations = loggedUser?.participations; + apollo.client.cache.writeQuery<{ loggedUser: IUser }>({ + query: LOGGED_USER_UPCOMING_EVENTS, + variables: () => ({ + page: 1, + limit: 10, + afterDateTime: dateFilter.value, + }), + data: { + loggedUser: { + ...loggedUser, + participations: { + total: participations.total - 1, + elements: participations.elements.filter( + (participation) => participation.event.id !== eventid + ), + }, + }, + }, + }); + + /** + * Remove event from past event participations + */ + const participationData = apollo.client.cache.readQuery<{ + loggedUser: Pick; + }>({ + query: LOGGED_USER_PARTICIPATIONS, + variables: () => ({ page: 1, limit: 10 }), + }); + if (!participationData) return; + const loggedUser2 = participationData?.loggedUser; + const participations2 = loggedUser?.participations; + apollo.client.cache.writeQuery<{ + loggedUser: Pick; + }>({ + query: LOGGED_USER_PARTICIPATIONS, + variables: () => ({ page: 1, limit: 10 }), + data: { + loggedUser: { + ...loggedUser2, + participations: { + total: participations2.total - 1, + elements: participations2.elements.filter( + (participation) => participation.event.id !== eventid + ), + }, + }, + }, + }); }; const { restrictions } = useRestrictions();