Compare commits

..

No commits in common. "10ced9195d4ce39ab663912d07eafc196c2d7944" and "6fa64a8db3702e7dbce86917444e2ee77b46a3f5" have entirely different histories.

8 changed files with 65 additions and 164 deletions

View File

@ -131,6 +131,8 @@
"close": "Close", "close": "Close",
"copy": "Copy", "copy": "Copy",
"copiedToClipboard": "Copied to clipboard", "copiedToClipboard": "Copied to clipboard",
"shareTimestamp": "Share Timestamp",
"shareTimestampUrl": "Share Timestamp URL",
"back": "Back", "back": "Back",
"history": "History", "history": "History",
"fullscreen": "Fullscreen", "fullscreen": "Fullscreen",

View File

@ -100,13 +100,11 @@
}, },
"recording": { "recording": {
"shareTimestamp": { "shareTimestamp": {
"label": "Share Timestamp",
"title": "Share Review Timestamp", "title": "Share Review Timestamp",
"description": "Share a timestamped URL of current player position or choose a custom timestamp. Note that this is not a public share URL and is only accessible to users with access to Frigate and this camera.", "description": "Share the current player position or choose a custom timestamp.",
"current": "Current Player Timestamp", "current": "Current Player Timestamp",
"custom": "Custom Timestamp", "custom": "Custom Timestamp",
"customDescription": "Pick a specific point in time to share.", "customDescription": "Pick a specific point in time to share.",
"button": "Share Timestamp URL",
"shareTitle": "Frigate Review Timestamp: {{camera}}" "shareTitle": "Frigate Review Timestamp: {{camera}}"
}, },
"confirmDelete": { "confirmDelete": {

View File

@ -40,7 +40,7 @@ export default function ActionsDropdown({
{t("menu.export", { ns: "common" })} {t("menu.export", { ns: "common" })}
</DropdownMenuItem> </DropdownMenuItem>
<DropdownMenuItem onClick={onShareTimestampClick}> <DropdownMenuItem onClick={onShareTimestampClick}>
{t("recording.shareTimestamp.label", { ns: "components/dialog" })} {t("button.shareTimestamp", { ns: "common" })}
</DropdownMenuItem> </DropdownMenuItem>
<DropdownMenuItem onClick={onDebugReplayClick}> <DropdownMenuItem onClick={onDebugReplayClick}>
{t("title", { ns: "views/replay" })} {t("title", { ns: "views/replay" })}

View File

@ -26,7 +26,6 @@ import SaveExportOverlay from "./SaveExportOverlay";
import { isIOS, isMobile } from "react-device-detect"; import { isIOS, isMobile } from "react-device-detect";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { ShareTimestampContent } from "./ShareTimestampDialog";
type DrawerMode = type DrawerMode =
| "none" | "none"
@ -71,7 +70,7 @@ type MobileReviewSettingsDrawerProps = {
debugReplayRange?: TimeRange; debugReplayRange?: TimeRange;
setDebugReplayMode?: (mode: ExportMode) => void; setDebugReplayMode?: (mode: ExportMode) => void;
setDebugReplayRange?: (range: TimeRange | undefined) => void; setDebugReplayRange?: (range: TimeRange | undefined) => void;
onShareTimestamp?: (timestamp: number) => void; onShareTimestampClick?: () => void;
onUpdateFilter: (filter: ReviewFilter) => void; onUpdateFilter: (filter: ReviewFilter) => void;
setRange: (range: TimeRange | undefined) => void; setRange: (range: TimeRange | undefined) => void;
setMode: (mode: ExportMode) => void; setMode: (mode: ExportMode) => void;
@ -95,7 +94,7 @@ export default function MobileReviewSettingsDrawer({
debugReplayRange, debugReplayRange,
setDebugReplayMode = () => {}, setDebugReplayMode = () => {},
setDebugReplayRange = () => {}, setDebugReplayRange = () => {},
onShareTimestamp = () => {}, onShareTimestampClick = () => {},
onUpdateFilter, onUpdateFilter,
setRange, setRange,
setMode, setMode,
@ -113,15 +112,6 @@ export default function MobileReviewSettingsDrawer({
"1" | "5" | "custom" | "timeline" "1" | "5" | "custom" | "timeline"
>("1"); >("1");
const [isDebugReplayStarting, setIsDebugReplayStarting] = useState(false); const [isDebugReplayStarting, setIsDebugReplayStarting] = useState(false);
const [selectedShareOption, setSelectedShareOption] = useState<
"current" | "custom"
>("current");
const [shareTimestampAtOpen, setShareTimestampAtOpen] = useState(
Math.floor(currentTime),
);
const [customShareTimestamp, setCustomShareTimestamp] = useState(
Math.floor(currentTime),
);
// exports // exports
@ -294,22 +284,14 @@ export default function MobileReviewSettingsDrawer({
{features.includes("share-timestamp") && ( {features.includes("share-timestamp") && (
<Button <Button
className="flex w-full items-center justify-center gap-2" className="flex w-full items-center justify-center gap-2"
aria-label={t("recording.shareTimestamp.label", { aria-label={t("button.shareTimestamp", { ns: "common" })}
ns: "components/dialog",
})}
onClick={() => { onClick={() => {
const initialTimestamp = Math.floor(currentTime); setDrawerMode("none");
onShareTimestampClick();
setShareTimestampAtOpen(initialTimestamp);
setCustomShareTimestamp(initialTimestamp);
setSelectedShareOption("current");
setDrawerMode("share-timestamp");
}} }}
> >
<LuShare2 className="size-5 rounded-md bg-secondary-foreground stroke-secondary p-1" /> <LuShare2 className="size-5 rounded-md bg-secondary-foreground stroke-secondary p-1" />
{t("recording.shareTimestamp.label", { {t("button.shareTimestamp", { ns: "common" })}
ns: "components/dialog",
})}
</Button> </Button>
)} )}
{features.includes("calendar") && ( {features.includes("calendar") && (
@ -514,34 +496,6 @@ export default function MobileReviewSettingsDrawer({
}} }}
/> />
); );
} else if (drawerMode == "share-timestamp") {
content = (
<div className="w-full">
<div className="relative h-8 w-full">
<div
className="absolute left-0 text-selected"
onClick={() => setDrawerMode("select")}
>
{t("button.back", { ns: "common" })}
</div>
<div className="absolute left-1/2 -translate-x-1/2 text-muted-foreground">
{t("recording.shareTimestamp.title", { ns: "components/dialog" })}
</div>
</div>
<ShareTimestampContent
currentTime={shareTimestampAtOpen}
selectedOption={selectedShareOption}
setSelectedOption={setSelectedShareOption}
customTimestamp={customShareTimestamp}
setCustomTimestamp={setCustomShareTimestamp}
onShareTimestamp={(timestamp) => {
onShareTimestamp(timestamp);
setDrawerMode("none");
}}
onCancel={() => setDrawerMode("select")}
/>
</div>
);
} }
return ( return (

View File

@ -3,7 +3,6 @@ import {
Dialog, Dialog,
DialogContent, DialogContent,
DialogDescription, DialogDescription,
DialogFooter,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@/components/ui/dialog"; } from "@/components/ui/dialog";
@ -15,9 +14,7 @@ import {
PopoverTrigger, PopoverTrigger,
} from "@/components/ui/popover"; } from "@/components/ui/popover";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { Separator } from "@/components/ui/separator";
import { useFormattedTimestamp } from "@/hooks/use-date-utils"; import { useFormattedTimestamp } from "@/hooks/use-date-utils";
import { cn } from "@/lib/utils";
import { FrigateConfig } from "@/types/frigateConfig"; import { FrigateConfig } from "@/types/frigateConfig";
import { getUTCOffset } from "@/utils/dateUtil"; import { getUTCOffset } from "@/utils/dateUtil";
import { useCallback, useMemo, useState } from "react"; import { useCallback, useMemo, useState } from "react";
@ -25,16 +22,13 @@ import useSWR from "swr";
import { TimezoneAwareCalendar } from "./ReviewActivityCalendar"; import { TimezoneAwareCalendar } from "./ReviewActivityCalendar";
import { FaCalendarAlt } from "react-icons/fa"; import { FaCalendarAlt } from "react-icons/fa";
import { isDesktop, isIOS, isMobile } from "react-device-detect"; import { isDesktop, isIOS, isMobile } from "react-device-detect";
import { LuShare2 } from "react-icons/lu";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
type ShareTimestampDialogProps = { type ShareTimestampDialogProps = {
currentTime: number; currentTime: number;
open: boolean; open: boolean;
onOpenChange: (open: boolean) => void; onOpenChange: (open: boolean) => void;
selectedOption: "current" | "custom";
setSelectedOption: (option: "current" | "custom") => void;
customTimestamp: number;
setCustomTimestamp: (timestamp: number) => void;
onShareTimestamp: (timestamp: number) => void; onShareTimestamp: (timestamp: number) => void;
}; };
@ -42,17 +36,26 @@ export default function ShareTimestampDialog({
currentTime, currentTime,
open, open,
onOpenChange, onOpenChange,
selectedOption,
setSelectedOption,
customTimestamp,
setCustomTimestamp,
onShareTimestamp, onShareTimestamp,
}: Readonly<ShareTimestampDialogProps>) { }: Readonly<ShareTimestampDialogProps>) {
const { t } = useTranslation(["components/dialog"]); const { t } = useTranslation(["components/dialog"]);
const [selectedOption, setSelectedOption] = useState<"current" | "custom">(
"current",
);
const [customTimestamp, setCustomTimestamp] = useState(
Math.floor(currentTime),
);
const handleOpenChange = useCallback( const handleOpenChange = useCallback(
(nextOpen: boolean) => onOpenChange(nextOpen), (nextOpen: boolean) => {
[onOpenChange], if (nextOpen) {
setSelectedOption("current");
setCustomTimestamp(Math.floor(currentTime));
}
onOpenChange(nextOpen);
},
[currentTime, onOpenChange],
); );
const content = ( const content = (
@ -66,7 +69,6 @@ export default function ShareTimestampDialog({
onShareTimestamp(timestamp); onShareTimestamp(timestamp);
onOpenChange(false); onOpenChange(false);
}} }}
onCancel={() => onOpenChange(false)}
/> />
); );
@ -106,17 +108,15 @@ type ShareTimestampContentProps = {
customTimestamp: number; customTimestamp: number;
setCustomTimestamp: (timestamp: number) => void; setCustomTimestamp: (timestamp: number) => void;
onShareTimestamp: (timestamp: number) => void; onShareTimestamp: (timestamp: number) => void;
onCancel?: () => void;
}; };
export function ShareTimestampContent({ function ShareTimestampContent({
currentTime, currentTime,
selectedOption, selectedOption,
setSelectedOption, setSelectedOption,
customTimestamp, customTimestamp,
setCustomTimestamp, setCustomTimestamp,
onShareTimestamp, onShareTimestamp,
onCancel,
}: Readonly<ShareTimestampContentProps>) { }: Readonly<ShareTimestampContentProps>) {
const { t } = useTranslation(["common", "components/dialog"]); const { t } = useTranslation(["common", "components/dialog"]);
const { data: config } = useSWR<FrigateConfig>("config"); const { data: config } = useSWR<FrigateConfig>("config");
@ -140,8 +140,6 @@ export function ShareTimestampContent({
</div> </div>
</div> </div>
{isDesktop && <Separator className="my-4 bg-secondary" />}
<RadioGroup <RadioGroup
className="mt-4 flex flex-col gap-4" className="mt-4 flex flex-col gap-4"
value={selectedOption} value={selectedOption}
@ -193,32 +191,16 @@ export function ShareTimestampContent({
</div> </div>
</RadioGroup> </RadioGroup>
{isDesktop && <Separator className="my-4 bg-secondary" />} <div className="mt-4">
<DialogFooter
className={cn("mt-4", !isDesktop && "flex flex-col-reverse gap-4")}
>
{onCancel && (
<Button <Button
type="button" className="w-full justify-between gap-3"
className={cn(
"cursor-pointer p-2 text-center",
!isDesktop && "w-full",
)}
onClick={onCancel}
>
{t("button.cancel", { ns: "common" })}
</Button>
)}
<Button
className={cn(!isDesktop && "w-full")}
variant="select" variant="select"
size="sm"
onClick={() => onShareTimestamp(Math.floor(selectedTimestamp))} onClick={() => onShareTimestamp(Math.floor(selectedTimestamp))}
> >
{t("recording.shareTimestamp.button", { ns: "components/dialog" })} <span>{t("button.shareTimestampUrl", { ns: "common" })}</span>
<LuShare2 className="size-4" />
</Button> </Button>
</DialogFooter> </div>
</div> </div>
); );
} }
@ -293,10 +275,7 @@ function CustomTimestampSelector({
return ( return (
<div <div
className={cn( className={`flex items-center rounded-lg bg-secondary text-secondary-foreground ${isDesktop ? "gap-2 px-2" : "pl-2"}`}
"flex items-center rounded-lg bg-secondary text-secondary-foreground",
isDesktop ? "gap-2 px-2" : "pl-2",
)}
> >
<FaCalendarAlt /> <FaCalendarAlt />
<div className="flex flex-wrap items-center"> <div className="flex flex-wrap items-center">
@ -310,7 +289,7 @@ function CustomTimestampSelector({
> >
<PopoverTrigger asChild> <PopoverTrigger asChild>
<Button <Button
className={cn("text-primary", !isDesktop && "text-xs")} className={`text-primary ${isDesktop ? "" : "text-xs"}`}
aria-label={label} aria-label={label}
variant={selectorOpen ? "select" : "default"} variant={selectorOpen ? "select" : "default"}
size="sm" size="sm"
@ -319,7 +298,7 @@ function CustomTimestampSelector({
{formattedTimestamp} {formattedTimestamp}
</Button> </Button>
</PopoverTrigger> </PopoverTrigger>
<PopoverContent className="flex flex-col items-center"> <PopoverContent className="flex flex-col items-center" disablePortal>
<TimezoneAwareCalendar <TimezoneAwareCalendar
timezone={config?.ui.timezone} timezone={config?.ui.timezone}
selectedDay={new Date(displayTimestamp * 1000)} selectedDay={new Date(displayTimestamp * 1000)}

View File

@ -272,7 +272,6 @@ export default function Events() {
...reviewFilter, ...reviewFilter,
...getReviewDayBounds(new Date(reviewLink.timestamp * 1000)), ...getReviewDayBounds(new Date(reviewLink.timestamp * 1000)),
}); });
globalThis.setTimeout(() => {
setRecording( setRecording(
{ {
camera: reviewLink.camera, camera: reviewLink.camera,
@ -284,9 +283,8 @@ export default function Events() {
}, },
true, true,
); );
}, 0);
return true; return false;
}); });
// review paging // review paging

View File

@ -1,5 +1,3 @@
import { baseUrl } from "@/api/baseUrl.ts";
export const RECORDING_REVIEW_LINK_PARAM = "timestamp"; export const RECORDING_REVIEW_LINK_PARAM = "timestamp";
export type RecordingReviewLinkState = { export type RecordingReviewLinkState = {
@ -14,30 +12,21 @@ export function parseRecordingReviewLink(
return undefined; return undefined;
} }
const separatorIndex = value.lastIndexOf("_"); const [camera, timestamp] = value.split("|");
if (separatorIndex <= 0 || separatorIndex == value.length - 1) {
return undefined;
}
const camera = value.slice(0, separatorIndex);
const timestamp = value.slice(separatorIndex + 1);
if (!camera || !timestamp) { if (!camera || !timestamp) {
return undefined; return undefined;
} }
const parsedTimestamp = Number(timestamp); const parsedTimestamp = Number(timestamp);
const now = Math.floor(Date.now() / 1000);
if (!Number.isFinite(parsedTimestamp) || parsedTimestamp <= 0) { if (!Number.isFinite(parsedTimestamp)) {
return undefined; return undefined;
} }
return { return {
camera, camera,
// clamp future timestamps to now timestamp: Math.floor(parsedTimestamp),
timestamp: Math.min(Math.floor(parsedTimestamp), now),
}; };
} }
@ -45,12 +34,11 @@ export function createRecordingReviewUrl(
pathname: string, pathname: string,
state: RecordingReviewLinkState, state: RecordingReviewLinkState,
): string { ): string {
const url = new URL(baseUrl); const url = new URL(globalThis.location.href);
url.pathname = pathname.startsWith("/") ? pathname : `/${pathname}`; const normalizedPathname = pathname.startsWith("/")
url.searchParams.set( ? pathname
RECORDING_REVIEW_LINK_PARAM, : `/${pathname}`;
`${state.camera}_${Math.floor(state.timestamp)}`, const reviewLink = `${state.camera}|${Math.floor(state.timestamp)}`;
);
return url.toString(); return `${url.origin}${normalizedPathname}?${RECORDING_REVIEW_LINK_PARAM}=${reviewLink}`;
} }

View File

@ -210,15 +210,6 @@ export function RecordingView({
const [debugReplayMode, setDebugReplayMode] = useState<ExportMode>("none"); const [debugReplayMode, setDebugReplayMode] = useState<ExportMode>("none");
const [debugReplayRange, setDebugReplayRange] = useState<TimeRange>(); const [debugReplayRange, setDebugReplayRange] = useState<TimeRange>();
const [shareTimestampOpen, setShareTimestampOpen] = useState(false); const [shareTimestampOpen, setShareTimestampOpen] = useState(false);
const [shareTimestampAtOpen, setShareTimestampAtOpen] = useState(
Math.floor(startTime),
);
const [shareTimestampOption, setShareTimestampOption] = useState<
"current" | "custom"
>("current");
const [customShareTimestamp, setCustomShareTimestamp] = useState(
Math.floor(startTime),
);
// move to next clip // move to next clip
@ -695,26 +686,15 @@ export function RecordingView({
setMotionOnly={() => {}} setMotionOnly={() => {}}
/> />
)} )}
{isDesktop && (
<ShareTimestampDialog <ShareTimestampDialog
currentTime={shareTimestampAtOpen} currentTime={currentTime}
open={shareTimestampOpen} open={shareTimestampOpen}
onOpenChange={setShareTimestampOpen} onOpenChange={setShareTimestampOpen}
selectedOption={shareTimestampOption}
setSelectedOption={setShareTimestampOption}
customTimestamp={customShareTimestamp}
setCustomTimestamp={setCustomShareTimestamp}
onShareTimestamp={onShareReviewLink} onShareTimestamp={onShareReviewLink}
/> />
)}
{isDesktop && ( {isDesktop && (
<ActionsDropdown <ActionsDropdown
onShareTimestampClick={() => { onShareTimestampClick={() => {
const initialTimestamp = Math.floor(currentTime);
setShareTimestampAtOpen(initialTimestamp);
setShareTimestampOption("current");
setCustomShareTimestamp(initialTimestamp);
setShareTimestampOpen(true); setShareTimestampOpen(true);
}} }}
onDebugReplayClick={() => { onDebugReplayClick={() => {
@ -796,7 +776,9 @@ export function RecordingView({
mainControllerRef.current?.pause(); mainControllerRef.current?.pause();
} }
}} }}
onShareTimestamp={onShareReviewLink} onShareTimestampClick={() => {
setShareTimestampOpen(true);
}}
onUpdateFilter={updateFilter} onUpdateFilter={updateFilter}
setRange={setExportRange} setRange={setExportRange}
setMode={setExportMode} setMode={setExportMode}