import { Action, ActionPanel, confirmAlert, Form, Icon, showToast, Toast, useNavigation } from "@raycast/api"; import { useState } from "react"; import { relocateProject } from "./lib/project-relocation"; export function RelocateProjectForm(props: { projectName: string; oldPath: string; onMoved: () => Promise }) { const { pop } = useNavigation(); const [busy, setBusy] = useState(false); async function save(values: { newPath: string[] }) { const newPath = values.newPath?.[0]; if (!newPath) { await showToast({ style: Toast.Style.Failure, title: "Bitte den neuen Projektordner wählen" }); return; } if (!(await confirmAlert({ title: "Projektordner aktualisieren?", message: `Alle gespeicherten Projektstände und Regeln werden künftig ${newPath} zugeordnet. ` + `Bisheriger Pfad: ${props.oldPath}. Die Dateien im gewählten Ordner werden nicht verändert.`, primaryAction: { title: "Projektpfad aktualisieren" }, }))) return; setBusy(true); const toast = await showToast({ style: Toast.Style.Animated, title: "Projektpfad wird aktualisiert" }); try { const result = await relocateProject(props.oldPath, newPath); await props.onMoved(); toast.style = Toast.Style.Success; toast.title = "Projektordner aktualisiert"; toast.message = `${result.runsMoved} Projektstände übernommen` + (result.copiesRelinked ? ` · ${result.copiesRelinked} Kopienordner neu gefunden` : "") + (result.copiesMissing ? ` · ${result.copiesMissing} Kopienordner nicht gefunden; gespeicherte Stände bleiben verfügbar` : ""); pop(); } catch (error) { toast.style = Toast.Style.Failure; toast.title = "Projektpfad nicht aktualisiert"; toast.message = (error as Error).message; } finally { setBusy(false); } } return
}> ; }