import { useEffect, useRef } from "preact/hooks"; import { useI18n } from "../../../shared/i18n/context"; import type { UpdateStep } from "../../../shared/hooks/use-update-status"; import type { TranslationKey } from "../../../shared/i18n/translations"; const STEP_LABELS: Record = { pull: "updatePulling", install: "updateInstalling", build: "updateBuilding", restart: "updateRestarting", }; interface UpdateModalProps { open: boolean; onClose: () => void; mode: "git" | "docker" | "electron"; commits: { hash: string; message: string }[]; release: { version: string; body: string; url: string } | null; onApply: () => void; applying: boolean; restarting: boolean; restartFailed: boolean; updateSteps?: UpdateStep[]; } export function UpdateModal({ open, onClose, mode, commits, release, onApply, applying, restarting, restartFailed, updateSteps = [], }: UpdateModalProps) { const { t } = useI18n(); const dialogRef = useRef(null); useEffect(() => { const dialog = dialogRef.current; if (!dialog) return; if (open && !dialog.open) { dialog.showModal(); } else if (!open && dialog.open) { dialog.close(); } }, [open]); // Close on backdrop click const handleBackdropClick = (e: MouseEvent) => { if (e.target === dialogRef.current && !restarting && !applying) { onClose(); } }; // Close on Escape const handleCancel = (e: Event) => { if (restarting || applying) { e.preventDefault(); } }; if (!open) return null; return (
{/* Header */}

{t("updateTitle")}

{!restarting && !applying && ( )}
{/* Body */}
{(applying || restarting) && updateSteps.length > 0 ? (
{updateSteps.map((s) => (
{s.status === "done" ? ( ) : s.status === "error" ? ( ) : ( )} {t(STEP_LABELS[s.step] ?? ("updateBuilding" as TranslationKey))}
))}
) : restarting ? (
{t("updateRestarting")}
) : restartFailed ? (
{t("restartFailed")}
) : mode === "git" ? (
    {commits.map((c) => (
  • {c.hash} {c.message}
  • ))}
) : ( <> {release && (
                  {release.body}
                
)} )}
{/* Footer */} {!restarting && !restartFailed && (
{mode === "git" ? ( ) : mode === "docker" ? (
{t("dockerAutoUpdateHint")}
) : ( {t("electronUpdateHint")} )}
)} {/* Close button for restartFailed state */} {restartFailed && (
)}
); }