Refactor frontend API calls into hooks and complete task states

This commit is contained in:
2026-03-20 15:18:04 +01:00
parent d30d138146
commit 28a7610276
16 changed files with 483 additions and 409 deletions

View File

@@ -9,15 +9,8 @@
* always receive a safe fallback.
*/
import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from "react";
import { fetchTimezone } from "../api/setup";
import { createContext, useContext, useMemo } from "react";
import { useTimezoneData } from "../hooks/useTimezoneData";
// ---------------------------------------------------------------------------
// Context definition
@@ -52,19 +45,7 @@ export interface TimezoneProviderProps {
export function TimezoneProvider({
children,
}: TimezoneProviderProps): React.JSX.Element {
const [timezone, setTimezone] = useState<string>("UTC");
const load = useCallback((): void => {
fetchTimezone()
.then((resp) => { setTimezone(resp.timezone); })
.catch(() => {
// Silently fall back to UTC; the backend may not be reachable yet.
});
}, []);
useEffect(() => {
load();
}, [load]);
const { timezone } = useTimezoneData();
const value = useMemo<TimezoneContextValue>(() => ({ timezone }), [timezone]);