File tree Expand file tree Collapse file tree 2 files changed +47
-2
lines changed Expand file tree Collapse file tree 2 files changed +47
-2
lines changed Original file line number Diff line number Diff line change 1
- import { useCallback , useMemo } from "react" ;
1
+ import { useCallback , useEffect , useMemo } from "react" ;
2
2
import { useLocation , useNavigate } from "react-router-dom" ;
3
3
import { usePersistence } from "./use-persistence" ;
4
4
@@ -91,3 +91,30 @@ export function useHashState<S extends string>(): [
91
91
92
92
return [ hash , setHash ] ;
93
93
}
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
+ }
Original file line number Diff line number Diff line change 1
1
import ActivityIndicator from "@/components/indicators/activity-indicator" ;
2
2
import useApiFilter from "@/hooks/use-api-filter" ;
3
3
import { useTimezone } from "@/hooks/use-date-utils" ;
4
- import { useOverlayState } from "@/hooks/use-overlay-state" ;
4
+ import { useOverlayState , useSearchEffect } from "@/hooks/use-overlay-state" ;
5
5
import { FrigateConfig } from "@/types/frigateConfig" ;
6
6
import { Preview } from "@/types/preview" ;
7
7
import { RecordingStartingPoint } from "@/types/record" ;
@@ -33,6 +33,24 @@ export default function Events() {
33
33
const [ recording , setRecording ] =
34
34
useOverlayState < RecordingStartingPoint > ( "recording" ) ;
35
35
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
+
36
54
const [ startTime , setStartTime ] = useState < number > ( ) ;
37
55
38
56
useEffect ( ( ) => {
You can’t perform that action at this time.
0 commit comments