Skip to content

Commit

Permalink
Allow customizing if search is preserved for overlay state
Browse files Browse the repository at this point in the history
  • Loading branch information
NickM-27 committed Dec 12, 2024
1 parent 9f0d29f commit 1a23fde
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion web/src/hooks/use-overlay-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { usePersistence } from "./use-persistence";
export function useOverlayState<S>(
key: string,
defaultValue: S | undefined = undefined,
preserveSearch: boolean = true,
): [S | undefined, (value: S, replace?: boolean) => void] {
const location = useLocation();
const navigate = useNavigate();
Expand All @@ -15,7 +16,7 @@ export function useOverlayState<S>(
(value: S, replace: boolean = false) => {
const newLocationState = { ...currentLocationState };
newLocationState[key] = value;
navigate(location.pathname + location.search, {
navigate(location.pathname + (preserveSearch ? location.search : ""), {
state: newLocationState,
replace,
});
Expand Down
33 changes: 19 additions & 14 deletions web/src/pages/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ export default function Events() {

const [showReviewed, setShowReviewed] = usePersistence("showReviewed", false);

const [recording, setRecording] =
useOverlayState<RecordingStartingPoint>("recording");
const [recording, setRecording] = useOverlayState<RecordingStartingPoint>(
"recording",
undefined,
false,
);

useSearchEffect("id", (reviewId: string) => {
axios
Expand All @@ -50,18 +53,20 @@ export default function Events() {
const startTime = resp.data.start_time - REVIEW_PADDING;
const date = new Date(startTime * 1000);

setReviewFilter({
after: getBeginningOfDayTimestamp(date),
before: getEndOfDayTimestamp(date),
});
setRecording(
{
camera: resp.data.camera,
startTime,
severity: resp.data.severity,
},
true,
);
setTimeout(() => {
setReviewFilter({
after: getBeginningOfDayTimestamp(date),
before: getEndOfDayTimestamp(date),
});
setRecording(
{
camera: resp.data.camera,
startTime,
severity: resp.data.severity,
},
true,
);
}, 100);
}
})
.catch(() => {});
Expand Down

0 comments on commit 1a23fde

Please sign in to comment.