This commit is contained in:
ben
2026-08-20 12:23:30 +02:00
parent e61750f314
commit a980812137
9 changed files with 351 additions and 106 deletions
+9 -4
View File
@@ -12,10 +12,15 @@ export function useRooms() {
// activeRoomId === null => all rooms combined via /events
export function useEvents(activeRoomId: number | null, from?: string, to?: string) {
const key = activeRoomId === null ? ["events", from, to] : ["room-events", activeRoomId, from, to]
const { data, error, isLoading, mutate } = useSWR(key, () =>
activeRoomId === null
? api.getUserEvents(from, to)
: api.getRoomEvents(activeRoomId, from, to),
const { data, error, isLoading, mutate } = useSWR(
key,
() =>
activeRoomId === null
? api.getUserEvents(from, to)
: api.getRoomEvents(activeRoomId, from, to),
// Keep showing the previous week/room's events while the new key loads,
// instead of flashing an empty/loading state on every switch.
{ keepPreviousData: true },
)
return { events: data ?? [], error, isLoading, mutate }
}