mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-06-10 23:27:07 -04:00
* remove redundant per-view toasters in settings * add variants to standardize dialog footer button layouts * remove text-md this class name compiles to nothing in tailwind. we used to add it to prevent iOS from zooming when focusing on an input, but that is now solved via the viewport meta in index.html * make wizard footers consistent with dialog footers * consistent destructive button style remove text-white from individual buttons and add it to the variant
99 lines
2.4 KiB
TypeScript
99 lines
2.4 KiB
TypeScript
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogFooter,
|
|
DialogDescription,
|
|
} from "@/components/ui/dialog";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { Input } from "@/components/ui/input";
|
|
import { useMemo, useState } from "react";
|
|
import { isMobile } from "react-device-detect";
|
|
import { toast } from "sonner";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
type SaveSearchDialogProps = {
|
|
existingNames: string[];
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
onSave: (name: string) => void;
|
|
};
|
|
|
|
export function SaveSearchDialog({
|
|
existingNames,
|
|
isOpen,
|
|
onClose,
|
|
onSave,
|
|
}: SaveSearchDialogProps) {
|
|
const { t } = useTranslation(["components/dialog"]);
|
|
|
|
const [searchName, setSearchName] = useState("");
|
|
|
|
const handleSave = () => {
|
|
if (searchName.trim()) {
|
|
onSave(searchName.trim());
|
|
setSearchName("");
|
|
toast.success(
|
|
t("search.saveSearch.success", {
|
|
searchName: searchName.trim(),
|
|
}),
|
|
{
|
|
position: "top-center",
|
|
},
|
|
);
|
|
onClose();
|
|
}
|
|
};
|
|
|
|
const overwrite = useMemo(
|
|
() => existingNames.includes(searchName),
|
|
[existingNames, searchName],
|
|
);
|
|
|
|
return (
|
|
<Dialog open={isOpen} onOpenChange={onClose}>
|
|
<DialogContent
|
|
onOpenAutoFocus={(e) => {
|
|
if (isMobile) {
|
|
e.preventDefault();
|
|
}
|
|
}}
|
|
>
|
|
<DialogHeader>
|
|
<DialogTitle>{t("search.saveSearch.label")}</DialogTitle>
|
|
<DialogDescription className="sr-only">
|
|
{t("search.saveSearch.desc")}
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<Input
|
|
value={searchName}
|
|
onChange={(e) => setSearchName(e.target.value)}
|
|
placeholder={t("search.saveSearch.placeholder")}
|
|
/>
|
|
{overwrite && (
|
|
<div className="ml-1 text-sm text-danger">
|
|
{t("search.saveSearch.overwrite", { searchName })}
|
|
</div>
|
|
)}
|
|
<DialogFooter>
|
|
<Button
|
|
aria-label={t("button.cancel", { ns: "common" })}
|
|
onClick={onClose}
|
|
>
|
|
{t("button.cancel", { ns: "common" })}
|
|
</Button>
|
|
<Button
|
|
onClick={handleSave}
|
|
variant="select"
|
|
aria-label={t("search.saveSearch.button.save.label")}
|
|
>
|
|
{t("button.save", { ns: "common" })}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|