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_PARTICIPATIONS,
|
||||||
LOGGED_USER_UPCOMING_EVENTS,
|
LOGGED_USER_UPCOMING_EVENTS,
|
||||||
} from "@/graphql/participant";
|
} from "@/graphql/participant";
|
||||||
import { useQuery } from "@vue/apollo-composable";
|
import { useApolloClient, useQuery } from "@vue/apollo-composable";
|
||||||
import { computed, inject, ref, defineAsyncComponent } from "vue";
|
import { computed, inject, ref, defineAsyncComponent } from "vue";
|
||||||
import { IUser } from "@/types/current-user.model";
|
import { IUser } from "@/types/current-user.model";
|
||||||
import {
|
import {
|
||||||
@ -414,16 +414,74 @@ const loadMorePastParticipations = (): void => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const apollo = useApolloClient();
|
||||||
|
|
||||||
const eventDeleted = (eventid: string): void => {
|
const eventDeleted = (eventid: string): void => {
|
||||||
futureParticipations.value = futureParticipations.value.filter(
|
/**
|
||||||
(participation) => participation.event.id !== eventid
|
* Remove event from upcoming event participations
|
||||||
);
|
*/
|
||||||
pastParticipations.value = {
|
const upcomingEventsData = apollo.client.cache.readQuery<{
|
||||||
elements: pastParticipations.value.elements.filter(
|
loggedUser: IUser;
|
||||||
(participation) => participation.event.id !== eventid
|
}>({
|
||||||
),
|
query: LOGGED_USER_UPCOMING_EVENTS,
|
||||||
total: pastParticipations.value.total - 1,
|
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<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();
|
const { restrictions } = useRestrictions();
|
||||||
|
Loading…
Reference in New Issue
Block a user