mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-20 13:54:36 +01:00
Miscellaneous Fixes (#21050)
* Don't add to history when opening search dialog * Update caniuse * Revamp the history handling for dialog components * clarify audio transcription docs * Use titlecase helper * Allow running object clasasification on stationary objects * small spacing tweaks for tablets * require admin role to delete users * explicitly prevent deletion of admin user --------- Co-authored-by: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>
This commit is contained in:
57
web/src/hooks/use-history-back.ts
Normal file
57
web/src/hooks/use-history-back.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import * as React from "react";
|
||||
|
||||
interface UseHistoryBackOptions {
|
||||
enabled: boolean;
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook that manages browser history for overlay components (dialogs, sheets, etc.)
|
||||
* When enabled, pressing the browser back button will close the overlay instead of navigating away.
|
||||
*/
|
||||
export function useHistoryBack({
|
||||
enabled,
|
||||
open,
|
||||
onClose,
|
||||
}: UseHistoryBackOptions): void {
|
||||
const historyPushedRef = React.useRef(false);
|
||||
const closedByBackRef = React.useRef(false);
|
||||
|
||||
// Keep onClose in a ref to avoid effect re-runs that cause multiple history pushes
|
||||
const onCloseRef = React.useRef(onClose);
|
||||
React.useLayoutEffect(() => {
|
||||
onCloseRef.current = onClose;
|
||||
});
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!enabled) return;
|
||||
|
||||
if (open) {
|
||||
// Only push history state if we haven't already (prevents duplicates in strict mode)
|
||||
if (!historyPushedRef.current) {
|
||||
window.history.pushState({ overlayOpen: true }, "");
|
||||
historyPushedRef.current = true;
|
||||
}
|
||||
|
||||
const handlePopState = () => {
|
||||
closedByBackRef.current = true;
|
||||
historyPushedRef.current = false;
|
||||
onCloseRef.current();
|
||||
};
|
||||
|
||||
window.addEventListener("popstate", handlePopState);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("popstate", handlePopState);
|
||||
};
|
||||
} else {
|
||||
// Overlay is closing - clean up history if we pushed and it wasn't via back button
|
||||
if (historyPushedRef.current && !closedByBackRef.current) {
|
||||
window.history.back();
|
||||
}
|
||||
historyPushedRef.current = false;
|
||||
closedByBackRef.current = false;
|
||||
}
|
||||
}, [enabled, open]);
|
||||
}
|
||||
Reference in New Issue
Block a user