mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Cleanup overlay state with types and use overlay for severity (#10299)
This commit is contained in:
parent
3d90f50d84
commit
ccb5e05e3e
@ -1,15 +1,16 @@
|
|||||||
import { useCallback, useMemo } from "react";
|
import { useCallback, useMemo } from "react";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
export default function useOverlayState(
|
export default function useOverlayState<S extends string>(
|
||||||
key: string,
|
key: string,
|
||||||
): [string | undefined, (value: string, replace?: boolean) => void] {
|
defaultValue: S | undefined = undefined,
|
||||||
|
): [S | undefined, (value: S, replace?: boolean) => void] {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const currentLocationState = location.state;
|
const currentLocationState = location.state;
|
||||||
|
|
||||||
const setOverlayStateValue = useCallback(
|
const setOverlayStateValue = useCallback(
|
||||||
(value: string, replace: boolean = false) => {
|
(value: S, replace: boolean = false) => {
|
||||||
const newLocationState = { ...currentLocationState };
|
const newLocationState = { ...currentLocationState };
|
||||||
newLocationState[key] = value;
|
newLocationState[key] = value;
|
||||||
navigate(location.pathname, { state: newLocationState, replace });
|
navigate(location.pathname, { state: newLocationState, replace });
|
||||||
@ -19,10 +20,10 @@ export default function useOverlayState(
|
|||||||
[key, navigate],
|
[key, navigate],
|
||||||
);
|
);
|
||||||
|
|
||||||
const overlayStateValue = useMemo<string | undefined>(
|
const overlayStateValue = useMemo<S | undefined>(
|
||||||
() => location.state && location.state[key],
|
() => location.state && location.state[key],
|
||||||
[location, key],
|
[location, key],
|
||||||
);
|
);
|
||||||
|
|
||||||
return [overlayStateValue, setOverlayStateValue];
|
return [overlayStateValue ?? defaultValue, setOverlayStateValue];
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,10 @@ export default function Events() {
|
|||||||
|
|
||||||
// recordings viewer
|
// recordings viewer
|
||||||
|
|
||||||
const [severity, setSeverity] = useState<ReviewSeverity>("alert");
|
const [severity, setSeverity] = useOverlayState<ReviewSeverity>(
|
||||||
|
"severity",
|
||||||
|
"alert",
|
||||||
|
);
|
||||||
const [selectedReviewId, setSelectedReviewId] = useOverlayState("review");
|
const [selectedReviewId, setSelectedReviewId] = useOverlayState("review");
|
||||||
|
|
||||||
// review filter
|
// review filter
|
||||||
@ -339,7 +342,7 @@ export default function Events() {
|
|||||||
reachedEnd={isDone}
|
reachedEnd={isDone}
|
||||||
isValidating={isValidating}
|
isValidating={isValidating}
|
||||||
filter={reviewFilter}
|
filter={reviewFilter}
|
||||||
severity={severity}
|
severity={severity ?? "alert"}
|
||||||
setSeverity={setSeverity}
|
setSeverity={setSeverity}
|
||||||
loadNextPage={onLoadNextPage}
|
loadNextPage={onLoadNextPage}
|
||||||
markItemAsReviewed={markItemAsReviewed}
|
markItemAsReviewed={markItemAsReviewed}
|
||||||
|
Loading…
Reference in New Issue
Block a user