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
@@ -53,6 +53,13 @@ export function toInputDateTime(date: Date): string {
return toBackendDateTime(date).replace(" ", "T")
}
// For <input type="time"> values ("HH:MM").
export function toInputTime(date: Date): string {
const h = String(date.getHours()).padStart(2, "0")
const mi = String(date.getMinutes()).padStart(2, "0")
return `${h}:${mi}`
}
export function formatTime(date: Date): string {
if (isNaN(date.getTime())) return "--:--"
return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", hour12: false })
+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 }
}