mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Improve preview loading (#11469)
* Improve preview loading * Ensure it works when selecting dates
This commit is contained in:
parent
2a86969f54
commit
cc3bbcc303
@ -27,31 +27,8 @@ export function useCameraPreviews(
|
||||
fetchPreviews
|
||||
? `preview/${camera}/start/${Math.round(timeRange.after)}/end/${Math.round(timeRange.before)}`
|
||||
: null,
|
||||
{ revalidateOnFocus: false, revalidateOnReconnect: false },
|
||||
{ revalidateOnFocus: autoRefresh, revalidateOnReconnect: autoRefresh },
|
||||
);
|
||||
|
||||
// Set a timeout to update previews on the hour
|
||||
useEffect(() => {
|
||||
if (!autoRefresh || !fetchPreviews || !allPreviews) {
|
||||
return;
|
||||
}
|
||||
|
||||
const callback = () => {
|
||||
const nextPreviewStart = new Date(
|
||||
allPreviews[allPreviews.length - 1].end * 1000,
|
||||
);
|
||||
nextPreviewStart.setHours(nextPreviewStart.getHours() + 1);
|
||||
|
||||
if (Date.now() > nextPreviewStart.getTime()) {
|
||||
setTimeRange({ after: timeRange.after, before: Date.now() / 1000 });
|
||||
}
|
||||
};
|
||||
document.addEventListener("focusin", callback);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("focusin", callback);
|
||||
};
|
||||
}, [allPreviews, autoRefresh, fetchPreviews, timeRange]);
|
||||
|
||||
return allPreviews;
|
||||
}
|
||||
|
@ -163,24 +163,20 @@ export default function Events() {
|
||||
|
||||
// preview videos
|
||||
const previewTimes = useMemo(() => {
|
||||
if (!reviews || reviews.length == 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// offset by timezone minutes
|
||||
const timestampOffset = getTimestampOffset(Date.now() / 1000);
|
||||
|
||||
const startDate = new Date();
|
||||
const startDate = new Date(selectedTimeRange.after * 1000);
|
||||
startDate.setMinutes(0, 0, 0);
|
||||
|
||||
const endDate = new Date(reviews.at(-1)?.end_time || 0);
|
||||
endDate.setHours(0, 0, 0, 0);
|
||||
const endDate = new Date(selectedTimeRange.before * 1000);
|
||||
endDate.setHours(endDate.getHours() + 1, 0, 0, 0);
|
||||
|
||||
return {
|
||||
after: startDate.getTime() / 1000 + timestampOffset,
|
||||
before: endDate.getTime() / 1000 + timestampOffset,
|
||||
};
|
||||
}, [reviews]);
|
||||
}, [selectedTimeRange]);
|
||||
|
||||
const allPreviews = useCameraPreviews(
|
||||
previewTimes ?? { after: 0, before: 0 },
|
||||
|
Loading…
Reference in New Issue
Block a user