/** Deployment dialogs: Sync with Deployed and the SSH password prompt. */ import { useState } from "react"; import clsx from "clsx"; import type { SyncEntry, SyncStatus } from "@/platform/ipc"; import { useTx, useTxTemplate } from "@/platform/i18n"; import { relativePath, useProject } from "@/platform/project"; import { Checkbox, Dialog, Input, Spinner, T } from "@/ui"; import { closeSync, runSync } from "./actions"; import { formatSize, formatTime, syncChoices, syncSteps, type SyncChoice } from "./model"; import { patchSync, useDeployment } from "./store"; import styles from "./Deployment.module.css"; const STATUS_LABELS: Record = { localOnly: "Local only", remoteOnly: "Remote only", localNewer: "Local is newer", remoteNewer: "Remote is newer", different: "Different size", same: "Identical", }; const CHOICE_LABELS: Record = { skip: "Skip", upload: "Upload", download: "Download", deleteRemote: "Delete remote", deleteLocal: "Delete local", }; function SyncRow({ entry, choice, onChoice, disabled, }: { entry: SyncEntry; choice: SyncChoice; onChoice: (c: SyncChoice) => void; disabled: boolean; }) { const tx = useTx(); return ( {entry.path} {entry.local ? formatSize(entry.local.size) : ""} {formatTime(entry.local?.mtime)} {entry.remote ? formatSize(entry.remote.size) : ""} {formatTime(entry.remote?.mtime)} {tx(STATUS_LABELS[entry.status])} ); } function SyncDialog() { const sync = useDeployment((s) => s.sync); const root = useProject((s) => s.project?.root ?? null); const tx = useTx(); const txt = useTxTemplate(); if (!sync) return null; const entries = sync.entries; const shown = entries?.filter((e) => !sync.hideSame || e.status !== "same") ?? []; const steps = syncSteps(sync.choices); const same = entries?.filter((e) => e.status === "same").length ?? 0; const where = sync.paths.map((path) => (root ? relativePath(root, path) || "/" : path)).join(", "); return ( patchSync({ hideSame })} label={txt(`Hide identical files (${same})`)} /> ) } buttons={[ { label: "Cancel", role: "cancel" }, { label: "Synchronize", role: "default", disabled: !entries || sync.running || steps.length === 0, onClick: () => void runSync(steps), }, ]} >
{where} {entries && <> · {txt(`${steps.length} of ${entries.length} files will change`)}}
{!!sync.skipped?.length && (
{txt(`Skipped: ${sync.skipped.length}`)}:{" "} {sync.skipped.map((s) => (root ? relativePath(root, s.path) : s.path)).join(", ")}
)} {sync.error &&
{sync.error}
} {!entries && !sync.error && (
Comparing local and remote files…
)} {entries && (
{shown.length === 0 && ( )} {shown.map((e) => ( patchSync({ choices: { ...sync.choices, [e.path]: c } })} /> ))}
{tx("Action")} {tx("Path")} {tx("Local size")} {tx("Local modified")} {tx("Remote size")} {tx("Remote modified")} {tx("Status")}
Local and remote files are identical
)} {sync.running && (
Synchronizing…
)}
); } function SecretDialog() { const prompt = useDeployment((s) => s.secret); const [secret, setSecret] = useState(""); const [save, setSave] = useState(false); if (!prompt) return null; const finish = (answer: { secret: string; save: boolean } | null) => { prompt.resolve(answer); setSecret(""); setSave(false); }; return ( finish(null)} width={420} buttons={[ { label: "Cancel", role: "cancel" }, { label: "OK", role: "default", disabled: !secret, onClick: () => finish({ secret, save }) }, ]} >
{ e.preventDefault(); if (secret) finish({ secret, save }); }} >
{prompt.message}
setSecret(e.target.value)} />
); } export function DeploymentDialogs() { return ( <> ); }