import { t } from "@lingui/core/macro" import { Trans } from "@lingui/react/macro" import { memo, useMemo, useState } from "react" import { useStore } from "@nanostores/react" import { $alerts } from "@/lib/stores" import { Dialog, DialogTrigger, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { BellIcon, GlobeIcon, ServerIcon } from "lucide-react" import { alertInfo, cn } from "@/lib/utils" import { Button } from "@/components/ui/button" import { AlertRecord, SystemRecord } from "@/types" import { $router, Link } from "../router" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import { Checkbox } from "../ui/checkbox" import { SystemAlert, SystemAlertGlobal } from "./alerts-system" import { getPagePath } from "@nanostores/router" export default memo(function AlertsButton({ system }: { system: SystemRecord }) { const alerts = useStore($alerts) const [opened, setOpened] = useState(false) const hasAlert = alerts.some((alert) => alert.system === system.id) return useMemo( () => ( {opened && } ), [opened, hasAlert] ) // return useMemo( // () => ( // // // // // // {opened && } // // // ), // [opened, hasAlert] // ) }) function AlertDialogContent({ system }: { system: SystemRecord }) { const alerts = useStore($alerts) const [overwriteExisting, setOverwriteExisting] = useState(false) // alertsSignature changes only when alerts for this system change let alertsSignature = "" const systemAlerts = alerts.filter((alert) => { if (alert.system === system.id) { alertsSignature += alert.name + alert.min + alert.value return true } return false }) as AlertRecord[] return useMemo(() => { // console.log("render modal", system.name, alertsSignature) const data = Object.keys(alertInfo).map((name) => { const alert = alertInfo[name as keyof typeof alertInfo] return { name: name as keyof typeof alertInfo, alert, system, } }) return ( <> Alerts See{" "} notification settings {" "} to configure how you receive alerts. {system.name} All Systems
{data.map((d) => ( ))}
{data.map((d) => ( ))}
) }, [alertsSignature, overwriteExisting]) }