import { Action, ActionPanel, Detail, Icon, List, showToast, Toast, } from "@raycast/api"; import { useEffect, useState } from "react"; import { canonicalProjectPath, listAllRuns } from "./lib/velum-project"; import { listSessions } from "./sessions"; import type { PlaceholderMapping } from "./types"; import { markdownCodeBlock } from "./ui"; type TableSource = { id: string; title: string; subtitle: string; mapping: PlaceholderMapping; }; export function TranslationTable({ title, mapping, }: { title: string; mapping: PlaceholderMapping; }) { const groups = new Map>(); for (const entry of Object.entries(mapping).sort(([a], [b]) => a.localeCompare(b), )) { const type = entry[1].type || "Sonstige"; const entries = groups.get(type) ?? []; entries.push(entry); groups.set(type, entries); } return ( {[...groups] .sort(([a], [b]) => a.localeCompare(b)) .map(([type, entries]) => ( {entries.map(([placeholder, entry]) => ( } /> } /> } /> ))} ))} ); } export default function Command() { const [projects, setProjects] = useState([]); const [sessions, setSessions] = useState([]); const [busy, setBusy] = useState(true); useEffect(() => { Promise.all([listAllRuns(), listSessions()]) .then(([runs, savedSessions]) => { const latest = new Map(); for (const { run } of runs) { const path = canonicalProjectPath(run.projectPath); if (!latest.has(path)) latest.set(path, { id: path, title: run.projectName, subtitle: `${path} · ${new Date(run.createdAt).toLocaleString("de-AT")}`, mapping: run.mapping, }); } setProjects( [...latest.values()].sort((a, b) => a.title.localeCompare(b.title)), ); setSessions( savedSessions.map((session) => ({ id: session.id, title: session.name, subtitle: `${Object.keys(session.mapping).length} Zuordnungen · ${new Date(session.updatedAt).toLocaleString("de-AT")}`, mapping: session.mapping, })), ); }) .catch((error: Error) => showToast({ style: Toast.Style.Failure, title: "Übersetzungstabellen nicht lesbar", message: error.message, }), ) .finally(() => setBusy(false)); }, []); return ( {projects.map((source) => ( } /> } /> ))} {sessions.map((source) => ( } /> } /> ))} ); }