Refactor frontend API calls into hooks and complete task states
This commit is contained in:
@@ -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]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user