2024-10-06 20:43:36 +03:00
|
|
|
import { isDesktop, isIOS, isMobile, isSafari } from "react-device-detect";
|
2024-06-23 23:58:00 +03:00
|
|
|
import { SearchResult } from "@/types/search";
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
|
|
|
|
import { useFormattedTimestamp } from "@/hooks/use-date-utils";
|
|
|
|
|
import { getIconForLabel } from "@/utils/iconUtil";
|
|
|
|
|
import { useApiHost } from "@/api";
|
2024-08-14 17:02:21 +03:00
|
|
|
import { Button } from "../../ui/button";
|
2025-11-06 19:22:52 +03:00
|
|
|
import {
|
|
|
|
|
useCallback,
|
|
|
|
|
useEffect,
|
|
|
|
|
useLayoutEffect,
|
|
|
|
|
useMemo,
|
|
|
|
|
useRef,
|
|
|
|
|
useState,
|
|
|
|
|
} from "react";
|
2024-06-23 23:58:00 +03:00
|
|
|
import axios from "axios";
|
|
|
|
|
import { toast } from "sonner";
|
2024-08-14 17:02:21 +03:00
|
|
|
import { Textarea } from "../../ui/textarea";
|
2024-09-11 17:41:16 +03:00
|
|
|
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
|
|
|
|
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
|
|
|
|
|
import useOptimisticState from "@/hooks/use-optimistic-state";
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from "@/components/ui/dialog";
|
|
|
|
|
import { Event } from "@/types/event";
|
|
|
|
|
import { baseUrl } from "@/api/baseUrl";
|
|
|
|
|
import { cn } from "@/lib/utils";
|
2024-09-11 20:32:45 +03:00
|
|
|
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
2024-10-01 00:54:53 +03:00
|
|
|
import {
|
2025-02-10 23:23:42 +03:00
|
|
|
FaArrowRight,
|
2024-10-06 20:43:36 +03:00
|
|
|
FaCheckCircle,
|
2025-11-06 19:22:52 +03:00
|
|
|
FaChevronLeft,
|
|
|
|
|
FaChevronRight,
|
2025-11-08 22:26:30 +03:00
|
|
|
FaMicrophone,
|
|
|
|
|
FaCheck,
|
|
|
|
|
FaTimes,
|
2024-10-01 00:54:53 +03:00
|
|
|
} from "react-icons/fa";
|
2025-11-01 17:19:30 +03:00
|
|
|
import { TrackingDetails } from "./TrackingDetails";
|
2025-11-06 19:22:52 +03:00
|
|
|
import { AnnotationSettingsPane } from "./AnnotationSettingsPane";
|
2025-11-01 17:19:30 +03:00
|
|
|
import { DetailStreamProvider } from "@/context/detail-stream-context";
|
2024-09-12 22:39:35 +03:00
|
|
|
import {
|
|
|
|
|
MobilePage,
|
|
|
|
|
MobilePageContent,
|
|
|
|
|
MobilePageDescription,
|
|
|
|
|
MobilePageHeader,
|
|
|
|
|
MobilePageTitle,
|
|
|
|
|
} from "@/components/mobile/MobilePage";
|
2024-09-13 23:44:31 +03:00
|
|
|
import {
|
|
|
|
|
Tooltip,
|
|
|
|
|
TooltipContent,
|
|
|
|
|
TooltipTrigger,
|
|
|
|
|
} from "@/components/ui/tooltip";
|
2025-11-06 19:22:52 +03:00
|
|
|
import { REVIEW_PADDING } from "@/types/review";
|
2024-10-02 01:05:16 +03:00
|
|
|
import { capitalizeAll } from "@/utils/stringUtil";
|
2024-09-24 17:14:51 +03:00
|
|
|
import useGlobalMutation from "@/hooks/use-global-mutate";
|
2025-11-06 19:22:52 +03:00
|
|
|
import DetailActionsMenu from "./DetailActionsMenu";
|
2024-10-01 00:54:53 +03:00
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from "@/components/ui/dropdown-menu";
|
2024-10-06 20:43:36 +03:00
|
|
|
import { TransformComponent, TransformWrapper } from "react-zoom-pan-pinch";
|
|
|
|
|
import useImageLoaded from "@/hooks/use-image-loaded";
|
|
|
|
|
import ImageLoadingIndicator from "@/components/indicators/ImageLoadingIndicator";
|
2024-10-13 20:46:40 +03:00
|
|
|
import { GenericVideoPlayer } from "@/components/player/GenericVideoPlayer";
|
2024-10-17 14:30:52 +03:00
|
|
|
import {
|
|
|
|
|
Popover,
|
|
|
|
|
PopoverContent,
|
|
|
|
|
PopoverTrigger,
|
|
|
|
|
} from "@/components/ui/popover";
|
2025-11-08 15:44:30 +03:00
|
|
|
import {
|
|
|
|
|
Drawer,
|
|
|
|
|
DrawerContent,
|
|
|
|
|
DrawerTitle,
|
|
|
|
|
DrawerTrigger,
|
|
|
|
|
} from "@/components/ui/drawer";
|
2025-11-06 19:22:52 +03:00
|
|
|
import { LuInfo } from "react-icons/lu";
|
2024-10-23 06:09:57 +03:00
|
|
|
import { TooltipPortal } from "@radix-ui/react-tooltip";
|
2025-02-24 02:56:48 +03:00
|
|
|
import { FaPencilAlt } from "react-icons/fa";
|
|
|
|
|
import TextEntryDialog from "@/components/overlay/dialog/TextEntryDialog";
|
2025-04-17 16:34:24 +03:00
|
|
|
import { Trans, useTranslation } from "react-i18next";
|
2025-04-10 17:27:01 +03:00
|
|
|
import { useIsAdmin } from "@/hooks/use-is-admin";
|
2025-06-26 17:25:47 +03:00
|
|
|
import { getTranslatedLabel } from "@/utils/i18n";
|
2025-11-07 17:02:06 +03:00
|
|
|
import { CameraNameLabel } from "@/components/camera/FriendlyNameLabel";
|
2025-11-06 19:22:52 +03:00
|
|
|
import { DialogPortal } from "@radix-ui/react-dialog";
|
|
|
|
|
import { useDetailStream } from "@/context/detail-stream-context";
|
|
|
|
|
import { PiSlidersHorizontalBold } from "react-icons/pi";
|
2025-11-08 22:26:30 +03:00
|
|
|
import { HiSparkles } from "react-icons/hi";
|
2025-11-24 16:34:56 +03:00
|
|
|
import { useAudioTranscriptionProcessState } from "@/api/ws";
|
2024-09-11 17:41:16 +03:00
|
|
|
|
2025-11-01 17:19:30 +03:00
|
|
|
const SEARCH_TABS = ["snapshot", "tracking_details"] as const;
|
2024-10-15 16:24:47 +03:00
|
|
|
export type SearchTab = (typeof SEARCH_TABS)[number];
|
2024-06-23 23:58:00 +03:00
|
|
|
|
2025-11-06 19:22:52 +03:00
|
|
|
type TabsWithActionsProps = {
|
|
|
|
|
search: SearchResult;
|
|
|
|
|
searchTabs: SearchTab[];
|
|
|
|
|
pageToggle: SearchTab;
|
|
|
|
|
setPageToggle: (v: SearchTab) => void;
|
|
|
|
|
config?: FrigateConfig;
|
|
|
|
|
setSearch: (s: SearchResult | undefined) => void;
|
|
|
|
|
setSimilarity?: () => void;
|
|
|
|
|
isPopoverOpen: boolean;
|
|
|
|
|
setIsPopoverOpen: (open: boolean) => void;
|
|
|
|
|
dialogContainer: HTMLDivElement | null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function TabsWithActions({
|
|
|
|
|
search,
|
|
|
|
|
searchTabs,
|
|
|
|
|
pageToggle,
|
|
|
|
|
setPageToggle,
|
|
|
|
|
config,
|
|
|
|
|
setSearch,
|
|
|
|
|
setSimilarity,
|
|
|
|
|
isPopoverOpen,
|
|
|
|
|
setIsPopoverOpen,
|
|
|
|
|
dialogContainer,
|
|
|
|
|
}: TabsWithActionsProps) {
|
|
|
|
|
const { t } = useTranslation(["views/explore", "views/faceLibrary"]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (pageToggle !== "tracking_details" && isPopoverOpen) {
|
|
|
|
|
setIsPopoverOpen(false);
|
|
|
|
|
}
|
|
|
|
|
}, [pageToggle, isPopoverOpen, setIsPopoverOpen]);
|
|
|
|
|
|
|
|
|
|
if (!search) return null;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex items-center justify-between gap-1">
|
|
|
|
|
<ScrollArea className="flex-1 whitespace-nowrap">
|
2025-11-08 15:44:30 +03:00
|
|
|
<div className="mb-2 flex flex-row">
|
2025-11-06 19:22:52 +03:00
|
|
|
<ToggleGroup
|
|
|
|
|
className="*:rounded-md *:px-3 *:py-4"
|
|
|
|
|
type="single"
|
|
|
|
|
size="sm"
|
|
|
|
|
value={pageToggle}
|
|
|
|
|
onValueChange={(value: SearchTab) => {
|
|
|
|
|
if (value) {
|
|
|
|
|
setPageToggle(value);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{Object.values(searchTabs).map((item) => (
|
|
|
|
|
<ToggleGroupItem
|
|
|
|
|
key={item}
|
|
|
|
|
className="flex scroll-mx-10 items-center justify-between gap-2 text-muted-foreground"
|
|
|
|
|
value={item}
|
|
|
|
|
data-nav-item={item}
|
|
|
|
|
aria-label={`Select ${item}`}
|
|
|
|
|
>
|
|
|
|
|
<div className="smart-capitalize">
|
|
|
|
|
{item === "snapshot"
|
|
|
|
|
? search?.has_snapshot
|
|
|
|
|
? t("type.snapshot")
|
|
|
|
|
: t("type.thumbnail")
|
|
|
|
|
: t(`type.${item}`)}
|
|
|
|
|
</div>
|
|
|
|
|
</ToggleGroupItem>
|
|
|
|
|
))}
|
|
|
|
|
</ToggleGroup>
|
|
|
|
|
<ScrollBar orientation="horizontal" className="h-0" />
|
|
|
|
|
</div>
|
|
|
|
|
</ScrollArea>
|
|
|
|
|
<DetailActionsMenu
|
|
|
|
|
search={search}
|
|
|
|
|
config={config}
|
|
|
|
|
setSearch={setSearch}
|
|
|
|
|
setSimilarity={setSimilarity}
|
|
|
|
|
/>
|
|
|
|
|
{pageToggle === "tracking_details" && (
|
|
|
|
|
<AnnotationSettings
|
|
|
|
|
search={search}
|
|
|
|
|
open={isPopoverOpen}
|
|
|
|
|
setIsOpen={setIsPopoverOpen}
|
|
|
|
|
container={dialogContainer}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type AnnotationSettingsProps = {
|
|
|
|
|
search: SearchResult;
|
|
|
|
|
open: boolean;
|
|
|
|
|
setIsOpen: (open: boolean) => void;
|
|
|
|
|
container?: HTMLElement | null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function AnnotationSettings({
|
|
|
|
|
search,
|
|
|
|
|
open,
|
|
|
|
|
setIsOpen,
|
|
|
|
|
container,
|
|
|
|
|
}: AnnotationSettingsProps) {
|
|
|
|
|
const { t } = useTranslation(["views/explore"]);
|
|
|
|
|
const { annotationOffset, setAnnotationOffset } = useDetailStream();
|
|
|
|
|
|
|
|
|
|
const ignoreNextOpenRef = useRef(false);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setIsOpen(false);
|
|
|
|
|
ignoreNextOpenRef.current = false;
|
|
|
|
|
}, [search, setIsOpen]);
|
|
|
|
|
|
|
|
|
|
const handleOpenChange = useCallback(
|
|
|
|
|
(nextOpen: boolean) => {
|
|
|
|
|
if (nextOpen) {
|
|
|
|
|
if (ignoreNextOpenRef.current) {
|
|
|
|
|
ignoreNextOpenRef.current = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setIsOpen(true);
|
|
|
|
|
} else {
|
|
|
|
|
setIsOpen(false);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[setIsOpen],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const registerTriggerCloseIntent = useCallback(() => {
|
|
|
|
|
if (open) {
|
|
|
|
|
ignoreNextOpenRef.current = true;
|
|
|
|
|
}
|
|
|
|
|
}, [open]);
|
|
|
|
|
|
|
|
|
|
const Overlay = isDesktop ? Popover : Drawer;
|
|
|
|
|
const Trigger = isDesktop ? PopoverTrigger : DrawerTrigger;
|
|
|
|
|
const Content = isDesktop ? PopoverContent : DrawerContent;
|
2025-11-08 15:44:30 +03:00
|
|
|
const Title = isDesktop ? "div" : DrawerTitle;
|
2025-11-06 19:22:52 +03:00
|
|
|
const contentProps = isDesktop
|
|
|
|
|
? { align: "end" as const, container: container ?? undefined }
|
|
|
|
|
: {};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="ml-2">
|
|
|
|
|
<Overlay modal={isDesktop} open={open} onOpenChange={handleOpenChange}>
|
|
|
|
|
<Trigger asChild>
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
className="size-7 p-1.5"
|
|
|
|
|
variant={open ? "select" : "ghost"}
|
|
|
|
|
aria-label={t("trackingDetails.adjustAnnotationSettings")}
|
|
|
|
|
aria-expanded={open}
|
|
|
|
|
onPointerDown={registerTriggerCloseIntent}
|
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
|
if (open && (event.key === "Enter" || event.key === " ")) {
|
|
|
|
|
registerTriggerCloseIntent();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<PiSlidersHorizontalBold className="size-5" />
|
|
|
|
|
</Button>
|
|
|
|
|
</Trigger>
|
2025-11-08 15:44:30 +03:00
|
|
|
<Title className="sr-only">
|
|
|
|
|
{t("trackingDetails.adjustAnnotationSettings")}
|
|
|
|
|
</Title>
|
2025-11-06 19:22:52 +03:00
|
|
|
<Content
|
|
|
|
|
className={
|
|
|
|
|
isDesktop
|
|
|
|
|
? "w-[90vw] max-w-md bg-background_alt p-0"
|
|
|
|
|
: "mx-1 max-h-[75dvh] overflow-hidden rounded-t-2xl px-4 pb-4"
|
|
|
|
|
}
|
|
|
|
|
{...contentProps}
|
|
|
|
|
{...(isDesktop ? { disablePortal: true } : {})}
|
|
|
|
|
data-annotation-popover
|
|
|
|
|
>
|
|
|
|
|
<AnnotationSettingsPane
|
|
|
|
|
event={search as unknown as Event}
|
|
|
|
|
annotationOffset={annotationOffset}
|
|
|
|
|
setAnnotationOffset={setAnnotationOffset}
|
|
|
|
|
/>
|
|
|
|
|
</Content>
|
|
|
|
|
</Overlay>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DialogContentComponentProps = {
|
|
|
|
|
page: SearchTab;
|
|
|
|
|
search: SearchResult;
|
|
|
|
|
isDesktop: boolean;
|
|
|
|
|
apiHost: string;
|
|
|
|
|
config?: FrigateConfig;
|
|
|
|
|
searchTabs: SearchTab[];
|
|
|
|
|
pageToggle: SearchTab;
|
|
|
|
|
setPageToggle: (v: SearchTab) => void;
|
|
|
|
|
setSearch: (s: SearchResult | undefined) => void;
|
|
|
|
|
setInputFocused: React.Dispatch<React.SetStateAction<boolean>>;
|
|
|
|
|
setSimilarity?: () => void;
|
|
|
|
|
isPopoverOpen: boolean;
|
|
|
|
|
setIsPopoverOpen: (open: boolean) => void;
|
|
|
|
|
dialogContainer: HTMLDivElement | null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function DialogContentComponent({
|
|
|
|
|
page,
|
|
|
|
|
search,
|
|
|
|
|
isDesktop,
|
|
|
|
|
apiHost,
|
|
|
|
|
config,
|
|
|
|
|
searchTabs,
|
|
|
|
|
pageToggle,
|
|
|
|
|
setPageToggle,
|
|
|
|
|
setSearch,
|
|
|
|
|
setInputFocused,
|
|
|
|
|
setSimilarity,
|
|
|
|
|
isPopoverOpen,
|
|
|
|
|
setIsPopoverOpen,
|
|
|
|
|
dialogContainer,
|
|
|
|
|
}: DialogContentComponentProps) {
|
|
|
|
|
if (page === "tracking_details") {
|
|
|
|
|
return (
|
|
|
|
|
<TrackingDetails
|
2025-11-08 15:44:30 +03:00
|
|
|
className={cn(isDesktop ? "size-full" : "flex flex-col gap-4")}
|
2025-11-06 19:22:52 +03:00
|
|
|
event={search as unknown as Event}
|
|
|
|
|
tabs={
|
|
|
|
|
isDesktop ? (
|
|
|
|
|
<TabsWithActions
|
|
|
|
|
search={search}
|
|
|
|
|
searchTabs={searchTabs}
|
|
|
|
|
pageToggle={pageToggle}
|
|
|
|
|
setPageToggle={setPageToggle}
|
|
|
|
|
config={config}
|
|
|
|
|
setSearch={setSearch}
|
|
|
|
|
setSimilarity={setSimilarity}
|
|
|
|
|
isPopoverOpen={isPopoverOpen}
|
|
|
|
|
setIsPopoverOpen={setIsPopoverOpen}
|
|
|
|
|
dialogContainer={dialogContainer}
|
|
|
|
|
/>
|
|
|
|
|
) : undefined
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Snapshot page content
|
|
|
|
|
const snapshotElement = search.has_snapshot ? (
|
|
|
|
|
<ObjectSnapshotTab
|
|
|
|
|
className={isDesktop ? undefined : "mb-4"}
|
|
|
|
|
search={
|
|
|
|
|
{
|
|
|
|
|
...search,
|
|
|
|
|
plus_id: config?.plus?.enabled ? search.plus_id : "not_enabled",
|
|
|
|
|
} as unknown as Event
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
2025-11-08 22:26:30 +03:00
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"max-w-lg",
|
|
|
|
|
!isDesktop ? "mb-4 w-full" : "mx-auto size-full",
|
|
|
|
|
)}
|
|
|
|
|
>
|
2025-11-06 19:22:52 +03:00
|
|
|
<img
|
|
|
|
|
className="w-full select-none rounded-lg object-contain transition-opacity"
|
|
|
|
|
style={
|
|
|
|
|
isIOS
|
|
|
|
|
? {
|
|
|
|
|
WebkitUserSelect: "none",
|
|
|
|
|
WebkitTouchCallout: "none",
|
|
|
|
|
}
|
|
|
|
|
: undefined
|
|
|
|
|
}
|
|
|
|
|
draggable={false}
|
|
|
|
|
src={`${apiHost}api/events/${search.id}/thumbnail.webp`}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (isDesktop) {
|
|
|
|
|
return (
|
2025-11-08 22:26:30 +03:00
|
|
|
<div className="grid h-full w-full grid-cols-[60%_40%] gap-4">
|
|
|
|
|
<div className="scrollbar-container min-w-0 overflow-y-auto overflow-x-hidden">
|
2025-11-06 19:22:52 +03:00
|
|
|
{snapshotElement}
|
|
|
|
|
</div>
|
2025-11-08 22:26:30 +03:00
|
|
|
<div className="flex min-w-0 flex-col gap-4 pr-2">
|
2025-11-06 19:22:52 +03:00
|
|
|
<TabsWithActions
|
|
|
|
|
search={search}
|
|
|
|
|
searchTabs={searchTabs}
|
|
|
|
|
pageToggle={pageToggle}
|
|
|
|
|
setPageToggle={setPageToggle}
|
|
|
|
|
config={config}
|
|
|
|
|
setSearch={setSearch}
|
|
|
|
|
setSimilarity={setSimilarity}
|
|
|
|
|
isPopoverOpen={isPopoverOpen}
|
|
|
|
|
setIsPopoverOpen={setIsPopoverOpen}
|
|
|
|
|
dialogContainer={dialogContainer}
|
|
|
|
|
/>
|
2025-11-08 22:26:30 +03:00
|
|
|
<div className="scrollbar-container min-w-0 flex-1 overflow-y-auto overflow-x-hidden px-4">
|
2025-11-06 19:22:52 +03:00
|
|
|
<ObjectDetailsTab
|
|
|
|
|
search={search}
|
|
|
|
|
config={config}
|
|
|
|
|
setSearch={setSearch}
|
|
|
|
|
setInputFocused={setInputFocused}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// mobile
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{snapshotElement}
|
|
|
|
|
<ObjectDetailsTab
|
|
|
|
|
search={search}
|
|
|
|
|
config={config}
|
|
|
|
|
setSearch={setSearch}
|
|
|
|
|
setInputFocused={setInputFocused}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-23 23:58:00 +03:00
|
|
|
type SearchDetailDialogProps = {
|
|
|
|
|
search?: SearchResult;
|
2024-10-15 16:24:47 +03:00
|
|
|
page: SearchTab;
|
2024-06-23 23:58:00 +03:00
|
|
|
setSearch: (search: SearchResult | undefined) => void;
|
2024-10-15 16:24:47 +03:00
|
|
|
setSearchPage: (page: SearchTab) => void;
|
2024-06-23 23:58:00 +03:00
|
|
|
setSimilarity?: () => void;
|
2025-01-20 16:23:22 +03:00
|
|
|
setInputFocused: React.Dispatch<React.SetStateAction<boolean>>;
|
2025-11-06 19:22:52 +03:00
|
|
|
onPrevious?: () => void;
|
|
|
|
|
onNext?: () => void;
|
2024-06-23 23:58:00 +03:00
|
|
|
};
|
2025-11-06 19:22:52 +03:00
|
|
|
|
2024-06-23 23:58:00 +03:00
|
|
|
export default function SearchDetailDialog({
|
|
|
|
|
search,
|
2024-10-15 16:24:47 +03:00
|
|
|
page,
|
2024-06-23 23:58:00 +03:00
|
|
|
setSearch,
|
2024-10-15 16:24:47 +03:00
|
|
|
setSearchPage,
|
2024-06-23 23:58:00 +03:00
|
|
|
setSimilarity,
|
2025-01-20 16:23:22 +03:00
|
|
|
setInputFocused,
|
2025-11-06 19:22:52 +03:00
|
|
|
onPrevious,
|
|
|
|
|
onNext,
|
2024-06-23 23:58:00 +03:00
|
|
|
}: SearchDetailDialogProps) {
|
2025-03-18 00:57:46 +03:00
|
|
|
const { t } = useTranslation(["views/explore", "views/faceLibrary"]);
|
2024-06-23 23:58:00 +03:00
|
|
|
const { data: config } = useSWR<FrigateConfig>("config", {
|
|
|
|
|
revalidateOnFocus: false,
|
|
|
|
|
});
|
2025-11-01 17:19:30 +03:00
|
|
|
const apiHost = useApiHost();
|
2024-06-23 23:58:00 +03:00
|
|
|
|
2024-09-11 17:41:16 +03:00
|
|
|
// tabs
|
|
|
|
|
|
2024-10-15 16:24:47 +03:00
|
|
|
const [pageToggle, setPageToggle] = useOptimisticState(
|
|
|
|
|
page,
|
|
|
|
|
setSearchPage,
|
|
|
|
|
100,
|
|
|
|
|
);
|
2024-09-11 17:41:16 +03:00
|
|
|
|
2024-09-12 22:39:35 +03:00
|
|
|
// dialog and mobile page
|
|
|
|
|
|
|
|
|
|
const [isOpen, setIsOpen] = useState(search != undefined);
|
2025-11-06 19:22:52 +03:00
|
|
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
|
|
|
const dialogContentRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
const [dialogContainer, setDialogContainer] = useState<HTMLDivElement | null>(
|
|
|
|
|
null,
|
|
|
|
|
);
|
2024-09-12 22:39:35 +03:00
|
|
|
|
2024-10-25 15:24:04 +03:00
|
|
|
const handleOpenChange = useCallback(
|
|
|
|
|
(open: boolean) => {
|
|
|
|
|
setIsOpen(open);
|
|
|
|
|
if (!open) {
|
2025-11-06 19:22:52 +03:00
|
|
|
setIsPopoverOpen(false);
|
2024-10-25 15:24:04 +03:00
|
|
|
// short timeout to allow the mobile page animation
|
|
|
|
|
// to complete before updating the state
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
setSearch(undefined);
|
|
|
|
|
}, 300);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[setSearch],
|
|
|
|
|
);
|
|
|
|
|
|
2025-11-06 19:22:52 +03:00
|
|
|
useLayoutEffect(() => {
|
|
|
|
|
setDialogContainer(dialogContentRef.current);
|
|
|
|
|
}, [isOpen, search?.id]);
|
|
|
|
|
|
2024-09-12 22:39:35 +03:00
|
|
|
useEffect(() => {
|
2024-10-16 15:15:25 +03:00
|
|
|
if (search) {
|
|
|
|
|
setIsOpen(search != undefined);
|
|
|
|
|
}
|
2024-09-12 22:39:35 +03:00
|
|
|
}, [search]);
|
|
|
|
|
|
2025-11-06 19:22:52 +03:00
|
|
|
// show/hide annotation settings is handled inside TabsWithActions
|
|
|
|
|
|
2024-09-11 17:41:16 +03:00
|
|
|
const searchTabs = useMemo(() => {
|
|
|
|
|
if (!config || !search) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const views = [...SEARCH_TABS];
|
|
|
|
|
|
2024-10-30 14:54:06 +03:00
|
|
|
if (search.data.type != "object" || !search.has_clip) {
|
2025-10-26 21:12:20 +03:00
|
|
|
const index = views.indexOf("tracking_details");
|
2024-09-26 23:30:56 +03:00
|
|
|
views.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-11 17:41:16 +03:00
|
|
|
return views;
|
|
|
|
|
}, [config, search]);
|
|
|
|
|
|
2024-09-12 17:46:29 +03:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (searchTabs.length == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!searchTabs.includes(pageToggle)) {
|
2025-11-01 17:19:30 +03:00
|
|
|
setSearchPage("snapshot");
|
2024-09-12 17:46:29 +03:00
|
|
|
}
|
2024-10-15 16:24:47 +03:00
|
|
|
}, [pageToggle, searchTabs, setSearchPage]);
|
2024-09-12 17:46:29 +03:00
|
|
|
|
2024-09-11 17:41:16 +03:00
|
|
|
if (!search) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// content
|
|
|
|
|
|
2024-09-12 22:39:35 +03:00
|
|
|
const Overlay = isDesktop ? Dialog : MobilePage;
|
|
|
|
|
const Content = isDesktop ? DialogContent : MobilePageContent;
|
|
|
|
|
const Header = isDesktop ? DialogHeader : MobilePageHeader;
|
|
|
|
|
const Title = isDesktop ? DialogTitle : MobilePageTitle;
|
|
|
|
|
const Description = isDesktop ? DialogDescription : MobilePageDescription;
|
2024-09-11 17:41:16 +03:00
|
|
|
|
|
|
|
|
return (
|
2025-11-01 17:19:30 +03:00
|
|
|
<DetailStreamProvider
|
|
|
|
|
isDetailMode={true}
|
|
|
|
|
currentTime={(search as unknown as Event)?.start_time ?? 0}
|
|
|
|
|
camera={(search as unknown as Event)?.camera ?? ""}
|
|
|
|
|
initialSelectedObjectIds={[(search as unknown as Event).id as string]}
|
2025-04-28 17:41:08 +03:00
|
|
|
>
|
2025-11-01 17:19:30 +03:00
|
|
|
<Overlay
|
|
|
|
|
open={isOpen}
|
|
|
|
|
onOpenChange={handleOpenChange}
|
|
|
|
|
enableHistoryBack={true}
|
2024-09-11 17:41:16 +03:00
|
|
|
>
|
2025-11-06 19:22:52 +03:00
|
|
|
{isDesktop && onPrevious && onNext && (
|
|
|
|
|
<DialogPortal>
|
|
|
|
|
<div className="pointer-events-none fixed inset-0 z-[200] flex items-center justify-center">
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"relative flex items-center justify-between",
|
|
|
|
|
"w-full",
|
|
|
|
|
// match dialog's max-width classes
|
|
|
|
|
"sm:max-w-xl md:max-w-4xl lg:max-w-[70%]",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onPrevious?.();
|
|
|
|
|
}}
|
|
|
|
|
className="nav-button pointer-events-auto absolute -left-16 rounded-lg border bg-secondary/60 p-2 text-primary-variant shadow-lg backdrop-blur-sm hover:bg-secondary/80 hover:text-primary"
|
|
|
|
|
aria-label={t("searchResult.previousTrackedObject")}
|
|
|
|
|
>
|
|
|
|
|
<FaChevronLeft className="size-4" />
|
|
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
{t("searchResult.previousTrackedObject")}
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onNext?.();
|
|
|
|
|
}}
|
|
|
|
|
className="nav-button pointer-events-auto absolute -right-16 rounded-lg border bg-secondary/60 p-2 text-primary-variant shadow-lg backdrop-blur-sm hover:bg-secondary/80 hover:text-primary"
|
|
|
|
|
aria-label={t("searchResult.nextTrackedObject")}
|
|
|
|
|
>
|
|
|
|
|
<FaChevronRight className="size-4" />
|
|
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
{t("searchResult.nextTrackedObject")}
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</DialogPortal>
|
|
|
|
|
)}
|
2025-11-01 17:19:30 +03:00
|
|
|
<Content
|
2025-11-06 19:22:52 +03:00
|
|
|
ref={isDesktop ? dialogContentRef : undefined}
|
2025-11-01 17:19:30 +03:00
|
|
|
className={cn(
|
|
|
|
|
"scrollbar-container overflow-y-auto",
|
|
|
|
|
isDesktop &&
|
2025-11-06 19:22:52 +03:00
|
|
|
"max-h-[95dvh] sm:max-w-xl md:max-w-4xl lg:max-w-[70%]",
|
2025-11-08 15:44:30 +03:00
|
|
|
isMobile && "flex h-full flex-col px-4",
|
2025-11-01 17:19:30 +03:00
|
|
|
)}
|
2025-11-08 15:44:30 +03:00
|
|
|
onEscapeKeyDown={(event) => {
|
|
|
|
|
if (isPopoverOpen) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
}}
|
2025-11-06 19:22:52 +03:00
|
|
|
onInteractOutside={(e) => {
|
|
|
|
|
if (isPopoverOpen) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
const target = e.target as HTMLElement;
|
|
|
|
|
if (target.closest(".nav-button")) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
}}
|
2024-09-11 17:41:16 +03:00
|
|
|
>
|
2025-11-08 15:44:30 +03:00
|
|
|
<Header className={cn(!isDesktop && "top-0 z-[60] mb-0")}>
|
2025-11-01 17:19:30 +03:00
|
|
|
<Title>{t("trackedObjectDetails")}</Title>
|
|
|
|
|
<Description className="sr-only">
|
|
|
|
|
{t("trackedObjectDetails")}
|
2025-11-06 19:22:52 +03:00
|
|
|
<span className="sr-only" tabIndex={0} />
|
2025-11-01 17:19:30 +03:00
|
|
|
</Description>
|
|
|
|
|
</Header>
|
2025-11-06 19:22:52 +03:00
|
|
|
|
|
|
|
|
{!isDesktop && (
|
|
|
|
|
<div className="flex w-full flex-col justify-center gap-4">
|
|
|
|
|
<TabsWithActions
|
|
|
|
|
search={search}
|
|
|
|
|
searchTabs={searchTabs}
|
|
|
|
|
pageToggle={pageToggle}
|
|
|
|
|
setPageToggle={setPageToggle}
|
|
|
|
|
config={config}
|
|
|
|
|
setSearch={setSearch}
|
|
|
|
|
setSimilarity={setSimilarity}
|
|
|
|
|
isPopoverOpen={isPopoverOpen}
|
|
|
|
|
setIsPopoverOpen={setIsPopoverOpen}
|
|
|
|
|
dialogContainer={dialogContainer}
|
2025-11-01 17:19:30 +03:00
|
|
|
/>
|
2025-11-06 19:22:52 +03:00
|
|
|
</div>
|
2025-11-01 17:19:30 +03:00
|
|
|
)}
|
2025-11-06 19:22:52 +03:00
|
|
|
|
|
|
|
|
<DialogContentComponent
|
|
|
|
|
page={page}
|
|
|
|
|
search={search}
|
|
|
|
|
isDesktop={isDesktop}
|
|
|
|
|
apiHost={apiHost}
|
|
|
|
|
config={config}
|
|
|
|
|
searchTabs={searchTabs}
|
|
|
|
|
pageToggle={pageToggle}
|
|
|
|
|
setPageToggle={setPageToggle}
|
|
|
|
|
setSearch={setSearch}
|
|
|
|
|
setInputFocused={setInputFocused}
|
|
|
|
|
setSimilarity={setSimilarity}
|
|
|
|
|
isPopoverOpen={isPopoverOpen}
|
|
|
|
|
setIsPopoverOpen={setIsPopoverOpen}
|
|
|
|
|
dialogContainer={dialogContainer}
|
|
|
|
|
/>
|
2025-11-01 17:19:30 +03:00
|
|
|
</Content>
|
|
|
|
|
</Overlay>
|
|
|
|
|
</DetailStreamProvider>
|
2024-09-11 17:41:16 +03:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ObjectDetailsTabProps = {
|
|
|
|
|
search: SearchResult;
|
|
|
|
|
config?: FrigateConfig;
|
|
|
|
|
setSearch: (search: SearchResult | undefined) => void;
|
2025-01-20 16:23:22 +03:00
|
|
|
setInputFocused: React.Dispatch<React.SetStateAction<boolean>>;
|
2024-09-11 17:41:16 +03:00
|
|
|
};
|
|
|
|
|
function ObjectDetailsTab({
|
|
|
|
|
search,
|
|
|
|
|
config,
|
|
|
|
|
setSearch,
|
2025-01-20 16:23:22 +03:00
|
|
|
setInputFocused,
|
2024-09-11 17:41:16 +03:00
|
|
|
}: ObjectDetailsTabProps) {
|
2025-11-06 19:22:52 +03:00
|
|
|
const { t, i18n } = useTranslation([
|
|
|
|
|
"views/explore",
|
|
|
|
|
"views/faceLibrary",
|
|
|
|
|
"components/dialog",
|
|
|
|
|
]);
|
2025-03-16 18:36:20 +03:00
|
|
|
|
2024-06-23 23:58:00 +03:00
|
|
|
const apiHost = useApiHost();
|
|
|
|
|
|
2024-09-24 17:14:51 +03:00
|
|
|
// mutation / revalidation
|
|
|
|
|
|
|
|
|
|
const mutate = useGlobalMutation();
|
|
|
|
|
|
2025-11-17 17:12:05 +03:00
|
|
|
// Helper to map over SWR cached search results while preserving
|
|
|
|
|
// either paginated format (SearchResult[][]) or flat format (SearchResult[])
|
|
|
|
|
const mapSearchResults = useCallback(
|
|
|
|
|
(
|
|
|
|
|
currentData: SearchResult[][] | SearchResult[] | undefined,
|
|
|
|
|
fn: (event: SearchResult) => SearchResult,
|
|
|
|
|
) => {
|
|
|
|
|
if (!currentData) return currentData;
|
|
|
|
|
if (Array.isArray(currentData[0])) {
|
|
|
|
|
return (currentData as SearchResult[][]).map((page) => page.map(fn));
|
|
|
|
|
}
|
|
|
|
|
return (currentData as SearchResult[]).map(fn);
|
|
|
|
|
},
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
2025-04-10 17:27:01 +03:00
|
|
|
// users
|
|
|
|
|
|
|
|
|
|
const isAdmin = useIsAdmin();
|
|
|
|
|
|
2024-06-23 23:58:00 +03:00
|
|
|
// data
|
|
|
|
|
|
2024-09-13 23:44:31 +03:00
|
|
|
const [desc, setDesc] = useState(search?.data.description);
|
2025-02-24 02:56:48 +03:00
|
|
|
const [isSubLabelDialogOpen, setIsSubLabelDialogOpen] = useState(false);
|
2025-04-10 17:27:01 +03:00
|
|
|
const [isLPRDialogOpen, setIsLPRDialogOpen] = useState(false);
|
2025-11-08 22:26:30 +03:00
|
|
|
const [isEditingDesc, setIsEditingDesc] = useState(false);
|
|
|
|
|
const originalDescRef = useRef<string | null>(null);
|
2024-06-23 23:58:00 +03:00
|
|
|
|
2025-01-20 16:23:22 +03:00
|
|
|
const handleDescriptionFocus = useCallback(() => {
|
|
|
|
|
setInputFocused(true);
|
|
|
|
|
}, [setInputFocused]);
|
|
|
|
|
|
|
|
|
|
const handleDescriptionBlur = useCallback(() => {
|
|
|
|
|
setInputFocused(false);
|
|
|
|
|
}, [setInputFocused]);
|
|
|
|
|
|
2024-06-23 23:58:00 +03:00
|
|
|
// we have to make sure the current selected search item stays in sync
|
2024-09-14 16:42:56 +03:00
|
|
|
useEffect(() => setDesc(search?.data.description ?? ""), [search]);
|
2024-06-23 23:58:00 +03:00
|
|
|
|
|
|
|
|
const formattedDate = useFormattedTimestamp(
|
|
|
|
|
search?.start_time ?? 0,
|
|
|
|
|
config?.ui.time_format == "24hour"
|
2025-04-23 00:50:21 +03:00
|
|
|
? t("time.formattedTimestampMonthDayYearHourMinute.24hour", {
|
|
|
|
|
ns: "common",
|
|
|
|
|
})
|
|
|
|
|
: t("time.formattedTimestampMonthDayYearHourMinute.12hour", {
|
|
|
|
|
ns: "common",
|
|
|
|
|
}),
|
2024-09-12 22:28:15 +03:00
|
|
|
config?.ui.timezone,
|
2024-06-23 23:58:00 +03:00
|
|
|
);
|
|
|
|
|
|
2025-04-15 17:46:33 +03:00
|
|
|
const topScore = useMemo(() => {
|
2024-09-10 21:38:58 +03:00
|
|
|
if (!search) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-23 18:31:20 +03:00
|
|
|
const value = search.data.top_score ?? search.top_score ?? 0;
|
2024-09-10 21:38:58 +03:00
|
|
|
|
|
|
|
|
return Math.round(value * 100);
|
|
|
|
|
}, [search]);
|
|
|
|
|
|
|
|
|
|
const subLabelScore = useMemo(() => {
|
|
|
|
|
if (!search) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-18 21:26:44 +03:00
|
|
|
if (search.sub_label && search.data?.sub_label_score) {
|
2024-10-23 01:07:42 +03:00
|
|
|
return Math.round((search.data?.sub_label_score ?? 0) * 100);
|
2024-09-10 21:38:58 +03:00
|
|
|
} else {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
}, [search]);
|
|
|
|
|
|
2025-03-13 02:45:16 +03:00
|
|
|
const recognizedLicensePlateScore = useMemo(() => {
|
2025-03-12 23:38:28 +03:00
|
|
|
if (!search) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 02:45:16 +03:00
|
|
|
if (
|
|
|
|
|
search.data.recognized_license_plate &&
|
|
|
|
|
search.data?.recognized_license_plate_score
|
|
|
|
|
) {
|
|
|
|
|
return Math.round(
|
|
|
|
|
(search.data?.recognized_license_plate_score ?? 0) * 100,
|
|
|
|
|
);
|
2025-03-12 23:38:28 +03:00
|
|
|
} else {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
}, [search]);
|
|
|
|
|
|
2025-04-15 17:46:33 +03:00
|
|
|
const snapScore = useMemo(() => {
|
|
|
|
|
if (!search?.has_snapshot) {
|
2025-04-17 16:34:24 +03:00
|
|
|
return undefined;
|
2025-04-15 17:46:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const value = search.data.score ?? search.score ?? 0;
|
|
|
|
|
|
|
|
|
|
return Math.floor(value * 100);
|
|
|
|
|
}, [search]);
|
|
|
|
|
|
2025-02-10 23:23:42 +03:00
|
|
|
const averageEstimatedSpeed = useMemo(() => {
|
|
|
|
|
if (!search || !search.data?.average_estimated_speed) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (search.data?.average_estimated_speed != 0) {
|
|
|
|
|
return search.data?.average_estimated_speed.toFixed(1);
|
|
|
|
|
} else {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
}, [search]);
|
|
|
|
|
|
|
|
|
|
const velocityAngle = useMemo(() => {
|
|
|
|
|
if (!search || !search.data?.velocity_angle) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (search.data?.velocity_angle != 0) {
|
|
|
|
|
return search.data?.velocity_angle.toFixed(1);
|
|
|
|
|
} else {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
}, [search]);
|
|
|
|
|
|
2025-11-21 02:50:17 +03:00
|
|
|
const isEventsKey = useCallback((key: unknown): boolean => {
|
|
|
|
|
const candidate = Array.isArray(key) ? key[0] : key;
|
|
|
|
|
const EVENTS_KEY_PATTERNS = ["events", "events/search", "events/explore"];
|
|
|
|
|
return (
|
|
|
|
|
typeof candidate === "string" &&
|
|
|
|
|
EVENTS_KEY_PATTERNS.some((p) => candidate.includes(p))
|
|
|
|
|
);
|
|
|
|
|
}, []);
|
|
|
|
|
|
2024-06-23 23:58:00 +03:00
|
|
|
const updateDescription = useCallback(() => {
|
|
|
|
|
if (!search) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
axios
|
|
|
|
|
.post(`events/${search.id}/description`, { description: desc })
|
|
|
|
|
.then((resp) => {
|
|
|
|
|
if (resp.status == 200) {
|
2025-03-16 18:36:20 +03:00
|
|
|
toast.success(t("details.tips.descriptionSaved"), {
|
2024-06-23 23:58:00 +03:00
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-09-24 17:14:51 +03:00
|
|
|
mutate(
|
2025-11-21 02:50:17 +03:00
|
|
|
(key) => isEventsKey(key),
|
2025-11-17 17:12:05 +03:00
|
|
|
(currentData: SearchResult[][] | SearchResult[] | undefined) =>
|
|
|
|
|
mapSearchResults(currentData, (event) =>
|
|
|
|
|
event.id === search.id
|
|
|
|
|
? { ...event, data: { ...event.data, description: desc } }
|
|
|
|
|
: event,
|
|
|
|
|
),
|
2024-10-22 00:14:57 +03:00
|
|
|
{
|
|
|
|
|
optimisticData: true,
|
|
|
|
|
rollbackOnError: true,
|
|
|
|
|
revalidate: false,
|
|
|
|
|
},
|
2024-09-24 17:14:51 +03:00
|
|
|
);
|
2025-11-21 02:50:17 +03:00
|
|
|
setSearch({ ...search, data: { ...search.data, description: desc } });
|
2024-06-23 23:58:00 +03:00
|
|
|
})
|
2025-03-08 19:01:08 +03:00
|
|
|
.catch((error) => {
|
|
|
|
|
const errorMessage =
|
|
|
|
|
error.response?.data?.message ||
|
|
|
|
|
error.response?.data?.detail ||
|
|
|
|
|
"Unknown error";
|
2025-03-16 18:36:20 +03:00
|
|
|
toast.error(
|
|
|
|
|
t("details.tips.saveDescriptionFailed", {
|
|
|
|
|
errorMessage,
|
|
|
|
|
}),
|
|
|
|
|
{
|
|
|
|
|
position: "top-center",
|
|
|
|
|
},
|
|
|
|
|
);
|
2024-09-13 23:44:31 +03:00
|
|
|
setDesc(search.data.description);
|
2024-06-23 23:58:00 +03:00
|
|
|
});
|
2025-11-21 02:50:17 +03:00
|
|
|
}, [desc, search, mutate, t, mapSearchResults, isEventsKey, setSearch]);
|
2024-09-24 17:14:51 +03:00
|
|
|
|
2024-10-01 00:54:53 +03:00
|
|
|
const regenerateDescription = useCallback(
|
|
|
|
|
(source: "snapshot" | "thumbnails") => {
|
|
|
|
|
if (!search) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
axios
|
|
|
|
|
.put(`events/${search.id}/description/regenerate?source=${source}`)
|
|
|
|
|
.then((resp) => {
|
|
|
|
|
if (resp.status == 200) {
|
|
|
|
|
toast.success(
|
2025-03-16 18:36:20 +03:00
|
|
|
t("details.item.toast.success.regenerate", {
|
|
|
|
|
provider: capitalizeAll(
|
|
|
|
|
config?.genai.provider.replaceAll("_", " ") ??
|
|
|
|
|
t("generativeAI"),
|
|
|
|
|
),
|
|
|
|
|
}),
|
2024-10-01 00:54:53 +03:00
|
|
|
{
|
|
|
|
|
position: "top-center",
|
|
|
|
|
duration: 7000,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-10-23 15:14:50 +03:00
|
|
|
.catch((error) => {
|
2025-03-08 19:01:08 +03:00
|
|
|
const errorMessage =
|
|
|
|
|
error.response?.data?.message ||
|
|
|
|
|
error.response?.data?.detail ||
|
|
|
|
|
"Unknown error";
|
2024-10-01 00:54:53 +03:00
|
|
|
toast.error(
|
2025-03-16 18:36:20 +03:00
|
|
|
t("details.item.toast.error.regenerate", {
|
|
|
|
|
provider: capitalizeAll(
|
|
|
|
|
config?.genai.provider.replaceAll("_", " ") ??
|
|
|
|
|
t("generativeAI"),
|
|
|
|
|
),
|
|
|
|
|
errorMessage,
|
|
|
|
|
}),
|
2025-03-08 19:01:08 +03:00
|
|
|
{ position: "top-center" },
|
2024-09-24 17:14:51 +03:00
|
|
|
);
|
2024-10-01 00:54:53 +03:00
|
|
|
});
|
|
|
|
|
},
|
2025-03-16 18:36:20 +03:00
|
|
|
[search, config, t],
|
2024-10-01 00:54:53 +03:00
|
|
|
);
|
2024-06-23 23:58:00 +03:00
|
|
|
|
2025-02-24 02:56:48 +03:00
|
|
|
const handleSubLabelSave = useCallback(
|
|
|
|
|
(text: string) => {
|
|
|
|
|
if (!search) return;
|
|
|
|
|
|
|
|
|
|
// set score to 1.0 if we're manually entering a sub label
|
|
|
|
|
const subLabelScore =
|
|
|
|
|
text === "" ? undefined : search.data?.sub_label_score || 1.0;
|
|
|
|
|
|
|
|
|
|
axios
|
|
|
|
|
.post(`${apiHost}api/events/${search.id}/sub_label`, {
|
|
|
|
|
camera: search.camera,
|
|
|
|
|
subLabel: text,
|
|
|
|
|
subLabelScore: subLabelScore,
|
|
|
|
|
})
|
|
|
|
|
.then((response) => {
|
|
|
|
|
if (response.status === 200) {
|
2025-03-16 18:36:20 +03:00
|
|
|
toast.success(t("details.item.toast.success.updatedSublabel"), {
|
2025-02-24 02:56:48 +03:00
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mutate(
|
2025-11-21 02:50:17 +03:00
|
|
|
(key) => isEventsKey(key),
|
2025-11-17 17:12:05 +03:00
|
|
|
(currentData: SearchResult[][] | SearchResult[] | undefined) =>
|
|
|
|
|
mapSearchResults(currentData, (event) =>
|
2025-02-24 02:56:48 +03:00
|
|
|
event.id === search.id
|
|
|
|
|
? {
|
|
|
|
|
...event,
|
|
|
|
|
sub_label: text,
|
|
|
|
|
data: {
|
|
|
|
|
...event.data,
|
|
|
|
|
sub_label_score: subLabelScore,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: event,
|
2025-11-17 17:12:05 +03:00
|
|
|
),
|
2025-02-24 02:56:48 +03:00
|
|
|
{
|
|
|
|
|
optimisticData: true,
|
|
|
|
|
rollbackOnError: true,
|
|
|
|
|
revalidate: false,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
setSearch({
|
|
|
|
|
...search,
|
|
|
|
|
sub_label: text,
|
|
|
|
|
data: {
|
|
|
|
|
...search.data,
|
|
|
|
|
sub_label_score: subLabelScore,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
setIsSubLabelDialogOpen(false);
|
|
|
|
|
}
|
|
|
|
|
})
|
2025-03-08 19:01:08 +03:00
|
|
|
.catch((error) => {
|
|
|
|
|
const errorMessage =
|
|
|
|
|
error.response?.data?.message ||
|
|
|
|
|
error.response?.data?.detail ||
|
|
|
|
|
"Unknown error";
|
2025-03-16 18:36:20 +03:00
|
|
|
toast.error(
|
|
|
|
|
t("details.item.toast.error.updatedSublabelFailed", {
|
|
|
|
|
errorMessage,
|
|
|
|
|
}),
|
|
|
|
|
{
|
|
|
|
|
position: "top-center",
|
|
|
|
|
},
|
|
|
|
|
);
|
2025-02-24 02:56:48 +03:00
|
|
|
});
|
|
|
|
|
},
|
2025-11-21 02:50:17 +03:00
|
|
|
[search, apiHost, mutate, setSearch, t, mapSearchResults, isEventsKey],
|
2025-02-24 02:56:48 +03:00
|
|
|
);
|
|
|
|
|
|
2025-04-10 17:27:01 +03:00
|
|
|
// recognized plate
|
|
|
|
|
|
|
|
|
|
const handleLPRSave = useCallback(
|
|
|
|
|
(text: string) => {
|
|
|
|
|
if (!search) return;
|
|
|
|
|
|
|
|
|
|
// set score to 1.0 if we're manually entering a new plate
|
|
|
|
|
const plateScore = text === "" ? undefined : 1.0;
|
|
|
|
|
|
|
|
|
|
axios
|
|
|
|
|
.post(`${apiHost}api/events/${search.id}/recognized_license_plate`, {
|
|
|
|
|
recognizedLicensePlate: text,
|
|
|
|
|
recognizedLicensePlateScore: plateScore,
|
|
|
|
|
})
|
|
|
|
|
.then((response) => {
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
toast.success(t("details.item.toast.success.updatedLPR"), {
|
|
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mutate(
|
2025-11-21 02:50:17 +03:00
|
|
|
(key) => isEventsKey(key),
|
2025-11-17 17:12:05 +03:00
|
|
|
(currentData: SearchResult[][] | SearchResult[] | undefined) =>
|
|
|
|
|
mapSearchResults(currentData, (event) =>
|
2025-04-10 17:27:01 +03:00
|
|
|
event.id === search.id
|
|
|
|
|
? {
|
|
|
|
|
...event,
|
|
|
|
|
data: {
|
|
|
|
|
...event.data,
|
|
|
|
|
recognized_license_plate: text,
|
|
|
|
|
recognized_license_plate_score: plateScore,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: event,
|
2025-11-17 17:12:05 +03:00
|
|
|
),
|
2025-04-10 17:27:01 +03:00
|
|
|
{
|
|
|
|
|
optimisticData: true,
|
|
|
|
|
rollbackOnError: true,
|
|
|
|
|
revalidate: false,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
setSearch({
|
|
|
|
|
...search,
|
|
|
|
|
data: {
|
|
|
|
|
...search.data,
|
|
|
|
|
recognized_license_plate: text,
|
|
|
|
|
recognized_license_plate_score: plateScore,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
setIsLPRDialogOpen(false);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
const errorMessage =
|
|
|
|
|
error.response?.data?.message ||
|
|
|
|
|
error.response?.data?.detail ||
|
|
|
|
|
"Unknown error";
|
|
|
|
|
toast.error(
|
|
|
|
|
t("details.item.toast.error.updatedLPRFailed", {
|
|
|
|
|
errorMessage,
|
|
|
|
|
}),
|
|
|
|
|
{
|
|
|
|
|
position: "top-center",
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
2025-11-21 02:50:17 +03:00
|
|
|
[search, apiHost, mutate, setSearch, t, mapSearchResults, isEventsKey],
|
2025-04-10 17:27:01 +03:00
|
|
|
);
|
|
|
|
|
|
2025-05-27 18:26:00 +03:00
|
|
|
// speech transcription
|
|
|
|
|
|
|
|
|
|
const onTranscribe = useCallback(() => {
|
|
|
|
|
axios
|
|
|
|
|
.put(`/audio/transcribe`, { event_id: search.id })
|
|
|
|
|
.then((resp) => {
|
|
|
|
|
if (resp.status == 202) {
|
|
|
|
|
toast.success(t("details.item.toast.success.audioTranscription"), {
|
|
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
const errorMessage =
|
|
|
|
|
error.response?.data?.message ||
|
|
|
|
|
error.response?.data?.detail ||
|
|
|
|
|
"Unknown error";
|
|
|
|
|
toast.error(
|
|
|
|
|
t("details.item.toast.error.audioTranscription", {
|
|
|
|
|
errorMessage,
|
|
|
|
|
}),
|
|
|
|
|
{
|
|
|
|
|
position: "top-center",
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}, [search, t]);
|
|
|
|
|
|
2025-11-24 16:34:56 +03:00
|
|
|
// audio transcription processing state
|
|
|
|
|
|
|
|
|
|
const { payload: audioTranscriptionProcessState } =
|
|
|
|
|
useAudioTranscriptionProcessState();
|
|
|
|
|
|
2025-11-06 19:22:52 +03:00
|
|
|
// frigate+ submission
|
|
|
|
|
|
|
|
|
|
type SubmissionState = "reviewing" | "uploading" | "submitted";
|
|
|
|
|
const [state, setState] = useState<SubmissionState>(
|
|
|
|
|
search?.plus_id ? "submitted" : "reviewing",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
useEffect(
|
|
|
|
|
() => setState(search?.plus_id ? "submitted" : "reviewing"),
|
|
|
|
|
[search],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const onSubmitToPlus = useCallback(
|
|
|
|
|
async (falsePositive: boolean) => {
|
|
|
|
|
if (!search) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
falsePositive
|
|
|
|
|
? axios.put(`events/${search.id}/false_positive`)
|
|
|
|
|
: axios.post(`events/${search.id}/plus`, {
|
|
|
|
|
include_annotation: 1,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
setState("submitted");
|
2025-11-21 02:50:17 +03:00
|
|
|
setSearch({ ...search, plus_id: "new_upload" });
|
2025-11-08 15:44:30 +03:00
|
|
|
mutate(
|
2025-11-21 02:50:17 +03:00
|
|
|
(key) => isEventsKey(key),
|
2025-11-17 17:12:05 +03:00
|
|
|
(currentData: SearchResult[][] | SearchResult[] | undefined) =>
|
|
|
|
|
mapSearchResults(currentData, (event) =>
|
|
|
|
|
event.id === search.id
|
|
|
|
|
? { ...event, plus_id: "new_upload" }
|
|
|
|
|
: event,
|
|
|
|
|
),
|
2025-11-08 15:44:30 +03:00
|
|
|
{
|
|
|
|
|
optimisticData: true,
|
|
|
|
|
rollbackOnError: true,
|
|
|
|
|
revalidate: false,
|
|
|
|
|
},
|
|
|
|
|
);
|
2025-11-06 19:22:52 +03:00
|
|
|
},
|
2025-11-21 02:50:17 +03:00
|
|
|
[search, mutate, mapSearchResults, setSearch, isEventsKey],
|
2025-11-06 19:22:52 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const popoverContainerRef = useRef<HTMLDivElement | null>(null);
|
2025-11-08 22:26:30 +03:00
|
|
|
const canRegenerate = !!(
|
|
|
|
|
config?.cameras[search.camera].objects.genai.enabled && search.end_time
|
|
|
|
|
);
|
|
|
|
|
const showGenAIPlaceholder = !!(
|
|
|
|
|
config?.cameras[search.camera].objects.genai.enabled &&
|
|
|
|
|
!search.end_time &&
|
|
|
|
|
(config.cameras[search.camera].objects.genai.required_zones.length === 0 ||
|
|
|
|
|
search.zones.some((zone) =>
|
|
|
|
|
config.cameras[search.camera].objects.genai.required_zones.includes(
|
|
|
|
|
zone,
|
|
|
|
|
),
|
|
|
|
|
)) &&
|
|
|
|
|
(config.cameras[search.camera].objects.genai.objects.length === 0 ||
|
|
|
|
|
config.cameras[search.camera].objects.genai.objects.includes(
|
|
|
|
|
search.label,
|
|
|
|
|
))
|
|
|
|
|
);
|
2024-06-23 23:58:00 +03:00
|
|
|
return (
|
2025-11-06 19:22:52 +03:00
|
|
|
<div ref={popoverContainerRef} className="flex flex-col gap-5">
|
2024-09-11 17:41:16 +03:00
|
|
|
<div className="flex w-full flex-row">
|
|
|
|
|
<div className="flex w-full flex-col gap-3">
|
2025-11-06 19:22:52 +03:00
|
|
|
<div className="w-full">
|
|
|
|
|
<div className="flex w-full flex-row flex-wrap gap-6">
|
|
|
|
|
<div className="min-w-0 flex-1">
|
|
|
|
|
<div className="flex flex-col gap-3">
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<div className="text-sm text-primary/40">
|
|
|
|
|
{t("details.label")}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-row items-center gap-2 text-sm smart-capitalize">
|
|
|
|
|
{getIconForLabel(search.label, "size-4 text-primary")}
|
2025-11-12 02:23:30 +03:00
|
|
|
{getTranslatedLabel(search.label, search.data.type)}
|
2025-11-06 19:22:52 +03:00
|
|
|
{search.sub_label && ` (${search.sub_label})`}
|
|
|
|
|
{isAdmin && search.end_time && (
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<span>
|
|
|
|
|
<FaPencilAlt
|
|
|
|
|
className="size-4 cursor-pointer text-primary/40 hover:text-primary/80"
|
|
|
|
|
onClick={() => setIsSubLabelDialogOpen(true)}
|
|
|
|
|
/>
|
|
|
|
|
</span>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipPortal>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
{t("details.editSubLabel.title")}
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</TooltipPortal>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<div className="text-sm text-primary/40">
|
|
|
|
|
<div className="flex flex-row items-center gap-1">
|
|
|
|
|
{t("details.topScore.label")}
|
|
|
|
|
<Popover>
|
|
|
|
|
<PopoverTrigger asChild>
|
|
|
|
|
<div className="cursor-pointer p-0">
|
|
|
|
|
<LuInfo className="size-4" />
|
|
|
|
|
<span className="sr-only">Info</span>
|
|
|
|
|
</div>
|
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
<PopoverContent
|
|
|
|
|
container={popoverContainerRef.current}
|
|
|
|
|
className="w-80 text-xs"
|
|
|
|
|
>
|
|
|
|
|
{t("details.topScore.info")}
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
</Popover>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-sm">
|
|
|
|
|
{topScore}%{subLabelScore && ` (${subLabelScore}%)`}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<div className="text-sm text-primary/40">
|
|
|
|
|
{t("details.camera")}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-sm smart-capitalize">
|
|
|
|
|
<CameraNameLabel camera={search.camera} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="min-w-0 flex-1">
|
|
|
|
|
<div className="flex flex-col gap-3">
|
|
|
|
|
{snapScore != undefined && (
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<div className="text-sm text-primary/40">
|
|
|
|
|
<div className="flex flex-row items-center gap-1">
|
|
|
|
|
{t("details.snapshotScore.label")}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-sm">{snapScore}%</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{averageEstimatedSpeed && (
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<div className="text-sm text-primary/40">
|
|
|
|
|
{t("details.estimatedSpeed")}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col space-y-0.5 text-sm">
|
|
|
|
|
<div className="flex flex-row items-center gap-2">
|
|
|
|
|
{averageEstimatedSpeed}{" "}
|
|
|
|
|
{config?.ui.unit_system == "imperial"
|
|
|
|
|
? t("unit.speed.mph", { ns: "common" })
|
|
|
|
|
: t("unit.speed.kph", { ns: "common" })}
|
|
|
|
|
{velocityAngle != undefined && (
|
|
|
|
|
<span className="text-primary/40">
|
|
|
|
|
<FaArrowRight
|
|
|
|
|
size={10}
|
|
|
|
|
style={{
|
|
|
|
|
transform: `rotate(${(360 - Number(velocityAngle)) % 360}deg)`,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<div className="text-sm text-primary/40">
|
|
|
|
|
{t("details.timestamp")}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-sm">{formattedDate}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-06-23 23:58:00 +03:00
|
|
|
</div>
|
2024-09-11 17:41:16 +03:00
|
|
|
</div>
|
2025-03-13 02:45:16 +03:00
|
|
|
{search?.data.recognized_license_plate && (
|
2025-03-12 23:38:28 +03:00
|
|
|
<div className="flex flex-col gap-1.5">
|
2025-03-13 02:45:16 +03:00
|
|
|
<div className="text-sm text-primary/40">
|
2025-04-10 17:27:01 +03:00
|
|
|
{t("details.recognizedLicensePlate")}
|
2025-03-13 02:45:16 +03:00
|
|
|
</div>
|
2025-03-12 23:38:28 +03:00
|
|
|
<div className="flex flex-col space-y-0.5 text-sm">
|
|
|
|
|
<div className="flex flex-row items-center gap-2">
|
2025-03-13 02:45:16 +03:00
|
|
|
{search.data.recognized_license_plate}{" "}
|
|
|
|
|
{recognizedLicensePlateScore &&
|
|
|
|
|
` (${recognizedLicensePlateScore}%)`}
|
2025-04-10 17:27:01 +03:00
|
|
|
{isAdmin && (
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<span>
|
|
|
|
|
<FaPencilAlt
|
|
|
|
|
className="size-4 cursor-pointer text-primary/40 hover:text-primary/80"
|
2025-11-06 19:22:52 +03:00
|
|
|
onClick={() => setIsLPRDialogOpen(true)}
|
2025-04-10 17:27:01 +03:00
|
|
|
/>
|
|
|
|
|
</span>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipPortal>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
{t("details.editLPR.title")}
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</TooltipPortal>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
)}
|
2025-03-12 23:38:28 +03:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-11-06 19:22:52 +03:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-11-29 16:30:04 +03:00
|
|
|
{isAdmin &&
|
|
|
|
|
search.data.type === "object" &&
|
2025-11-08 15:44:30 +03:00
|
|
|
config?.plus?.enabled &&
|
2025-11-23 18:40:25 +03:00
|
|
|
search.end_time != undefined &&
|
2025-11-08 15:44:30 +03:00
|
|
|
search.has_snapshot && (
|
2025-11-07 16:53:27 +03:00
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"my-2 flex w-full flex-col justify-between gap-1.5",
|
|
|
|
|
state == "submitted" && "flex-row",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<div className="text-sm text-primary/40">
|
|
|
|
|
<div className="flex flex-row items-center gap-1">
|
|
|
|
|
{t("explore.plus.submitToPlus.label", {
|
2025-11-06 19:22:52 +03:00
|
|
|
ns: "components/dialog",
|
|
|
|
|
})}
|
2025-11-07 16:53:27 +03:00
|
|
|
<Popover>
|
|
|
|
|
<PopoverTrigger asChild>
|
|
|
|
|
<div className="cursor-pointer p-0">
|
|
|
|
|
<LuInfo className="size-4" />
|
|
|
|
|
<span className="sr-only">Info</span>
|
|
|
|
|
</div>
|
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
<PopoverContent
|
|
|
|
|
container={popoverContainerRef.current}
|
|
|
|
|
className="w-80 text-xs"
|
|
|
|
|
>
|
|
|
|
|
{t("explore.plus.submitToPlus.desc", {
|
|
|
|
|
ns: "components/dialog",
|
|
|
|
|
})}
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
</Popover>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-11-06 19:22:52 +03:00
|
|
|
|
2025-11-07 16:53:27 +03:00
|
|
|
<div className="flex flex-row items-center justify-between gap-2 text-sm">
|
|
|
|
|
{state == "reviewing" && (
|
|
|
|
|
<>
|
|
|
|
|
<div>
|
|
|
|
|
{i18n.language === "en" ? (
|
|
|
|
|
// English with a/an logic plus label
|
|
|
|
|
<>
|
|
|
|
|
{/^[aeiou]/i.test(search?.label || "") ? (
|
|
|
|
|
<Trans
|
|
|
|
|
ns="components/dialog"
|
|
|
|
|
values={{ label: search?.label }}
|
|
|
|
|
>
|
|
|
|
|
explore.plus.review.question.ask_an
|
|
|
|
|
</Trans>
|
|
|
|
|
) : (
|
|
|
|
|
<Trans
|
|
|
|
|
ns="components/dialog"
|
|
|
|
|
values={{ label: search?.label }}
|
|
|
|
|
>
|
|
|
|
|
explore.plus.review.question.ask_a
|
|
|
|
|
</Trans>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2025-11-06 19:22:52 +03:00
|
|
|
) : (
|
2025-11-07 16:53:27 +03:00
|
|
|
// For other languages
|
2025-11-06 19:22:52 +03:00
|
|
|
<Trans
|
|
|
|
|
ns="components/dialog"
|
2025-11-07 16:53:27 +03:00
|
|
|
values={{
|
|
|
|
|
untranslatedLabel: search?.label,
|
|
|
|
|
translatedLabel: getTranslatedLabel(search?.label),
|
|
|
|
|
}}
|
2025-11-06 19:22:52 +03:00
|
|
|
>
|
2025-11-07 16:53:27 +03:00
|
|
|
explore.plus.review.question.ask_full
|
2025-11-06 19:22:52 +03:00
|
|
|
</Trans>
|
|
|
|
|
)}
|
2025-11-07 16:53:27 +03:00
|
|
|
</div>
|
|
|
|
|
<div className="flex max-w-xl flex-row gap-2">
|
|
|
|
|
<Button
|
|
|
|
|
className="flex-1 bg-success"
|
|
|
|
|
aria-label={t("button.yes", { ns: "common" })}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setState("uploading");
|
|
|
|
|
onSubmitToPlus(false);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{t("button.yes", { ns: "common" })}
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
className="flex-1 text-white"
|
|
|
|
|
aria-label={t("button.no", { ns: "common" })}
|
|
|
|
|
variant="destructive"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setState("uploading");
|
|
|
|
|
onSubmitToPlus(true);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{t("button.no", { ns: "common" })}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{state == "uploading" && <ActivityIndicator />}
|
|
|
|
|
{state == "submitted" && (
|
|
|
|
|
<div className="flex flex-row items-center justify-center gap-2">
|
|
|
|
|
<FaCheckCircle className="size-4 text-success" />
|
2025-11-12 02:23:30 +03:00
|
|
|
{t("explore.plus.review.state.submitted", {
|
|
|
|
|
ns: "components/dialog",
|
|
|
|
|
})}
|
2025-11-07 16:53:27 +03:00
|
|
|
</div>
|
|
|
|
|
)}
|
2025-11-01 17:19:30 +03:00
|
|
|
</div>
|
2025-11-07 16:53:27 +03:00
|
|
|
</div>
|
|
|
|
|
)}
|
2024-09-11 17:41:16 +03:00
|
|
|
<div className="flex flex-col gap-1.5">
|
2025-11-08 22:26:30 +03:00
|
|
|
<div className="flex items-center justify-start gap-3">
|
|
|
|
|
<div className="text-sm text-primary/40">
|
|
|
|
|
{t("details.description.label")}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
aria-label={t("button.edit", { ns: "common" })}
|
|
|
|
|
className="text-primary/40 hover:text-primary/80"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
originalDescRef.current = desc ?? "";
|
|
|
|
|
setIsEditingDesc(true);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<FaPencilAlt className="size-4" />
|
|
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
{t("button.edit", { ns: "common" })}
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
|
|
|
|
|
{config?.cameras[search?.camera].audio_transcription.enabled &&
|
|
|
|
|
search?.label == "speech" &&
|
|
|
|
|
search?.end_time && (
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
aria-label={t("itemMenu.audioTranscription.label")}
|
2025-11-24 16:34:56 +03:00
|
|
|
className={cn(
|
|
|
|
|
"text-primary/40",
|
|
|
|
|
audioTranscriptionProcessState === "processing"
|
|
|
|
|
? "cursor-not-allowed"
|
|
|
|
|
: "hover:text-primary/80",
|
|
|
|
|
)}
|
2025-11-08 22:26:30 +03:00
|
|
|
onClick={onTranscribe}
|
2025-11-24 16:34:56 +03:00
|
|
|
disabled={audioTranscriptionProcessState === "processing"}
|
2025-11-08 22:26:30 +03:00
|
|
|
>
|
2025-11-24 16:34:56 +03:00
|
|
|
{audioTranscriptionProcessState === "processing" ? (
|
|
|
|
|
<ActivityIndicator className="size-4" />
|
|
|
|
|
) : (
|
|
|
|
|
<FaMicrophone className="size-4" />
|
|
|
|
|
)}
|
2025-11-08 22:26:30 +03:00
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
{t("itemMenu.audioTranscription.label")}
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{canRegenerate && (
|
|
|
|
|
<div className="relative">
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
|
<button
|
|
|
|
|
aria-label={t("details.button.regenerate.label")}
|
|
|
|
|
className="text-primary/40 hover:text-primary/80"
|
|
|
|
|
>
|
|
|
|
|
<HiSparkles className="size-4" />
|
|
|
|
|
</button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
{t("details.button.regenerate.title")}
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
<DropdownMenuContent>
|
|
|
|
|
{search.has_snapshot && (
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
className="cursor-pointer"
|
|
|
|
|
aria-label={t("details.regenerateFromSnapshot")}
|
|
|
|
|
onClick={() => regenerateDescription("snapshot")}
|
|
|
|
|
>
|
|
|
|
|
{t("details.regenerateFromSnapshot")}
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
)}
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
className="cursor-pointer"
|
|
|
|
|
aria-label={t("details.regenerateFromThumbnails")}
|
|
|
|
|
onClick={() => regenerateDescription("thumbnails")}
|
|
|
|
|
>
|
|
|
|
|
{t("details.regenerateFromThumbnails")}
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{!isEditingDesc ? (
|
|
|
|
|
showGenAIPlaceholder ? (
|
|
|
|
|
<div className="flex h-32 flex-col items-center justify-center gap-3 border p-4 text-sm text-primary/40">
|
2024-12-18 02:33:04 +03:00
|
|
|
<div className="flex">
|
|
|
|
|
<ActivityIndicator />
|
|
|
|
|
</div>
|
2025-03-16 18:36:20 +03:00
|
|
|
<div className="flex">{t("details.description.aiTips")}</div>
|
2024-12-18 02:33:04 +03:00
|
|
|
</div>
|
2025-11-08 22:26:30 +03:00
|
|
|
) : (
|
|
|
|
|
<div className="overflow-auto text-sm text-primary">
|
|
|
|
|
{desc || t("label.none", { ns: "common" })}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2024-12-18 02:33:04 +03:00
|
|
|
) : (
|
2025-11-08 22:26:30 +03:00
|
|
|
<div className="flex flex-col gap-2">
|
2024-12-18 02:33:04 +03:00
|
|
|
<Textarea
|
2025-11-17 17:12:05 +03:00
|
|
|
className="text-md h-32 md:text-sm"
|
2025-03-16 18:36:20 +03:00
|
|
|
placeholder={t("details.description.placeholder")}
|
2024-12-18 02:33:04 +03:00
|
|
|
value={desc}
|
|
|
|
|
onChange={(e) => setDesc(e.target.value)}
|
2025-01-20 16:23:22 +03:00
|
|
|
onFocus={handleDescriptionFocus}
|
|
|
|
|
onBlur={handleDescriptionBlur}
|
2025-11-08 22:26:30 +03:00
|
|
|
autoFocus
|
2024-12-18 02:33:04 +03:00
|
|
|
/>
|
2025-11-17 17:12:05 +03:00
|
|
|
<div className="mb-10 flex flex-row justify-end gap-5">
|
2025-11-08 22:26:30 +03:00
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
2025-11-17 17:12:05 +03:00
|
|
|
aria-label={t("button.cancel", { ns: "common" })}
|
|
|
|
|
className="text-primary/40 hover:text-primary"
|
2025-11-08 22:26:30 +03:00
|
|
|
onClick={() => {
|
|
|
|
|
setIsEditingDesc(false);
|
2025-11-17 17:12:05 +03:00
|
|
|
setDesc(originalDescRef.current ?? "");
|
2025-11-08 22:26:30 +03:00
|
|
|
}}
|
|
|
|
|
>
|
2025-11-17 17:12:05 +03:00
|
|
|
<FaTimes className="size-5" />
|
2025-11-08 22:26:30 +03:00
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
2025-11-17 17:12:05 +03:00
|
|
|
{t("button.cancel", { ns: "common" })}
|
2025-11-08 22:26:30 +03:00
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<button
|
2025-11-17 17:12:05 +03:00
|
|
|
aria-label={t("button.save", { ns: "common" })}
|
|
|
|
|
className="text-primary/40 hover:text-primary/80"
|
2025-11-08 22:26:30 +03:00
|
|
|
onClick={() => {
|
|
|
|
|
setIsEditingDesc(false);
|
2025-11-17 17:12:05 +03:00
|
|
|
updateDescription();
|
2025-11-08 22:26:30 +03:00
|
|
|
}}
|
|
|
|
|
>
|
2025-11-17 17:12:05 +03:00
|
|
|
<FaCheck className="size-5" />
|
2025-11-08 22:26:30 +03:00
|
|
|
</button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
2025-11-17 17:12:05 +03:00
|
|
|
{t("button.save", { ns: "common" })}
|
2025-11-08 22:26:30 +03:00
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-12-18 02:33:04 +03:00
|
|
|
)}
|
|
|
|
|
|
2025-11-08 22:26:30 +03:00
|
|
|
<TextEntryDialog
|
|
|
|
|
open={isSubLabelDialogOpen}
|
|
|
|
|
setOpen={setIsSubLabelDialogOpen}
|
|
|
|
|
title={t("details.editSubLabel.title")}
|
|
|
|
|
description={
|
|
|
|
|
search.label
|
|
|
|
|
? t("details.editSubLabel.desc", {
|
|
|
|
|
label: search.label,
|
|
|
|
|
})
|
|
|
|
|
: t("details.editSubLabel.descNoLabel")
|
|
|
|
|
}
|
|
|
|
|
onSave={handleSubLabelSave}
|
|
|
|
|
defaultValue={search?.sub_label || ""}
|
|
|
|
|
allowEmpty={true}
|
|
|
|
|
/>
|
|
|
|
|
<TextEntryDialog
|
|
|
|
|
open={isLPRDialogOpen}
|
|
|
|
|
setOpen={setIsLPRDialogOpen}
|
|
|
|
|
title={t("details.editLPR.title")}
|
|
|
|
|
description={
|
|
|
|
|
search.label
|
|
|
|
|
? t("details.editLPR.desc", {
|
|
|
|
|
label: search.label,
|
|
|
|
|
})
|
|
|
|
|
: t("details.editLPR.descNoLabel")
|
|
|
|
|
}
|
|
|
|
|
onSave={handleLPRSave}
|
|
|
|
|
defaultValue={search?.data.recognized_license_plate || ""}
|
|
|
|
|
allowEmpty={true}
|
|
|
|
|
/>
|
2024-09-11 17:41:16 +03:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-06 20:43:36 +03:00
|
|
|
type ObjectSnapshotTabProps = {
|
|
|
|
|
search: Event;
|
2025-11-06 19:22:52 +03:00
|
|
|
className?: string;
|
|
|
|
|
onEventUploaded?: () => void;
|
2024-10-06 20:43:36 +03:00
|
|
|
};
|
2024-11-12 15:37:25 +03:00
|
|
|
export function ObjectSnapshotTab({
|
2024-10-06 20:43:36 +03:00
|
|
|
search,
|
2025-11-06 19:22:52 +03:00
|
|
|
className,
|
2024-10-06 20:43:36 +03:00
|
|
|
}: ObjectSnapshotTabProps) {
|
|
|
|
|
const [imgRef, imgLoaded, onImgLoad] = useImageLoaded();
|
|
|
|
|
|
|
|
|
|
return (
|
2025-11-06 19:22:52 +03:00
|
|
|
<div className={cn("relative", isDesktop && "size-full", className)}>
|
2024-10-06 20:43:36 +03:00
|
|
|
<ImageLoadingIndicator
|
|
|
|
|
className="absolute inset-0 aspect-video min-h-[60dvh] w-full"
|
|
|
|
|
imgLoaded={imgLoaded}
|
|
|
|
|
/>
|
2025-11-06 19:22:52 +03:00
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex size-full items-center",
|
|
|
|
|
imgLoaded ? "visible" : "invisible",
|
|
|
|
|
)}
|
|
|
|
|
>
|
2024-10-06 20:43:36 +03:00
|
|
|
<TransformWrapper minScale={1.0} wheel={{ smoothStep: 0.005 }}>
|
2025-11-06 19:22:52 +03:00
|
|
|
<div className="flex w-full flex-col space-y-3 overflow-hidden">
|
2024-10-06 20:43:36 +03:00
|
|
|
<TransformComponent
|
|
|
|
|
wrapperStyle={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
}}
|
|
|
|
|
contentStyle={{
|
|
|
|
|
position: "relative",
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{search?.id && (
|
2025-11-06 19:22:52 +03:00
|
|
|
<div className="relative mx-auto flex h-full">
|
2024-10-23 06:09:57 +03:00
|
|
|
<img
|
|
|
|
|
ref={imgRef}
|
2025-11-06 19:22:52 +03:00
|
|
|
className="mx-auto max-h-[60dvh] rounded-lg bg-background object-contain"
|
2024-10-23 06:09:57 +03:00
|
|
|
src={`${baseUrl}api/events/${search?.id}/snapshot.jpg`}
|
|
|
|
|
alt={`${search?.label}`}
|
|
|
|
|
loading={isSafari ? "eager" : "lazy"}
|
|
|
|
|
onLoad={() => {
|
|
|
|
|
onImgLoad();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2024-10-06 20:43:36 +03:00
|
|
|
)}
|
|
|
|
|
</TransformComponent>
|
|
|
|
|
</div>
|
|
|
|
|
</TransformWrapper>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-11 17:41:16 +03:00
|
|
|
type VideoTabProps = {
|
|
|
|
|
search: SearchResult;
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-13 20:46:40 +03:00
|
|
|
export function VideoTab({ search }: VideoTabProps) {
|
2025-06-21 01:39:47 +03:00
|
|
|
const clipTimeRange = useMemo(() => {
|
|
|
|
|
const startTime = search.start_time - REVIEW_PADDING;
|
|
|
|
|
const endTime = (search.end_time ?? Date.now() / 1000) + REVIEW_PADDING;
|
|
|
|
|
return `start/${startTime}/end/${endTime}`;
|
|
|
|
|
}, [search]);
|
|
|
|
|
|
|
|
|
|
const source = `${baseUrl}vod/${search.camera}/${clipTimeRange}/index.m3u8`;
|
2024-09-11 22:20:41 +03:00
|
|
|
|
2024-09-11 17:41:16 +03:00
|
|
|
return (
|
2025-05-08 01:31:24 +03:00
|
|
|
<>
|
|
|
|
|
<span tabIndex={0} className="sr-only" />
|
2025-11-06 19:22:52 +03:00
|
|
|
<GenericVideoPlayer source={source} />
|
2025-05-08 01:31:24 +03:00
|
|
|
</>
|
2024-06-23 23:58:00 +03:00
|
|
|
);
|
|
|
|
|
}
|