fix: restore selected project files by default

This commit is contained in:
muena
2026-10-06 13:12:53 +02:00
parent 7bc0142f95
commit 43fbf46014

View File

@@ -145,7 +145,7 @@ function FilePicker(props: { run: ProjectRun; directory: string; historical?: bo
if (!active) return;
setSourceRoot(scan.root);
setFiles(scan.files);
setSelected(new Set(scan.files.map((file) => file.relPath)));
setSelected(new Set(scan.files.filter((file) => file.kind === "text").map((file) => file.relPath)));
setSkipped(scan.skipped);
}
load().catch((error: Error) => showToast({ style: Toast.Style.Failure,
@@ -161,7 +161,12 @@ function FilePicker(props: { run: ProjectRun; directory: string; historical?: bo
});
}
async function exportFiles() {
if (!selected.size || !sourceRoot) return;
if (busy) return;
if (!selected.size) {
await showToast({ style: Toast.Style.Failure, title: "Keine Dateien ausgewählt" });
return;
}
if (!sourceRoot) return;
setBusy(true);
const toast = await showToast({ style: Toast.Style.Animated, title: "Klartext-Kopien werden erstellt" });
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
@@ -191,7 +196,7 @@ function FilePicker(props: { run: ProjectRun; directory: string; historical?: bo
}
toast.style = Toast.Style.Success;
toast.title = `${selected.size} Klartext-Dateien in Downloads`;
await showInFinder(targetRoot);
await showInFinder(targetRoot).catch(() => undefined);
} catch (error) {
if (targetRoot) await fs.rm(targetRoot, { recursive: true, force: true });
toast.style = Toast.Style.Failure;
@@ -199,24 +204,34 @@ function FilePicker(props: { run: ProjectRun; directory: string; historical?: bo
toast.message = (error as Error).message;
} finally { setBusy(false); }
}
const textFiles = files.filter((file) => file.kind === "text");
const complexFiles = files.filter((file) => file.kind === "document");
const renderFile = (file: ProjectFile) => <List.Item key={file.relPath}
icon={selected.has(file.relPath) ? Icon.CheckCircle : Icon.Circle}
title={restorePath(file.relPath, props.run.mapping, props.run.matchModes)} subtitle={file.relPath}
accessories={file.kind === "document" ? [{ text: "Office · manuell auswählen" }] : []}
actions={<ActionPanel>
<Action title={selected.has(file.relPath) ? "Datei abwählen" : "Datei auswählen"} onAction={() => toggle(file.relPath)} />
<Action title="Auswahl nach Downloads wiederherstellen" icon={Icon.Download} onAction={exportFiles} />
<Action title="Nur Textdateien auswählen" onAction={() => setSelected(new Set(textFiles.map((item) => item.relPath)))} />
<Action title="Alle Dateien auswählen (inklusive Office)" onAction={() => setSelected(new Set(files.map((item) => item.relPath)))} />
<Action title="Keine auswählen" onAction={() => setSelected(new Set())} />
</ActionPanel>} />;
return <List isLoading={busy || !sourceRoot} navigationTitle={`${props.run.projectName}: Dateien für Klartext wählen`}
searchBarPlaceholder="Dateien filtern">
<List.Section title={`${selected.size} von ${files.length} Dateien ausgewählt · ${skipped} übersprungen`}>
<List.Item key="export" icon={Icon.Download} title="Ausgewählte Dateien wiederherstellen"
subtitle="Klartext-Kopien in Downloads/Velum erstellen"
subtitle="Klartext-Kopien in Downloads/Velum erstellen · Office-Dateien nur nach Auswahl"
actions={<ActionPanel><Action title="Auswahl nach Downloads wiederherstellen"
icon={Icon.Download} onAction={exportFiles} /></ActionPanel>} />
<List.Item key="source" icon={Icon.Folder} title="Quelle für die Wiederherstellung" subtitle={sourceRoot}
actions={<ActionPanel><Action title="Quellordner im Finder anzeigen" onAction={() => showInFinder(sourceRoot)} /></ActionPanel>} />
{files.map((file) => <List.Item key={file.relPath}
icon={selected.has(file.relPath) ? Icon.CheckCircle : Icon.Circle}
title={restorePath(file.relPath, props.run.mapping, props.run.matchModes)} subtitle={file.relPath}
actions={<ActionPanel>
<Action title={selected.has(file.relPath) ? "Datei abwählen" : "Datei auswählen"} onAction={() => toggle(file.relPath)} />
<Action title="Auswahl nach Downloads rückübersetzen" icon={Icon.Download} onAction={exportFiles} />
<Action title="Alle auswählen" onAction={() => setSelected(new Set(files.map((item) => item.relPath)))} />
<Action title="Keine auswählen" onAction={() => setSelected(new Set())} />
</ActionPanel>} />)}
</List.Section>
<List.Section title={`Textdateien · ${textFiles.length} · standardmäßig ausgewählt`}>
{textFiles.map(renderFile)}
</List.Section>
<List.Section title={`Office-Dateien · ${complexFiles.length} · bewusst auswählen`}>
{complexFiles.map(renderFile)}
</List.Section>
</List>;
}
@@ -230,6 +245,8 @@ function ProjectHistory(props: { projectName: string; entries: SavedRun[] }) {
title={new Date(run.createdAt).toLocaleString("de-AT")}
subtitle={`${run.files.length} Dateien`}
actions={<ActionPanel>
<Action title="Gespeicherten Stand wiederherstellen" icon={Icon.Download}
onAction={() => push(<FilePicker run={run} directory={directory} historical />)} />
<Action.Push title="Übersetzungstabelle anzeigen" icon={Icon.List}
target={<TranslationTable title={`${props.projectName} · ${new Date(run.createdAt).toLocaleString("de-AT")}`}
mapping={run.mapping} />} />
@@ -238,8 +255,6 @@ function ProjectHistory(props: { projectName: string; entries: SavedRun[] }) {
<Action.CopyToClipboard title="Speicherpfad kopieren" content={runCopiesPath(run, directory)} />
{run.copyPath && <Action title="Aktuelle Dateien dieses Kopienordners wiederherstellen" icon={Icon.Download}
onAction={() => push(<FilePicker run={run} directory={directory} />)} />}
<Action title="Gespeicherten Stand wiederherstellen" icon={Icon.Clock}
onAction={() => push(<FilePicker run={run} directory={directory} historical />)} />
</ActionPanel>} />)}
</List.Section>
</List>;
@@ -269,10 +284,10 @@ export default function Command() {
accessories={[{ text: `${run.files.length} Dateien` }, { text: new Date(run.createdAt).toLocaleString("de-AT") },
...(entries.length > 1 ? [{ text: `${entries.length} Stände` }] : [])]}
actions={<ActionPanel>
<Action.Push title="Übersetzungstabelle anzeigen" icon={Icon.List}
target={<TranslationTable title={run.projectName} mapping={run.mapping} />} />
<Action title="Projektdateien als Klartext wiederherstellen" icon={Icon.Download}
onAction={() => push(<FilePicker run={run} directory={directory} />)} />
<Action.Push title="Übersetzungstabelle anzeigen" icon={Icon.List}
target={<TranslationTable title={run.projectName} mapping={run.mapping} />} />
<Action title="Pseudonymisierte Kopien im Finder anzeigen" icon={Icon.Folder}
onAction={() => showInFinder(runCopiesPath(run, directory))} />
<Action.CopyToClipboard title="Speicherpfad kopieren" content={runCopiesPath(run, directory)} />