chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { useFetcher } from "@remix-run/react";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useTypedLoaderData } from "remix-typedjson";
|
||||
import type { loader } from "~/root";
|
||||
|
||||
export function TimezoneSetter() {
|
||||
const { timezone: storedTimezone } = useTypedLoaderData<typeof loader>();
|
||||
const fetcher = useFetcher();
|
||||
const hasSetTimezone = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (hasSetTimezone.current) return;
|
||||
|
||||
const browserTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
|
||||
if (browserTimezone && browserTimezone !== storedTimezone) {
|
||||
hasSetTimezone.current = true;
|
||||
fetcher.submit(
|
||||
{ timezone: browserTimezone },
|
||||
{
|
||||
method: "POST",
|
||||
action: "/resources/timezone",
|
||||
encType: "application/json",
|
||||
}
|
||||
);
|
||||
}
|
||||
}, [storedTimezone, fetcher]);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user