fix(front): Fix behaviour when deleting an event from event list
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
7872100af3
commit
cfd10ea960
|
@ -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(
|
||||
/**
|
||||
* 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
|
||||
),
|
||||
total: pastParticipations.value.total - 1,
|
||||
};
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Remove event from past event participations
|
||||
*/
|
||||
const participationData = apollo.client.cache.readQuery<{
|
||||
loggedUser: Pick<IUser, "participations">;
|
||||
}>({
|
||||
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<IUser, "participations">;
|
||||
}>({
|
||||
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();
|
||||
|
|
Loading…
Reference in a new issue