* Use different cursor for dragging preview

* Improve filters UI and add audio labels

* Use switch and adjust colors

* Disable chromecast button and remove dimming

* Change marked reviewed text
This commit is contained in:
Nicolas Mowen 2024-03-06 13:49:51 -07:00 committed by GitHub
parent 55077a0bc9
commit fb81e44283
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 293 additions and 196 deletions

View File

@ -1,4 +1,4 @@
import { LuCheck, LuVideo } from "react-icons/lu"; import { LuCheck } from "react-icons/lu";
import { Button } from "../ui/button"; import { Button } from "../ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"; import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
import useSWR from "swr"; import useSWR from "swr";
@ -16,8 +16,11 @@ import { ReviewFilter } from "@/types/review";
import { getEndOfDayTimestamp } from "@/utils/dateUtil"; import { getEndOfDayTimestamp } from "@/utils/dateUtil";
import { useFormattedTimestamp } from "@/hooks/use-date-utils"; import { useFormattedTimestamp } from "@/hooks/use-date-utils";
import { FaCalendarAlt, FaFilter, FaVideo } from "react-icons/fa"; import { FaCalendarAlt, FaFilter, FaVideo } from "react-icons/fa";
import { getIconTypeForGroup } from "@/utils/iconUtil";
import { IconType } from "react-icons"; import { IconType } from "react-icons";
import { isMobile } from "react-device-detect";
import { Drawer, DrawerContent, DrawerTrigger } from "../ui/drawer";
import { Switch } from "../ui/switch";
import { Label } from "../ui/label";
const ATTRIBUTES = ["amazon", "face", "fedex", "license_plate", "ups"]; const ATTRIBUTES = ["amazon", "face", "fedex", "license_plate", "ups"];
@ -41,14 +44,21 @@ export default function ReviewFilterGroup({
const cameras = filter?.cameras || Object.keys(config.cameras); const cameras = filter?.cameras || Object.keys(config.cameras);
cameras.forEach((camera) => { cameras.forEach((camera) => {
config.cameras[camera].objects.track.forEach((label) => { const cameraConfig = config.cameras[camera];
cameraConfig.objects.track.forEach((label) => {
if (!ATTRIBUTES.includes(label)) { if (!ATTRIBUTES.includes(label)) {
labels.add(label); labels.add(label);
} }
}); });
if (cameraConfig.audio.enabled_in_config) {
cameraConfig.audio.listen.forEach((label) => {
labels.add(label);
});
}
}); });
return [...labels]; return [...labels].sort();
}, [config, filter]); }, [config, filter]);
const filterValues = useMemo( const filterValues = useMemo(
@ -125,88 +135,123 @@ function CamerasFilterButton({
selectedCameras, selectedCameras,
updateCameraFilter, updateCameraFilter,
}: CameraFilterButtonProps) { }: CameraFilterButtonProps) {
const [open, setOpen] = useState(false);
const [currentCameras, setCurrentCameras] = useState<string[] | undefined>( const [currentCameras, setCurrentCameras] = useState<string[] | undefined>(
selectedCameras, selectedCameras,
); );
return ( const trigger = (
<DropdownMenu <Button size="sm" className="mx-1 capitalize" variant="secondary">
onOpenChange={(open) => { <FaVideo className="md:mr-[10px] text-muted-foreground" />
if (!open) { <div className="hidden md:block">
updateCameraFilter(currentCameras); {selectedCameras == undefined
} ? "All Cameras"
}} : `${selectedCameras.length} Cameras`}
> </div>
<DropdownMenuTrigger asChild> </Button>
<Button size="sm" className="mx-1 capitalize" variant="secondary"> );
<FaVideo className="md:mr-[10px] text-muted-foreground" /> const content = (
<div className="hidden md:block"> <>
{selectedCameras == undefined <DropdownMenuLabel className="flex justify-center">
? "All Cameras" Filter Cameras
: `${selectedCameras.length} Cameras`} </DropdownMenuLabel>
</div> <DropdownMenuSeparator />
</Button> <FilterCheckBox
</DropdownMenuTrigger> isChecked={currentCameras == undefined}
<DropdownMenuContent> label="All Cameras"
<DropdownMenuLabel>Filter Cameras</DropdownMenuLabel> onCheckedChange={(isChecked) => {
<DropdownMenuSeparator /> if (isChecked) {
setCurrentCameras(undefined);
}
}}
/>
{groups.length > 0 && (
<>
<DropdownMenuSeparator />
{groups.map(([name, conf]) => {
return (
<FilterCheckBox
key={name}
label={name}
isChecked={false}
onCheckedChange={() => {
setCurrentCameras([...conf.cameras]);
}}
/>
);
})}
</>
)}
<DropdownMenuSeparator />
{allCameras.map((item) => (
<FilterCheckBox <FilterCheckBox
isChecked={currentCameras == undefined} key={item}
label="All Cameras" isChecked={currentCameras?.includes(item) ?? false}
label={item.replaceAll("_", " ")}
onCheckedChange={(isChecked) => { onCheckedChange={(isChecked) => {
if (isChecked) { if (isChecked) {
setCurrentCameras(undefined); const updatedCameras = currentCameras ? [...currentCameras] : [];
updatedCameras.push(item);
setCurrentCameras(updatedCameras);
} else {
const updatedCameras = currentCameras ? [...currentCameras] : [];
// can not deselect the last item
if (updatedCameras.length > 1) {
updatedCameras.splice(updatedCameras.indexOf(item), 1);
setCurrentCameras(updatedCameras);
}
} }
}} }}
/> />
{groups.length > 0 && ( ))}
<> <DropdownMenuSeparator />
<DropdownMenuSeparator /> <div className="flex justify-center items-center">
{groups.map(([name, conf]) => { <Button
return ( variant="select"
<FilterCheckBox onClick={() => {
key={name} updateCameraFilter(currentCameras);
label={name} setOpen(false);
CheckIcon={getIconTypeForGroup(conf.icon)} }}
isChecked >
onCheckedChange={() => { Apply
setCurrentCameras([...conf.cameras]); </Button>
}} </div>
/> </>
); );
})}
</>
)}
<DropdownMenuSeparator />
{allCameras.map((item) => (
<FilterCheckBox
key={item}
isChecked={currentCameras?.includes(item) ?? false}
label={item.replaceAll("_", " ")}
onCheckedChange={(isChecked) => {
if (isChecked) {
const updatedCameras = currentCameras
? [...currentCameras]
: [];
updatedCameras.push(item); if (isMobile) {
setCurrentCameras(updatedCameras); return (
} else { <Drawer
const updatedCameras = currentCameras open={open}
? [...currentCameras] onOpenChange={(open) => {
: []; if (!open) {
setCurrentCameras(selectedCameras);
}
// can not deselect the last item setOpen(open);
if (updatedCameras.length > 1) { }}
updatedCameras.splice(updatedCameras.indexOf(item), 1); >
setCurrentCameras(updatedCameras); <DrawerTrigger asChild>{trigger}</DrawerTrigger>
} <DrawerContent>{content}</DrawerContent>
} </Drawer>
}} );
/> }
))}
<DropdownMenuSeparator /> return (
</DropdownMenuContent> <DropdownMenu
open={open}
onOpenChange={(open) => {
if (!open) {
setCurrentCameras(selectedCameras);
}
setOpen(open);
}}
>
<DropdownMenuTrigger asChild>{trigger}</DropdownMenuTrigger>
<DropdownMenuContent>{content}</DropdownMenuContent>
</DropdownMenu> </DropdownMenu>
); );
} }
@ -219,6 +264,7 @@ function CalendarFilterButton({
day, day,
updateSelectedDay, updateSelectedDay,
}: CalendarFilterButtonProps) { }: CalendarFilterButtonProps) {
const [open, setOpen] = useState(false);
const [selectedDay, setSelectedDay] = useState(day); const [selectedDay, setSelectedDay] = useState(day);
const disabledDates = useMemo(() => { const disabledDates = useMemo(() => {
const tomorrow = new Date(); const tomorrow = new Date();
@ -232,32 +278,71 @@ function CalendarFilterButton({
"%b %-d", "%b %-d",
); );
const trigger = (
<Button size="sm" className="mx-1" variant="secondary">
<FaCalendarAlt className="md:mr-[10px] text-muted-foreground" />
<div className="hidden md:block">
{day == undefined ? "Last 24 Hours" : selectedDate}
</div>
</Button>
);
const content = (
<>
<Calendar
mode="single"
disabled={disabledDates}
selected={selectedDay}
showOutsideDays={false}
onSelect={(day) => {
setSelectedDay(day);
}}
/>
<DropdownMenuSeparator />
<div className="flex justify-center items-center">
<Button
variant="select"
onClick={() => {
updateSelectedDay(selectedDay);
setOpen(false);
}}
>
Apply
</Button>
</div>
</>
);
if (isMobile) {
return (
<Drawer
open={open}
onOpenChange={(open) => {
if (!open) {
setSelectedDay(day);
}
setOpen(open);
}}
>
<DrawerTrigger asChild>{trigger}</DrawerTrigger>
<DrawerContent>{content}</DrawerContent>
</Drawer>
);
}
return ( return (
<Popover <Popover
open={open}
onOpenChange={(open) => { onOpenChange={(open) => {
if (!open) { if (!open) {
updateSelectedDay(selectedDay); setSelectedDay(day);
} }
setOpen(open);
}} }}
> >
<PopoverTrigger asChild> <PopoverTrigger asChild>{trigger}</PopoverTrigger>
<Button size="sm" className="mx-1" variant="secondary"> <PopoverContent>{content}</PopoverContent>
<FaCalendarAlt className="md:mr-[10px] text-muted-foreground" />
<div className="hidden md:block">
{day == undefined ? "Last 24 Hours" : selectedDate}
</div>
</Button>
</PopoverTrigger>
<PopoverContent>
<Calendar
mode="single"
disabled={disabledDates}
selected={selectedDay}
onSelect={(day) => {
setSelectedDay(day);
}}
/>
</PopoverContent>
</Popover> </Popover>
); );
} }
@ -276,108 +361,122 @@ function GeneralFilterButton({
showReviewed, showReviewed,
setShowReviewed, setShowReviewed,
}: GeneralFilterButtonProps) { }: GeneralFilterButtonProps) {
return ( const [open, setOpen] = useState(false);
<Popover> const [reviewed, setReviewed] = useState(showReviewed ?? 0);
<PopoverTrigger asChild>
<Button size="sm" className="ml-1" variant="secondary">
<FaFilter className="md:mr-[10px] text-muted-foreground" />
<div className="hidden md:block">Filter</div>
</Button>
</PopoverTrigger>
<PopoverContent side="left" asChild>
<div className="w-80 flex">
<LabelsFilterButton
allLabels={allLabels}
selectedLabels={selectedLabels}
updateLabelFilter={updateLabelFilter}
/>
<Button
className="capitalize flex justify-between items-center cursor-pointer w-full"
variant="secondary"
onClick={() => setShowReviewed(showReviewed == 0 ? 1 : 0)}
>
{showReviewed ? (
<LuCheck className="w-6 h-6" />
) : (
<div className="w-6 h-6" />
)}
<div className="ml-1 w-full flex justify-start">Show Reviewed</div>
</Button>
</div>
</PopoverContent>
</Popover>
);
}
type LabelFilterButtonProps = {
allLabels: string[];
selectedLabels: string[] | undefined;
updateLabelFilter: (labels: string[] | undefined) => void;
};
function LabelsFilterButton({
allLabels,
selectedLabels,
updateLabelFilter,
}: LabelFilterButtonProps) {
const [currentLabels, setCurrentLabels] = useState<string[] | undefined>( const [currentLabels, setCurrentLabels] = useState<string[] | undefined>(
selectedLabels, selectedLabels,
); );
return ( const trigger = (
<DropdownMenu <Button size="sm" className="ml-1" variant="secondary">
onOpenChange={(open) => { <FaFilter className="md:mr-[10px] text-muted-foreground" />
if (!open) { <div className="hidden md:block">Filter</div>
updateLabelFilter(currentLabels); </Button>
} );
}} const content = (
> <>
<DropdownMenuTrigger asChild> <div className="flex p-2 justify-start items-center">
<Button className="mx-1 capitalize" variant="secondary"> <Switch
<LuVideo className=" mr-[10px]" /> id="reviewed"
{selectedLabels == undefined checked={reviewed == 1}
? "All Labels" onCheckedChange={() => setReviewed(reviewed == 0 ? 1 : 0)}
: `${selectedLabels.length} Labels`} />
</Button> <Label className="ml-2" htmlFor="reviewed">Show Reviewed</Label>
</DropdownMenuTrigger> </div>
<DropdownMenuContent> <DropdownMenuSeparator />
<DropdownMenuLabel>Filter Labels</DropdownMenuLabel> <DropdownMenuLabel className="flex justify-center items-center">
<DropdownMenuSeparator /> Filter Labels
</DropdownMenuLabel>
<DropdownMenuSeparator />
<FilterCheckBox
isChecked={currentLabels == undefined}
label="All Labels"
onCheckedChange={(isChecked) => {
if (isChecked) {
setCurrentLabels(undefined);
}
}}
/>
<DropdownMenuSeparator />
{allLabels.map((item) => (
<FilterCheckBox <FilterCheckBox
isChecked={currentLabels == undefined} key={item}
label="All Labels" isChecked={currentLabels?.includes(item) ?? false}
label={item.replaceAll("_", " ")}
onCheckedChange={(isChecked) => { onCheckedChange={(isChecked) => {
if (isChecked) { if (isChecked) {
setCurrentLabels(undefined); const updatedLabels = currentLabels ? [...currentLabels] : [];
updatedLabels.push(item);
setCurrentLabels(updatedLabels);
} else {
const updatedLabels = currentLabels ? [...currentLabels] : [];
// can not deselect the last item
if (updatedLabels.length > 1) {
updatedLabels.splice(updatedLabels.indexOf(item), 1);
setCurrentLabels(updatedLabels);
}
} }
}} }}
/> />
<DropdownMenuSeparator /> ))}
{allLabels.map((item) => ( <DropdownMenuSeparator />
<FilterCheckBox <div className="flex justify-center items-center">
key={item} <Button
isChecked={currentLabels?.includes(item) ?? false} variant="select"
label={item.replaceAll("_", " ")} onClick={() => {
onCheckedChange={(isChecked) => { if (reviewed != showReviewed) {
if (isChecked) { setShowReviewed(reviewed);
const updatedLabels = currentLabels ? [...currentLabels] : []; }
updatedLabels.push(item); if (selectedLabels != currentLabels) {
setCurrentLabels(updatedLabels); updateLabelFilter(currentLabels);
} else { }
const updatedLabels = currentLabels ? [...currentLabels] : [];
// can not deselect the last item setOpen(false);
if (updatedLabels.length > 1) { }}
updatedLabels.splice(updatedLabels.indexOf(item), 1); >
setCurrentLabels(updatedLabels); Apply
} </Button>
} </div>
}} </>
/> );
))}
<DropdownMenuSeparator /> if (isMobile) {
</DropdownMenuContent> return (
</DropdownMenu> <Drawer
open={open}
onOpenChange={(open) => {
if (!open) {
setReviewed(showReviewed ?? 0);
setCurrentLabels(selectedLabels);
}
setOpen(open);
}}
>
<DrawerTrigger asChild>{trigger}</DrawerTrigger>
<DrawerContent>{content}</DrawerContent>
</Drawer>
);
}
return (
<Popover
open={open}
onOpenChange={(open) => {
if (!open) {
setReviewed(showReviewed ?? 0);
setCurrentLabels(selectedLabels);
}
setOpen(open);
}}
>
<PopoverTrigger asChild>{trigger}</PopoverTrigger>
<PopoverContent side="left">{content}</PopoverContent>
</Popover>
); );
} }

View File

@ -301,6 +301,7 @@ export default function DynamicVideoPlayer({
autoPlay autoPlay
playsInline playsInline
muted muted
disableRemotePlayback
onSeeked={onPreviewSeeked} onSeeked={onPreviewSeeked}
onLoadedData={() => controller.previewReady()} onLoadedData={() => controller.previewReady()}
> >
@ -308,9 +309,6 @@ export default function DynamicVideoPlayer({
<source src={currentPreview.src} type={currentPreview.type} /> <source src={currentPreview.src} type={currentPreview.type} />
)} )}
</video> </video>
{onClick && !hasRecordingAtTime && (
<div className="absolute inset-0 z-10 bg-black bg-opacity-60 rounded-2xl" />
)}
</div> </div>
); );
} }

View File

@ -10,7 +10,7 @@ const buttonVariants = cva(
variants: { variants: {
variant: { variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90", default: "bg-primary text-primary-foreground hover:bg-primary/90",
select: "bg-select text-white hover:bg-select/90", select: "bg-selected text-white hover:bg-opacity-90",
destructive: destructive:
"bg-destructive text-destructive-foreground hover:bg-destructive/90", "bg-destructive text-destructive-foreground hover:bg-destructive/90",
outline: outline:

View File

@ -25,24 +25,24 @@ function Calendar({
nav: "space-x-1 flex items-center", nav: "space-x-1 flex items-center",
nav_button: cn( nav_button: cn(
buttonVariants({ variant: "outline" }), buttonVariants({ variant: "outline" }),
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100" "h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100",
), ),
nav_button_previous: "absolute left-1", nav_button_previous: "absolute left-1",
nav_button_next: "absolute right-1", nav_button_next: "absolute right-1",
table: "w-full border-collapse space-y-1", table: "w-full border-collapse space-y-1",
head_row: "flex", head_row: "flex justify-center",
head_cell: head_cell:
"text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]", "text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]",
row: "flex w-full mt-2", row: "flex w-full mt-2 justify-center",
cell: "h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20", cell: "h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20",
day: cn( day: cn(
buttonVariants({ variant: "ghost" }), buttonVariants({ variant: "ghost" }),
"h-9 w-9 p-0 font-normal aria-selected:opacity-100" "h-9 w-9 p-0 font-normal aria-selected:opacity-100",
), ),
day_range_end: "day-range-end", day_range_end: "day-range-end",
day_selected: day_selected:
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground", "bg-selected text-white hover:bg-selected hover:text-white focus:bg-selected focus:text-white",
day_today: "bg-accent text-accent-foreground", day_today: "bg-muted text-muted-foreground",
day_outside: day_outside:
"day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30", "day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30",
day_disabled: "text-muted-foreground opacity-50", day_disabled: "text-muted-foreground opacity-50",

View File

@ -18,7 +18,7 @@ const Slider = React.forwardRef<
<SliderPrimitive.Track className="relative h-1 w-full grow overflow-hidden rounded-full"> <SliderPrimitive.Track className="relative h-1 w-full grow overflow-hidden rounded-full">
<SliderPrimitive.Range className="absolute h-full bg-blue-500" /> <SliderPrimitive.Range className="absolute h-full bg-blue-500" />
</SliderPrimitive.Track> </SliderPrimitive.Track>
<SliderPrimitive.Thumb className="block h-2 w-12 rounded-full border-2 border-transparent bg-transparent ring-offset-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50" /> <SliderPrimitive.Thumb className="block h-2 w-12 rounded-full border-2 border-transparent bg-transparent ring-offset-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 cursor-col-resize" />
</SliderPrimitive.Root> </SliderPrimitive.Root>
)); ));
Slider.displayName = SliderPrimitive.Root.displayName; Slider.displayName = SliderPrimitive.Root.displayName;

View File

@ -9,7 +9,7 @@ const Switch = React.forwardRef<
>(({ className, ...props }, ref) => ( >(({ className, ...props }, ref) => (
<SwitchPrimitives.Root <SwitchPrimitives.Root
className={cn( className={cn(
"peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input", "peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-selected data-[state=unchecked]:bg-input",
className className
)} )}
{...props} {...props}

View File

@ -517,7 +517,7 @@ function DetectionReview({
variant="select" variant="select"
onClick={markAllReviewed} onClick={markAllReviewed}
> >
Mark all items as reviewed Mark these items as reviewed
</Button> </Button>
) : ( ) : (
<ActivityIndicator /> <ActivityIndicator />