fix:#3 fetch room occupancy once

This commit is contained in:
survellow
2024-07-23 14:21:47 +02:00
parent a26a592ed7
commit fd2d19ab98
4 changed files with 73 additions and 16 deletions

View File

@@ -86,7 +86,7 @@ const { data: occupations } = useQuery({
showFree: event.free,
})),
enabled: () => selectedRoom.value !== "" && currentDateFrom.value !== "",
staleTime: 5000000, // 500 seconds
staleTime: 5000000, // 5000 seconds
});
watch(occupations, () => fullCalendar.value?.getApi().refetchEvents());

View File

@@ -87,16 +87,16 @@ function transformData(data: RoomOccupancyList) {
return events;
}
const { data: occupations } = useQuery({
queryKey: ["roomOccupation", selectedRoom, currentDateFrom, currentDateTo],
const { data: occupancy } = useQuery({
queryKey: ["roomOccupancy"],//, selectedRoom, currentDateFrom, currentDateTo],
queryFn: () =>
fetchRoomOccupancy(
new Date(currentDateFrom.value).toISOString(),
new Date(currentDateTo.value).toISOString()
),
select: (data) => transformData(data),
enabled: () => selectedRoom.value !== "" && currentDateFrom.value !== "",
staleTime: 5000000, // 500 seconds
fetchRoomOccupancy(),
staleTime: 12 * 3600000, // 12 hours
});
const occupations = computed(() => {
if (!occupancy.value) return;
return transformData(occupancy.value);
});
watch(occupations, () => fullCalendar.value?.getApi().refetchEvents());