mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-07-23 20:29:02 +03:00
Miscellaneous Fixes (#21050)
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
CI / AMD64 Build (push) Waiting to run
CI / Synaptics Build (push) Blocked by required conditions
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
CI / AMD64 Build (push) Waiting to run
CI / Synaptics Build (push) Blocked by required conditions
* 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:
co-authored by
Josh Hawkins
parent
e79ff9a079
commit
de2144f158
@@ -2,6 +2,7 @@ import * as React from "react";
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||
import { X } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useHistoryBack } from "@/hooks/use-history-back";
|
||||
|
||||
// Enhanced Dialog with History Support
|
||||
interface HistoryDialogProps extends DialogPrimitive.DialogProps {
|
||||
@@ -15,51 +16,28 @@ const Dialog = ({
|
||||
...props
|
||||
}: HistoryDialogProps) => {
|
||||
const [internalOpen, setInternalOpen] = React.useState(open || false);
|
||||
const historyStateRef = React.useRef<null | {
|
||||
listener: (e: PopStateEvent) => void;
|
||||
}>(null);
|
||||
|
||||
// Sync internal state with controlled open prop
|
||||
React.useEffect(() => {
|
||||
if (open !== undefined) {
|
||||
setInternalOpen(open);
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (enableHistoryBack) {
|
||||
if (internalOpen) {
|
||||
window.history.pushState({ dialogOpen: true }, "");
|
||||
const handleOpenChange = React.useCallback(
|
||||
(newOpen: boolean) => {
|
||||
setInternalOpen(newOpen);
|
||||
onOpenChange?.(newOpen);
|
||||
},
|
||||
[onOpenChange],
|
||||
);
|
||||
|
||||
const listener = () => {
|
||||
setInternalOpen(false);
|
||||
if (onOpenChange) onOpenChange(false);
|
||||
};
|
||||
|
||||
historyStateRef.current = { listener };
|
||||
window.addEventListener("popstate", listener);
|
||||
|
||||
return () => {
|
||||
if (internalOpen) {
|
||||
window.removeEventListener("popstate", listener);
|
||||
historyStateRef.current = null;
|
||||
}
|
||||
};
|
||||
} else if (historyStateRef.current) {
|
||||
window.removeEventListener(
|
||||
"popstate",
|
||||
historyStateRef.current.listener,
|
||||
);
|
||||
historyStateRef.current = null;
|
||||
}
|
||||
}
|
||||
}, [enableHistoryBack, internalOpen, onOpenChange]);
|
||||
|
||||
const handleOpenChange = (open: boolean) => {
|
||||
setInternalOpen(open);
|
||||
if (onOpenChange) {
|
||||
onOpenChange(open);
|
||||
}
|
||||
};
|
||||
// Handle browser back button to close dialog
|
||||
useHistoryBack({
|
||||
enabled: enableHistoryBack,
|
||||
open: internalOpen,
|
||||
onClose: () => handleOpenChange(false),
|
||||
});
|
||||
|
||||
return (
|
||||
<DialogPrimitive.Root
|
||||
|
||||
@@ -4,6 +4,7 @@ import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { X } from "lucide-react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useHistoryBack } from "@/hooks/use-history-back";
|
||||
|
||||
// Enhanced Sheet with History Support
|
||||
interface HistorySheetProps extends SheetPrimitive.DialogProps {
|
||||
@@ -17,51 +18,28 @@ const Sheet = ({
|
||||
...props
|
||||
}: HistorySheetProps) => {
|
||||
const [internalOpen, setInternalOpen] = React.useState(open || false);
|
||||
const historyStateRef = React.useRef<null | {
|
||||
listener: (e: PopStateEvent) => void;
|
||||
}>(null);
|
||||
|
||||
// Sync internal state with controlled open prop
|
||||
React.useEffect(() => {
|
||||
if (open !== undefined) {
|
||||
setInternalOpen(open);
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (enableHistoryBack) {
|
||||
if (internalOpen) {
|
||||
window.history.pushState({ sheetOpen: true }, "");
|
||||
const handleOpenChange = React.useCallback(
|
||||
(newOpen: boolean) => {
|
||||
setInternalOpen(newOpen);
|
||||
onOpenChange?.(newOpen);
|
||||
},
|
||||
[onOpenChange],
|
||||
);
|
||||
|
||||
const listener = () => {
|
||||
setInternalOpen(false);
|
||||
if (onOpenChange) onOpenChange(false);
|
||||
};
|
||||
|
||||
historyStateRef.current = { listener };
|
||||
window.addEventListener("popstate", listener);
|
||||
|
||||
return () => {
|
||||
if (internalOpen) {
|
||||
window.removeEventListener("popstate", listener);
|
||||
historyStateRef.current = null;
|
||||
}
|
||||
};
|
||||
} else if (historyStateRef.current) {
|
||||
window.removeEventListener(
|
||||
"popstate",
|
||||
historyStateRef.current.listener,
|
||||
);
|
||||
historyStateRef.current = null;
|
||||
}
|
||||
}
|
||||
}, [enableHistoryBack, internalOpen, onOpenChange]);
|
||||
|
||||
const handleOpenChange = (open: boolean) => {
|
||||
setInternalOpen(open);
|
||||
if (onOpenChange) {
|
||||
onOpenChange(open);
|
||||
}
|
||||
};
|
||||
// Handle browser back button to close sheet
|
||||
useHistoryBack({
|
||||
enabled: enableHistoryBack,
|
||||
open: internalOpen,
|
||||
onClose: () => handleOpenChange(false),
|
||||
});
|
||||
|
||||
return (
|
||||
<SheetPrimitive.Root
|
||||
|
||||
Reference in New Issue
Block a user