Use memo for recordings timezone (#5086)

This commit is contained in:
Nicolas Mowen 2023-01-14 10:03:29 -07:00 committed by GitHub
parent 24410849b7
commit 19d17c8c81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 7 deletions

View File

@ -296,6 +296,7 @@ export default function Events({ path, ...props }) {
} }
const timezone = config.ui?.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone; const timezone = config.ui?.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone;
const locale = window.navigator?.language || 'en-US';
return ( return (
<div className="space-y-4 p-2 px-4 w-full"> <div className="space-y-4 p-2 px-4 w-full">
@ -514,8 +515,8 @@ export default function Events({ path, ...props }) {
({(event.top_score * 100).toFixed(0)}%) ({(event.top_score * 100).toFixed(0)}%)
</div> </div>
<div className="text-sm"> <div className="text-sm">
{new Date(event.start_time * 1000).toLocaleDateString({ timeZone: timezone })}{' '} {new Date(event.start_time * 1000).toLocaleDateString(locale, { timeZone: timezone })}{' '}
{new Date(event.start_time * 1000).toLocaleTimeString({ timeZone: timezone })} ( {new Date(event.start_time * 1000).toLocaleTimeString(locale, { timeZone: timezone })} (
{clipDuration(event.start_time, event.end_time)}) {clipDuration(event.start_time, event.end_time)})
</div> </div>
<div className="capitalize text-sm flex align-center mt-1"> <div className="capitalize text-sm flex align-center mt-1">

View File

@ -10,11 +10,11 @@ import useSWR from 'swr';
export default function Recording({ camera, date, hour = '00', minute = '00', second = '00' }) { export default function Recording({ camera, date, hour = '00', minute = '00', second = '00' }) {
const { data: config } = useSWR('config'); const { data: config } = useSWR('config');
let timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const currentDate = useMemo( const currentDate = useMemo(
() => (date ? parseISO(`${date}T${hour || '00'}:${minute || '00'}:${second || '00'}`) : new Date()), () => (date ? parseISO(`${date}T${hour || '00'}:${minute || '00'}:${second || '00'}`) : new Date()),
[date, hour, minute, second] [date, hour, minute, second]
); );
const timezone = useMemo(() => config.ui?.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone, [config]);
const apiHost = useApiHost(); const apiHost = useApiHost();
const { data: recordingsSummary } = useSWR([`${camera}/recordings/summary`, { timezone }], { const { data: recordingsSummary } = useSWR([`${camera}/recordings/summary`, { timezone }], {
@ -118,10 +118,6 @@ export default function Recording({ camera, date, hour = '00', minute = '00', se
return <ActivityIndicator />; return <ActivityIndicator />;
} }
if (config.ui.timezone) {
timezone = config.ui.timezone;
}
if (recordingsSummary.length === 0) { if (recordingsSummary.length === 0) {
return ( return (
<div className="space-y-4"> <div className="space-y-4">