diff --git a/src/src/components/Contexts/SettingsContext.tsx b/src/src/components/Contexts/SettingsContext.tsx index 80980ce..0b14561 100644 --- a/src/src/components/Contexts/SettingsContext.tsx +++ b/src/src/components/Contexts/SettingsContext.tsx @@ -4,6 +4,7 @@ import { AuthContext } from './AuthContext'; type UserSettings = { readonly weekStart: number; + readonly timeZone: string }; export function SettingsProvider({ @@ -14,6 +15,8 @@ export function SettingsProvider({ const { token } = React.useContext(AuthContext); const [weekStart, setWeekStart] = React.useState(0); const [found, setFound] = React.useState(false); + const [timeZone, setTimeZone] = React.useState("default"); + const [foundTimeZone, setFoundTimeZone] = React.useState(false); // If the token has been set, try an update // Also make sure we havent already fetched @@ -31,11 +34,26 @@ export function SettingsProvider({ } }, [token]); + React.useEffect(() => { + if (token && !foundTimeZone) { + ajax('https://www.googleapis.com/calendar/v3/users/me/settings/timezone') + .then((res) => res.json()) + .then((val) => { + if (typeof val['value'] === 'string') { + let timezone = val['value']; + setTimeZone(timezone); + setFoundTimeZone(true); + } + }); + } + }, [token]); + const userSettings = React.useMemo( () => ({ weekStart, + timeZone }), - [weekStart] + [weekStart, timeZone] ); return ( @@ -47,5 +65,6 @@ export function SettingsProvider({ export const SettingsContext = React.createContext({ weekStart: 0, + timeZone: "default" }); SettingsContext.displayName = 'SettingsContext';