* Reset snapshot state when event is moved

* Add page listener for review page

* Add same listener for search page

* Use content height
This commit is contained in:
Nicolas Mowen 2024-10-02 08:32:12 -06:00 committed by GitHub
parent 20c3b890ae
commit 0aad7db2d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 53 additions and 15 deletions

View File

@ -12,7 +12,7 @@ import {
import { Event } from "@/types/event"; import { Event } from "@/types/event";
import { FrigateConfig } from "@/types/frigateConfig"; import { FrigateConfig } from "@/types/frigateConfig";
import axios from "axios"; import axios from "axios";
import { useCallback, useMemo, useState } from "react"; import { useCallback, useEffect, useMemo, useState } from "react";
import { isDesktop } from "react-device-detect"; import { isDesktop } from "react-device-detect";
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch"; import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
import useSWR from "swr"; import useSWR from "swr";
@ -62,6 +62,11 @@ export function FrigatePlusDialog({
upload?.plus_id ? "submitted" : "reviewing", upload?.plus_id ? "submitted" : "reviewing",
); );
useEffect(
() => setState(upload?.plus_id ? "submitted" : "reviewing"),
[upload],
);
const onSubmitToPlus = useCallback( const onSubmitToPlus = useCallback(
async (falsePositive: boolean) => { async (falsePositive: boolean) => {
if (!upload) { if (!upload) {

View File

@ -611,16 +611,19 @@ function DetectionReview({
// keyboard // keyboard
useKeyboardListener(["a", "r"], (key, modifiers) => { useKeyboardListener(["a", "r", "PageDown", "PageUp"], (key, modifiers) => {
if (modifiers.repeat || !modifiers.down) { if (modifiers.repeat || !modifiers.down) {
return; return;
} }
if (key == "a" && modifiers.ctrl) { switch (key) {
case "a":
if (modifiers.ctrl) {
onSelectAllReviews(); onSelectAllReviews();
} }
break;
if (key == "r" && selectedReviews.length > 0) { case "r":
if (selectedReviews.length > 0) {
currentItems?.forEach((item) => { currentItems?.forEach((item) => {
if (selectedReviews.includes(item.id)) { if (selectedReviews.includes(item.id)) {
item.has_been_reviewed = true; item.has_been_reviewed = true;
@ -629,6 +632,20 @@ function DetectionReview({
}); });
setSelectedReviews([]); setSelectedReviews([]);
} }
break;
case "PageDown":
contentRef.current?.scrollBy({
top: contentRef.current.clientHeight / 2,
behavior: "smooth",
});
break;
case "PageUp":
contentRef.current?.scrollBy({
top: -contentRef.current.clientHeight / 2,
behavior: "smooth",
});
break;
}
}); });
return ( return (

View File

@ -60,6 +60,7 @@ export default function SearchView({
loadMore, loadMore,
hasMore, hasMore,
}: SearchViewProps) { }: SearchViewProps) {
const contentRef = useRef<HTMLDivElement | null>(null);
const { data: config } = useSWR<FrigateConfig>("config", { const { data: config } = useSWR<FrigateConfig>("config", {
revalidateOnFocus: false, revalidateOnFocus: false,
}); });
@ -239,13 +240,25 @@ export default function SearchView({
return newIndex; return newIndex;
}); });
break; break;
case "PageDown":
contentRef.current?.scrollBy({
top: contentRef.current.clientHeight / 2,
behavior: "smooth",
});
break;
case "PageUp":
contentRef.current?.scrollBy({
top: -contentRef.current.clientHeight / 2,
behavior: "smooth",
});
break;
} }
}, },
[uniqueResults, inputFocused], [uniqueResults, inputFocused],
); );
useKeyboardListener( useKeyboardListener(
["ArrowLeft", "ArrowRight"], ["ArrowLeft", "ArrowRight", "PageDown", "PageUp"],
onKeyboardShortcut, onKeyboardShortcut,
!inputFocused, !inputFocused,
); );
@ -346,7 +359,10 @@ export default function SearchView({
)} )}
</div> </div>
<div className="no-scrollbar flex flex-1 flex-wrap content-start gap-2 overflow-y-auto"> <div
ref={contentRef}
className="no-scrollbar flex flex-1 flex-wrap content-start gap-2 overflow-y-auto"
>
{uniqueResults?.length == 0 && !isLoading && ( {uniqueResults?.length == 0 && !isLoading && (
<div className="absolute left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 flex-col items-center justify-center text-center"> <div className="absolute left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 flex-col items-center justify-center text-center">
<LuSearchX className="size-16" /> <LuSearchX className="size-16" />