mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Improve refreshing of review items (#10675)
This commit is contained in:
parent
7b7d3c56cc
commit
30d93e1d90
@ -1,45 +1,29 @@
|
|||||||
import { useFrigateReviews } from "@/api/ws";
|
import { ReviewSegment } from "@/types/review";
|
||||||
import { ReviewSeverity } from "@/types/review";
|
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { LuRefreshCcw } from "react-icons/lu";
|
import { LuRefreshCcw } from "react-icons/lu";
|
||||||
import { MutableRefObject, useEffect, useMemo, useState } from "react";
|
import { MutableRefObject, useMemo } from "react";
|
||||||
|
|
||||||
type NewReviewDataProps = {
|
type NewReviewDataProps = {
|
||||||
className: string;
|
className: string;
|
||||||
contentRef: MutableRefObject<HTMLDivElement | null>;
|
contentRef: MutableRefObject<HTMLDivElement | null>;
|
||||||
severity: ReviewSeverity;
|
reviewItems?: ReviewSegment[] | null;
|
||||||
hasUpdate: boolean;
|
itemsToReview?: number;
|
||||||
setHasUpdate: (update: boolean) => void;
|
|
||||||
pullLatestData: () => void;
|
pullLatestData: () => void;
|
||||||
};
|
};
|
||||||
export default function NewReviewData({
|
export default function NewReviewData({
|
||||||
className,
|
className,
|
||||||
contentRef,
|
contentRef,
|
||||||
severity,
|
reviewItems,
|
||||||
hasUpdate,
|
itemsToReview,
|
||||||
setHasUpdate,
|
|
||||||
pullLatestData,
|
pullLatestData,
|
||||||
}: NewReviewDataProps) {
|
}: NewReviewDataProps) {
|
||||||
const { payload: review } = useFrigateReviews();
|
const hasUpdate = useMemo(() => {
|
||||||
|
if (!reviewItems || !itemsToReview) {
|
||||||
const startCheckTs = useMemo(() => Date.now() / 1000, []);
|
return false;
|
||||||
const [reviewTs, setReviewTs] = useState(startCheckTs);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!review) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (review.type == "end" && review.review.severity == severity) {
|
return reviewItems.length != itemsToReview;
|
||||||
setReviewTs(review.review.start_time);
|
}, [reviewItems, itemsToReview]);
|
||||||
}
|
|
||||||
}, [review, severity]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (reviewTs > startCheckTs) {
|
|
||||||
setHasUpdate(true);
|
|
||||||
}
|
|
||||||
}, [startCheckTs, reviewTs, setHasUpdate]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
@ -52,7 +36,6 @@ export default function NewReviewData({
|
|||||||
} text-center mt-5 mx-auto bg-gray-400 text-white`}
|
} text-center mt-5 mx-auto bg-gray-400 text-white`}
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setHasUpdate(false);
|
|
||||||
pullLatestData();
|
pullLatestData();
|
||||||
if (contentRef.current) {
|
if (contentRef.current) {
|
||||||
contentRef.current.scrollTo({
|
contentRef.current.scrollTo({
|
||||||
|
@ -18,7 +18,9 @@ import { useCallback, useEffect, useMemo, useState } from "react";
|
|||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
export default function Events() {
|
export default function Events() {
|
||||||
const { data: config } = useSWR<FrigateConfig>("config");
|
const { data: config } = useSWR<FrigateConfig>("config", {
|
||||||
|
revalidateOnFocus: false,
|
||||||
|
});
|
||||||
const timezone = useTimezone(config);
|
const timezone = useTimezone(config);
|
||||||
|
|
||||||
// recordings viewer
|
// recordings viewer
|
||||||
@ -66,6 +68,9 @@ export default function Events() {
|
|||||||
};
|
};
|
||||||
}, [last24Hours, reviewSearchParams]);
|
}, [last24Hours, reviewSearchParams]);
|
||||||
|
|
||||||
|
// we want to update the items whenever the severity changes
|
||||||
|
useEffect(() => setBeforeTs(Date.now() / 1000), [severity]);
|
||||||
|
|
||||||
const reviewSegmentFetcher = useCallback((key: Array<string> | string) => {
|
const reviewSegmentFetcher = useCallback((key: Array<string> | string) => {
|
||||||
const [path, params] = Array.isArray(key) ? key : [key, undefined];
|
const [path, params] = Array.isArray(key) ? key : [key, undefined];
|
||||||
return axios.get(path, { params }).then((res) => res.data);
|
return axios.get(path, { params }).then((res) => res.data);
|
||||||
@ -93,15 +98,21 @@ export default function Events() {
|
|||||||
|
|
||||||
// review summary
|
// review summary
|
||||||
|
|
||||||
const { data: reviewSummary, mutate: updateSummary } = useSWR<ReviewSummary>([
|
const { data: reviewSummary, mutate: updateSummary } = useSWR<ReviewSummary>(
|
||||||
"review/summary",
|
[
|
||||||
|
"review/summary",
|
||||||
|
{
|
||||||
|
timezone: timezone,
|
||||||
|
cameras: reviewSearchParams["cameras"] ?? null,
|
||||||
|
labels: reviewSearchParams["labels"] ?? null,
|
||||||
|
},
|
||||||
|
],
|
||||||
{
|
{
|
||||||
timezone: timezone,
|
revalidateOnFocus: true,
|
||||||
cameras: reviewSearchParams["cameras"] ?? null,
|
refreshInterval: 30000,
|
||||||
labels: reviewSearchParams["labels"] ?? null,
|
revalidateOnReconnect: false,
|
||||||
},
|
},
|
||||||
{ revalidateOnFocus: false, revalidateOnReconnect: false },
|
);
|
||||||
]);
|
|
||||||
|
|
||||||
const reloadData = useCallback(() => {
|
const reloadData = useCallback(() => {
|
||||||
setBeforeTs(Date.now() / 1000);
|
setBeforeTs(Date.now() / 1000);
|
||||||
|
@ -382,10 +382,6 @@ function DetectionReview({
|
|||||||
[previewTime, setPreviewTime],
|
[previewTime, setPreviewTime],
|
||||||
);
|
);
|
||||||
|
|
||||||
// review interaction
|
|
||||||
|
|
||||||
const [hasUpdate, setHasUpdate] = useState(false);
|
|
||||||
|
|
||||||
// timeline interaction
|
// timeline interaction
|
||||||
|
|
||||||
const timelineDuration = useMemo(
|
const timelineDuration = useMemo(
|
||||||
@ -498,9 +494,8 @@ function DetectionReview({
|
|||||||
<NewReviewData
|
<NewReviewData
|
||||||
className="absolute w-full z-30 pointer-events-none"
|
className="absolute w-full z-30 pointer-events-none"
|
||||||
contentRef={contentRef}
|
contentRef={contentRef}
|
||||||
severity={severity}
|
reviewItems={currentItems}
|
||||||
hasUpdate={hasUpdate}
|
itemsToReview={itemsToReview}
|
||||||
setHasUpdate={setHasUpdate}
|
|
||||||
pullLatestData={pullLatestData}
|
pullLatestData={pullLatestData}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@ -555,7 +550,6 @@ function DetectionReview({
|
|||||||
className="text-white"
|
className="text-white"
|
||||||
variant="select"
|
variant="select"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setHasUpdate(false);
|
|
||||||
markAllItemsAsReviewed(currentItems ?? []);
|
markAllItemsAsReviewed(currentItems ?? []);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user