Move auth and timezone hooks into dedicated hook files

This commit is contained in:
2026-04-18 20:35:28 +02:00
parent d9550ae4aa
commit fba7675eb8
8 changed files with 40 additions and 49 deletions

View File

@@ -9,19 +9,19 @@
* always receive a safe fallback.
*/
import { createContext, useContext, useMemo } from "react";
import { createContext, useMemo } from "react";
import { useTimezoneData } from "../hooks/useTimezoneData";
// ---------------------------------------------------------------------------
// Context definition
// ---------------------------------------------------------------------------
interface TimezoneContextValue {
export interface TimezoneContextValue {
/** IANA timezone string, e.g. ``"Europe/Berlin"`` or ``"UTC"``. */
timezone: string;
}
const TimezoneContext = createContext<TimezoneContextValue>({ timezone: "UTC" });
export const TimezoneContext = createContext<TimezoneContextValue | undefined>(undefined);
// ---------------------------------------------------------------------------
// Provider
@@ -53,24 +53,3 @@ export function TimezoneProvider({
<TimezoneContext.Provider value={value}>{children}</TimezoneContext.Provider>
);
}
// ---------------------------------------------------------------------------
// Hook
// ---------------------------------------------------------------------------
/**
* Return the IANA timezone string configured during setup.
*
* Must be used inside a {@link TimezoneProvider}.
*
* @returns The configured timezone, e.g. ``"Europe/Berlin"``.
*
* @example
* ```tsx
* const { timezone } = useTimezone();
* const label = formatDate(item.created_at, timezone);
* ```
*/
export function useTimezone(): string {
return useContext(TimezoneContext).timezone;
}