Skip to content

Commit 1538743

Browse files
committed
Pull id search key and open recordings to review item
1 parent e5309ba commit 1538743

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

web/src/hooks/use-overlay-state.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useMemo } from "react";
1+
import { useCallback, useEffect, useMemo } from "react";
22
import { useLocation, useNavigate } from "react-router-dom";
33
import { usePersistence } from "./use-persistence";
44

@@ -91,3 +91,30 @@ export function useHashState<S extends string>(): [
9191

9292
return [hash, setHash];
9393
}
94+
95+
export function useSearchEffect(
96+
key: string,
97+
callback: (value: string) => void,
98+
) {
99+
const location = useLocation();
100+
101+
const param = useMemo(() => {
102+
if (!location || !location.search || location.search.length == 0) {
103+
return undefined;
104+
}
105+
106+
const params = location.search.substring(1).split("&");
107+
108+
return params
109+
.find((p) => p.includes("=") && p.split("=")[0] == key)
110+
?.split("=");
111+
}, [location, key]);
112+
113+
useEffect(() => {
114+
if (!param) {
115+
return;
116+
}
117+
118+
callback(param[1]);
119+
}, [param, callback]);
120+
}

web/src/pages/Events.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ActivityIndicator from "@/components/indicators/activity-indicator";
22
import useApiFilter from "@/hooks/use-api-filter";
33
import { useTimezone } from "@/hooks/use-date-utils";
4-
import { useOverlayState } from "@/hooks/use-overlay-state";
4+
import { useOverlayState, useSearchEffect } from "@/hooks/use-overlay-state";
55
import { FrigateConfig } from "@/types/frigateConfig";
66
import { Preview } from "@/types/preview";
77
import { RecordingStartingPoint } from "@/types/record";
@@ -33,6 +33,24 @@ export default function Events() {
3333
const [recording, setRecording] =
3434
useOverlayState<RecordingStartingPoint>("recording");
3535

36+
useSearchEffect("id", (reviewId: string) => {
37+
axios
38+
.get(`review/${reviewId}`)
39+
.then((resp) => {
40+
if (resp.status == 200 && resp.data) {
41+
setRecording(
42+
{
43+
camera: resp.data.camera,
44+
startTime: resp.data.start_time,
45+
severity: resp.data.severity,
46+
},
47+
true,
48+
);
49+
}
50+
})
51+
.catch(() => {});
52+
});
53+
3654
const [startTime, setStartTime] = useState<number>();
3755

3856
useEffect(() => {

0 commit comments

Comments
 (0)