msg
This commit is contained in:
@@ -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 })
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user