Allow customizing if search is preserved for overlay state

This commit is contained in:
Nicolas Mowen 2024-12-12 06:26:04 -07:00
parent 9f0d29feab
commit 1a23fdeff2
2 changed files with 21 additions and 15 deletions

View File

@ -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();
@ -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,
});

View File

@ -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
@ -50,6 +53,7 @@ export default function Events() {
const startTime = resp.data.start_time - REVIEW_PADDING;
const date = new Date(startTime * 1000);
setTimeout(() => {
setReviewFilter({
after: getBeginningOfDayTimestamp(date),
before: getEndOfDayTimestamp(date),
@ -62,6 +66,7 @@ export default function Events() {
},
true,
);
}, 100);
}
})
.catch(() => {});