import { useState, ReactNode } from "react"; import { SearchResult } from "@/types/search"; import { FrigateConfig } from "@/types/frigateConfig"; import { baseUrl } from "@/api/baseUrl"; import { toast } from "sonner"; import axios from "axios"; import { LuCamera, LuDownload, LuTrash2 } from "react-icons/lu"; import { FiMoreVertical } from "react-icons/fi"; import { FaArrowsRotate } from "react-icons/fa6"; import { MdImageSearch } from "react-icons/md"; import FrigatePlusIcon from "@/components/icons/FrigatePlusIcon"; import { isMobileOnly } from "react-device-detect"; import { buttonVariants } from "@/components/ui/button"; import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger, } from "@/components/ui/context-menu"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; import useSWR from "swr"; type SearchResultActionsProps = { searchResult: SearchResult; findSimilar: () => void; refreshResults: () => void; showObjectLifecycle: () => void; showSnapshot: () => void; isContextMenu?: boolean; children?: ReactNode; }; export default function SearchResultActions({ searchResult, findSimilar, refreshResults, showObjectLifecycle, showSnapshot, isContextMenu = false, children, }: SearchResultActionsProps) { const { data: config } = useSWR("config"); const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); const handleDelete = () => { axios .delete(`events/${searchResult.id}`) .then((resp) => { if (resp.status == 200) { toast.success("Tracked object deleted successfully.", { position: "top-center", }); refreshResults(); } }) .catch(() => { toast.error("Failed to delete tracked object.", { position: "top-center", }); }); }; const MenuItem = isContextMenu ? ContextMenuItem : DropdownMenuItem; const menuItems = ( <> {searchResult.has_clip && ( Download video )} {searchResult.has_snapshot && ( Download snapshot )} {searchResult.data.type == "object" && ( View object lifecycle )} {config?.semantic_search?.enabled && isContextMenu && ( Find similar )} {isMobileOnly && config?.plus?.enabled && searchResult.has_snapshot && searchResult.end_time && searchResult.data.type == "object" && !searchResult.plus_id && ( Submit to Frigate+ )} setDeleteDialogOpen(true)} > Delete ); return ( <> setDeleteDialogOpen(!deleteDialogOpen)} > Confirm Delete Deleting this tracked object removes the snapshot, any saved embeddings, and any associated object lifecycle entries. Recorded footage of this tracked object in History view will NOT be deleted.

Are you sure you want to proceed?
Cancel Delete
{isContextMenu ? ( {children} {menuItems} ) : ( <> {config?.semantic_search?.enabled && searchResult.data.type == "object" && ( Find similar )} {!isMobileOnly && config?.plus?.enabled && searchResult.has_snapshot && searchResult.end_time && searchResult.data.type == "object" && !searchResult.plus_id && ( Submit to Frigate+ )} {menuItems} )} ); }