NVR with realtime local object detection for IP cameras
TypeScript aicameragoogle-coralhome-assistanthome-automationhomeautomationmqttnvrobject-detectionrealtimertsptensorflow
Mobile UI/UX improvements (#23402)
Josh Hawkinsb751025339d9
diff --git a/web/index.html b/web/index.htmlindex be6b302f5c..bb019d4263 100644--- a/web/index.html+++ b/web/index.html@@ -3,7 +3,7 @@<head><meta charset="UTF-8" /><link rel="icon" href="/images/branding/favicon.ico" />- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" /><title>Frigate</title><linkrel="apple-touch-icon"diff --git a/web/public/locales/en/components/camera.json b/web/public/locales/en/components/camera.jsonindex ed37d1771f..3f6afc6420 100644--- a/web/public/locales/en/components/camera.json+++ b/web/public/locales/en/components/camera.json@@ -2,7 +2,10 @@"group": {"label": "Camera Groups","add": "Add Camera Group",+ "showAll": "Show all camera groups",+ "showLess": "Show less","edit": "Edit Camera Group",+ "editGroups": "Edit Camera Groups","delete": {"label": "Delete Camera Group","confirm": {diff --git a/web/src/App.tsx b/web/src/App.tsxindex 01c415de47..550bc36c81 100644--- a/web/src/App.tsx+++ b/web/src/App.tsx@@ -78,7 +78,9 @@ function DefaultAppView() {className={cn("absolute right-0 top-0 overflow-hidden",isMobile- ? `bottom-${isPWA ? 16 : 12} left-0 md:bottom-16 landscape:bottom-14 landscape:md:bottom-16`+ ? isPWA+ ? "bottom-[calc(3rem+env(safe-area-inset-bottom))] left-0 pt-[env(safe-area-inset-top)] md:bottom-[calc(4rem+env(safe-area-inset-bottom))] landscape:pl-[env(safe-area-inset-left)] landscape:pr-[env(safe-area-inset-right)]"+ : "bottom-12 left-0 md:bottom-16": "bottom-8 left-[52px]",)}>diff --git a/web/src/components/filter/CameraGroupSelector.tsx b/web/src/components/filter/CameraGroupSelector.tsxindex d4f01481f3..8f32846fc1 100644--- a/web/src/components/filter/CameraGroupSelector.tsx+++ b/web/src/components/filter/CameraGroupSelector.tsx@@ -8,7 +8,17 @@ import { isDesktop, isMobile } from "react-device-detect";import useSWR from "swr";import { MdHome } from "react-icons/md";import { Button, buttonVariants } from "../ui/button";-import { useCallback, useEffect, useMemo, useState } from "react";+import {+ useCallback,+ useEffect,+ useLayoutEffect,+ useMemo,+ useRef,+ useState,+} from "react";+import { AnimatePresence, motion } from "framer-motion";+import { HiDotsHorizontal } from "react-icons/hi";+import { IoClose } from "react-icons/io5";import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";import { LuPencil, LuPlus } from "react-icons/lu";import {@@ -56,7 +66,6 @@ import { z } from "zod";import { Toaster } from "@/components/ui/sonner";import { toast } from "sonner";import ActivityIndicator from "../indicators/activity-indicator";-import { ScrollArea, ScrollBar } from "../ui/scroll-area";import { useUserPersistence } from "@/hooks/use-user-persistence";import { TooltipPortal } from "@radix-ui/react-tooltip";import { cn } from "@/lib/utils";@@ -145,7 +154,142 @@ export function CameraGroupSelector({ className }: CameraGroupSelectorProps) {const [addGroup, setAddGroup] = useState(false);- const Scroller = isMobile ? ScrollArea : "div";+ // mobile overflow reveal - the group strip sits left of the logo and is+ // clipped (not scrollable) when there are too many groups, so render only+ // the buttons that fully fit and surface a kebab next to the last visible+ // one that expands a panel revealing all of them++ const [expanded, setExpanded] = useState(false);+ // null => all buttons fit, render them all with no kebab; a number => only+ // that many fit alongside the kebab+ const [visibleCount, setVisibleCount] = useState<number | null>(null);+ const wrapperRef = useRef<HTMLDivElement | null>(null);+ const measureRef = useRef<HTMLDivElement | null>(null);++ useLayoutEffect(() => {+ if (isDesktop) {+ return;+ }++ const wrapper = wrapperRef.current;+ const measure = measureRef.current;++ if (!wrapper || !measure) {+ return;+ }++ const gap = 8; // gap-2 between buttons in the strip+ const wrapperGap = 4; // gap-1 between the strip and the kebab++ const compute = () => {+ const buttons = Array.from(measure.children) as HTMLElement[];++ if (buttons.length === 0) {+ return;+ }++ // the trailing child of the measurement row is a kebab clone+ const kebab = buttons[buttons.length - 1];+ const groupButtons = buttons.slice(0, -1);+ const available = wrapper.clientWidth;+ const fullWidth =+ groupButtons.reduce((sum, el) => sum + el.offsetWidth, 0) ++ Math.max(groupButtons.length - 1, 0) * gap;++ if (fullWidth <= available) {+ setVisibleCount(null);+ return;+ }++ const budget = available - kebab.offsetWidth - wrapperGap;+ let used = 0;+ let count = 0;++ for (const el of groupButtons) {+ const next = (count === 0 ? 0 : gap) + el.offsetWidth;++ if (used + next <= budget) {+ used += next;+ count += 1;+ } else {+ break;+ }+ }++ setVisibleCount(Math.max(count, 1));+ };++ compute();++ const observer = new ResizeObserver(compute);+ observer.observe(wrapper);++ return () => observer.disconnect();+ }, [groups, isAdmin]);++ const groupButtons = (afterSelect?: () => void) => {+ const buttons = [+ <Button+ key="default-group"+ className={cn(+ "shrink-0",+ group == "default"+ ? "bg-blue-900 bg-opacity-60 text-selected focus:bg-blue-900 focus:bg-opacity-60"+ : "bg-secondary text-secondary-foreground",+ )}+ aria-label={t("menu.live.allCameras", { ns: "common" })}+ size="sm"+ onClick={() => {+ if (group) {+ setGroup("default", true);+ }+ afterSelect?.();+ }}+ >+ <MdHome className="size-5" />+ </Button>,+ ...groups.map(([name, config]) => (+ <Button+ key={name}+ className={cn(+ "shrink-0",+ group == name+ ? "bg-blue-900 bg-opacity-60 text-selected focus:bg-blue-900 focus:bg-opacity-60"+ : "bg-secondary text-secondary-foreground",+ )}+ aria-label={t("group.label")}+ size="sm"+ onClick={() => {+ setGroup(name, group != "default");+ afterSelect?.();+ }}+ >+ {config && config.icon && isValidIconName(config.icon) && (+ <IconRenderer icon={LuIcons[config.icon]} className="size-5" />+ )}+ </Button>+ )),+ ];++ if (isAdmin) {+ buttons.push(+ <Button+ key="add-group"+ className="shrink-0 bg-secondary text-muted-foreground"+ aria-label={t("group.add")}+ size="sm"+ onClick={() => {+ setAddGroup(true);+ afterSelect?.();+ }}+ >+ <LuPencil className="size-5 text-primary" />+ </Button>,+ );+ }++ return buttons;+ };return (<>@@ -158,12 +302,11 @@ export function CameraGroupSelector({ className }: CameraGroupSelectorProps) {deleteGroup={deleteGroup}isAdmin={isAdmin}/>- <Scroller className={`${isMobile ? "whitespace-nowrap" : ""}`}>+ {isDesktop ? (<divclassName={cn(- "flex items-center justify-start gap-2",+ "flex flex-col items-center justify-start gap-2",className,- isDesktop ? "flex-col" : "whitespace-nowrap",)}><Tooltip open={tooltip == "default"}>@@ -177,8 +320,8 @@ export function CameraGroupSelector({ className }: CameraGroupSelectorProps) {aria-label={t("menu.live.allCameras", { ns: "common" })}size="xs"onClick={() => (group ? setGroup("default", true) : null)}- onMouseEnter={() => (isDesktop ? showTooltip("default") : null)}- onMouseLeave={() => (isDesktop ? showTooltip(undefined) : null)}+ onMouseEnter={() => showTooltip("default")}+ onMouseLeave={() => showTooltip(undefined)}><MdHome className="size-4" /></Button>@@ -202,10 +345,8 @@ export function CameraGroupSelector({ className }: CameraGroupSelectorProps) {aria-label={t("group.label")}size="xs"onClick={() => setGroup(name, group != "default")}- onMouseEnter={() => (isDesktop ? showTooltip(name) : null)}- onMouseLeave={() =>- isDesktop ? showTooltip(undefined) : null- }+ onMouseEnter={() => showTooltip(name)}+ onMouseLeave={() => showTooltip(undefined)}>{config && config.icon && isValidIconName(config.icon) && (<IconRenderer@@ -225,18 +366,97 @@ export function CameraGroupSelector({ className }: CameraGroupSelectorProps) {})}{isAdmin && (+ <Tooltip open={tooltip == "edit"}>+ <TooltipTrigger asChild>+ <Button+ className="bg-secondary text-muted-foreground"+ aria-label={t("group.editGroups")}+ size="xs"+ onClick={() => setAddGroup(true)}+ onMouseEnter={() => showTooltip("edit")}+ onMouseLeave={() => showTooltip(undefined)}+ >+ <LuPencil className="size-4 text-primary" />+ </Button>+ </TooltipTrigger>+ <TooltipPortal>+ <TooltipContent side="right">+ {t("group.editGroups")}+ </TooltipContent>+ </TooltipPortal>+ </Tooltip>+ )}+ </div>+ ) : (+ <div+ ref={wrapperRef}+ className={cn("flex min-w-0 items-center gap-1", className)}+ >+ <div className="flex min-w-0 items-center gap-2 overflow-hidden whitespace-nowrap">+ {visibleCount == null+ ? groupButtons()+ : groupButtons().slice(0, visibleCount)}+ </div>+ {visibleCount != null && (<Button- className="bg-secondary text-muted-foreground"- aria-label={t("group.add")}- size="xs"- onClick={() => setAddGroup(true)}+ variant="ghost"+ size="sm"+ className="shrink-0 px-2 text-secondary-foreground"+ aria-label={t("group.showAll")}+ onClick={() => setExpanded(true)}>- <LuPlus className="size-4 text-primary" />+ <HiDotsHorizontal className="size-5" /></Button>)}- {isMobile && <ScrollBar orientation="horizontal" className="h-0" />}++ {/* invisible row used only to measure natural button widths so we+ can render exactly the buttons that fully fit */}+ <div+ className="pointer-events-none absolute left-0 top-0 h-0 w-0 overflow-hidden"+ aria-hidden+ inert+ >+ <div ref={measureRef} className="flex w-max items-center gap-2">+ {groupButtons()}+ <Button variant="ghost" size="sm" className="px-2">+ <HiDotsHorizontal className="size-5" />+ </Button>+ </div>+ </div>++ {expanded && (+ <div+ className="fixed inset-0 z-20"+ onClick={() => setExpanded(false)}+ />+ )}+ <AnimatePresence>+ {expanded && (+ <motion.div+ key="group-overlay"+ className="absolute inset-x-0 top-0 z-30 bg-background py-1 shadow-lg"+ initial={{ clipPath: "inset(0 100% 0 0)" }}+ animate={{ clipPath: "inset(0 0% 0 0)" }}+ exit={{ clipPath: "inset(0 100% 0 0)" }}+ transition={{ duration: 0.2, ease: "easeInOut" }}+ >+ <div className="flex flex-wrap items-center gap-2">+ {groupButtons(() => setExpanded(false))}+ <Button+ variant="ghost"+ size="sm"+ className="ml-auto shrink-0 px-2 text-secondary-foreground"+ aria-label={t("group.showLess")}+ onClick={() => setExpanded(false)}+ >+ <IoClose className="size-5" />+ </Button>+ </div>+ </motion.div>+ )}+ </AnimatePresence></div>- </Scroller>+ )}</>);}diff --git a/web/src/components/icons/LiveIcons.tsx b/web/src/components/icons/LiveIcons.tsxindex 9a8d58fcf9..b8ff089bba 100644--- a/web/src/components/icons/LiveIcons.tsx+++ b/web/src/components/icons/LiveIcons.tsx@@ -6,9 +6,9 @@ export function LiveGridIcon({ layout }: LiveIconProps) {return (<div className="flex size-full flex-col gap-0.5 overflow-hidden rounded-md"><div- className={`h-1 w-full ${layout == "grid" ? "bg-selected" : "bg-muted-foreground"}`}+ className={`w-full flex-1 ${layout == "grid" ? "bg-selected" : "bg-muted-foreground"}`}/>- <div className="flex h-1 w-full gap-0.5">+ <div className="flex w-full flex-1 gap-0.5"><divclassName={`w-full ${layout == "grid" ? "bg-selected" : "bg-muted-foreground"}`}/>@@ -16,7 +16,7 @@ export function LiveGridIcon({ layout }: LiveIconProps) {className={`w-full ${layout == "grid" ? "bg-selected" : "bg-muted-foreground"}`}/></div>- <div className="flex h-1 w-full gap-0.5">+ <div className="flex w-full flex-1 gap-0.5"><divclassName={`w-full ${layout == "grid" ? "bg-selected" : "bg-muted-foreground"}`}/>diff --git a/web/src/components/menu/GeneralSettings.tsx b/web/src/components/menu/GeneralSettings.tsxindex 88d834d4dc..19a0f51022 100644--- a/web/src/components/menu/GeneralSettings.tsx+++ b/web/src/components/menu/GeneralSettings.tsx@@ -82,9 +82,13 @@ import { MdCategory } from "react-icons/md";type GeneralSettingsProps = {className?: string;+ large?: boolean;};-export default function GeneralSettings({ className }: GeneralSettingsProps) {+export default function GeneralSettings({+ className,+ large,+}: GeneralSettingsProps) {const { t } = useTranslation(["common", "views/settings"]);const { getLocaleDocUrl } = useDocDomain();const { data: profile } = useSWR("profile");@@ -225,10 +229,13 @@ export default function GeneralSettings({ className }: GeneralSettingsProps) {isDesktop? "cursor-pointer rounded-lg bg-secondary text-secondary-foreground hover:bg-muted": "text-secondary-foreground",+ large && "size-12",className,)}>- <LuSettings className="size-5 md:m-[6px]" />+ <LuSettings+ className={cn("md:m-[6px]", large ? "size-6" : "size-5")}+ /></div></TooltipTrigger><TooltipPortal>diff --git a/web/src/components/mobile/MobilePage.tsx b/web/src/components/mobile/MobilePage.tsxindex ee56468cb2..b445a9f036 100644--- a/web/src/components/mobile/MobilePage.tsx+++ b/web/src/components/mobile/MobilePage.tsx@@ -146,9 +146,10 @@ export function MobilePageContent({<motion.divref={containerRef}className={cn(- "fixed inset-0 z-50 mb-12 bg-background",- isPWA && "mb-16",- "landscape:mb-14 landscape:md:mb-16",+ "fixed inset-0 z-50 bg-background",+ isPWA+ ? "mb-[calc(3rem+env(safe-area-inset-bottom))] md:mb-[calc(4rem+env(safe-area-inset-bottom))]"+ : "mb-12 md:mb-16",className,)}initial={{ x: "100%" }}diff --git a/web/src/components/navigation/Bottombar.tsx b/web/src/components/navigation/Bottombar.tsxindex 0c344363bf..309cf63a86 100644--- a/web/src/components/navigation/Bottombar.tsx+++ b/web/src/components/navigation/Bottombar.tsx@@ -4,7 +4,14 @@ import { Drawer, DrawerContent, DrawerTrigger } from "../ui/drawer";import useSWR from "swr";import { FrigateStats } from "@/types/stats";import { useEmbeddingsReindexProgress, useFrigateStats } from "@/api/ws";-import { useContext, useEffect, useMemo } from "react";+import {+ useContext,+ useEffect,+ useLayoutEffect,+ useMemo,+ useRef,+ useState,+} from "react";import useStats from "@/hooks/use-stats";import GeneralSettings from "../menu/GeneralSettings";import useNavigation from "@/hooks/use-navigation";@@ -14,36 +21,82 @@ import {} from "@/context/statusbar-provider";import { Link } from "react-router-dom";import { cn } from "@/lib/utils";-import { isIOS, isMobile } from "react-device-detect";+import { isMobile } from "react-device-detect";import { isPWA } from "@/utils/isPWA";import { useTranslation } from "react-i18next";function Bottombar() {const navItems = useNavigation("secondary");+ // Render 48px touch targets when they fit with even spacing, otherwise fall+ // back to the compact size. Measured against the live bar width and icon+ // count (which varies with enabled nav items and the status alert).+ const containerRef = useRef<HTMLDivElement | null>(null);+ const [large, setLarge] = useState(false);++ useLayoutEffect(() => {+ const el = containerRef.current;+ if (!el) {+ return;+ }++ const TARGET = 48; // standard bottom-nav touch target (px)+ const MIN_GAP = 8; // minimum spacing between targets (px)++ const compute = () => {+ const count = el.children.length;+ if (count === 0) {+ return;+ }+ const needed = count * TARGET + Math.max(count - 1, 0) * MIN_GAP;+ setLarge(needed <= el.clientWidth);+ };++ compute();++ const resize = new ResizeObserver(compute);+ resize.observe(el);+ // recompute when items are added/removed (e.g. the status alert appears)+ const mutation = new MutationObserver(compute);+ mutation.observe(el, { childList: true });++ return () => {+ resize.disconnect();+ mutation.disconnect();+ };+ }, [navItems]);+return (<div+ ref={containerRef}className={cn(- "absolute inset-x-4 bottom-0 flex h-16 flex-row justify-between",- isPWA && isIOS- ? "portrait:items-start portrait:pt-1 landscape:items-center"- : "items-center",- isMobile && !isPWA && "h-12 md:h-16",+ "absolute inset-x-4 bottom-0 flex h-16 flex-row items-center justify-between",+ isMobile &&+ (isPWA+ ? "h-[calc(3rem+env(safe-area-inset-bottom))] pb-[env(safe-area-inset-bottom)] md:h-[calc(4rem+env(safe-area-inset-bottom))]"+ : "h-12 md:h-16 md:pb-2"),)}>{navItems.map((item) => (- <NavItem key={item.id} className="p-2" item={item} Icon={item.icon} />+ <NavItem+ key={item.id}+ large={large}+ className="p-2"+ item={item}+ Icon={item.icon}+ />))}- <GeneralSettings className="p-2" />- <StatusAlertNav className="p-2" />+ <GeneralSettings large={large} className="p-2" />+ <StatusAlertNav large={large} className="p-2" /></div>);}type StatusAlertNavProps = {className?: string;+ large?: boolean;};-function StatusAlertNav({ className }: StatusAlertNavProps) {+function StatusAlertNav({ className, large }: StatusAlertNavProps) {const { t } = useTranslation(["views/system"]);const { data: initialStats } = useSWR<FrigateStats>("stats", {revalidateOnFocus: false,@@ -105,8 +158,18 @@ function StatusAlertNav({ className }: StatusAlertNavProps) {return (<Drawer><DrawerTrigger asChild>- <div className="p-2">- <IoIosWarning className="size-5 text-danger md:m-[6px]" />+ <div+ className={cn(+ "flex flex-col items-center justify-center p-2",+ large && "size-12",+ )}+ >+ <IoIosWarning+ className={cn(+ "text-danger md:m-[6px]",+ large ? "size-6" : "size-5",+ )}+ /></div></DrawerTrigger><DrawerContentdiff --git a/web/src/components/navigation/NavItem.tsx b/web/src/components/navigation/NavItem.tsxindex 204e7a9dd9..0d9e6632f0 100644--- a/web/src/components/navigation/NavItem.tsx+++ b/web/src/components/navigation/NavItem.tsx@@ -27,6 +27,7 @@ type NavItemProps = {item: NavData;Icon: IconType;onClick?: () => void;+ large?: boolean;};export default function NavItem({@@ -34,6 +35,7 @@ export default function NavItem({item,Icon,onClick,+ large,}: NavItemProps) {const { t } = useTranslation(["common"]);if (item.enabled == false) {@@ -48,11 +50,12 @@ export default function NavItem({cn("flex flex-col items-center justify-center rounded-lg p-[6px]",className,+ large && "size-12",variants[item.variant ?? "primary"][isActive ? "active" : "inactive"],)}>- <Icon className="size-5" />+ <Icon className={large ? "size-6" : "size-5"} /></NavLink>);diff --git a/web/src/components/ui/drawer.tsx b/web/src/components/ui/drawer.tsxindex 220708e7e2..af73e93e9d 100644--- a/web/src/components/ui/drawer.tsx+++ b/web/src/components/ui/drawer.tsx@@ -2,8 +2,6 @@ import * as React from "react";import { Drawer as DrawerPrimitive } from "vaul";import { cn } from "@/lib/utils";-import { isPWA } from "@/utils/isPWA";-import { isIOS } from "react-device-detect";const Drawer = ({shouldScaleBackground = true,@@ -43,10 +41,9 @@ const DrawerContent = React.forwardRef<<DrawerPrimitive.Contentref={ref}className={cn(- "fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background",+ "fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border border-b-0 bg-background",className,- isIOS && isPWA && "pb-5",- isIOS && !isPWA && "md:pb-5",+ "pb-[calc(0.25rem+env(safe-area-inset-bottom))]",)}{...props}>diff --git a/web/src/views/live/LiveDashboardView.tsx b/web/src/views/live/LiveDashboardView.tsxindex 629bf30b87..e935148151 100644--- a/web/src/views/live/LiveDashboardView.tsx+++ b/web/src/views/live/LiveDashboardView.tsx@@ -404,34 +404,38 @@ export default function LiveDashboardView({{isMobile && (<div className="relative flex h-11 items-center justify-between"><Logo className="absolute inset-x-1/2 h-8 -translate-x-1/2" />- <div className="max-w-[45%]">+ <div className="w-[45%]"><CameraGroupSelector /></div>{(!cameraGroup || cameraGroup == "default" || isMobileOnly) && (<div className="flex items-center gap-1"><Button- className={`p-1 ${+ className={mobileLayout == "grid"? "bg-blue-900 bg-opacity-60 focus:bg-blue-900 focus:bg-opacity-60": "bg-secondary"- }`}+ }aria-label="Use mobile grid layout"- size="xs"+ size="sm"onClick={() => setMobileLayout("grid")}>- <LiveGridIcon layout={mobileLayout} />+ <div className="size-5">+ <LiveGridIcon layout={mobileLayout} />+ </div></Button><Button- className={`p-1 ${+ className={mobileLayout == "list"? "bg-blue-900 bg-opacity-60 focus:bg-blue-900 focus:bg-opacity-60": "bg-secondary"- }`}+ }aria-label="Use mobile list layout"- size="xs"+ size="sm"onClick={() => setMobileLayout("list")}>- <LiveListIcon layout={mobileLayout} />+ <div className="size-5">+ <LiveListIcon layout={mobileLayout} />+ </div></Button></div>)}@@ -439,18 +443,21 @@ export default function LiveDashboardView({<div className="flex items-center gap-1"><ButtonclassName={cn(- "p-1",isEditMode? "bg-selected text-primary": "bg-secondary text-secondary-foreground",)}aria-label="Enter layout editing mode"- size="xs"+ size="sm"onClick={() =>setIsEditMode((prevIsEditMode) => !prevIsEditMode)}>- {isEditMode ? <IoClose /> : <LuLayoutDashboard />}+ {isEditMode ? (+ <IoClose className="size-5" />+ ) : (+ <LuLayoutDashboard className="size-5" />+ )}</Button></div>)}