import { useEffect } from "react";
import { useStore } from "../store/useStore";
import { DownloadIcon, PlusIcon, TrashIcon } from "../components/Icon";
import { downloadFile, type FileNode } from "../api/client";
import { relTime } from "../lib/time";
/** Panneau gauche : historique des sessions + arborescence de fichiers. */
export function LeftPanel() {
const {
sessions,
currentSessionId,
streamingSessionId,
refreshSessions,
refreshFiles,
fileTree,
newSession,
openSession,
removeSession,
} = useStore();
useEffect(() => {
refreshSessions();
refreshFiles();
}, [refreshSessions, refreshFiles]);
return (
{/* Historique */}
{sessions.length === 0 && (
Aucune session. Lance une conversation ci-dessous.
)}
{sessions.map((s) => {
const active = s.id === currentSessionId;
const working = s.id === streamingSessionId;
return (
openSession(s.id)}
className={`group cursor-pointer border-[3px] border-line px-3 py-2.5 ${
active ? "bg-card-deep shadow-hard-accent" : "bg-card"
}`}
style={{ borderRadius: 7 }}
>
{s.title}
{working && (
EN COURS
)}
{relTime(s.updated_at)} · {s.message_count ?? 0} message
{(s.message_count ?? 0) > 1 ? "s" : ""}
);
})}
{/* Fichiers */}
FICHIERS
workspace/
{fileTree.length === 0 ? (
Aucun fichier pour l'instant.
L'agent créera des fichiers ici.
) : (
)}
);
}
function FileTree({ nodes, depth }: { nodes: FileNode[]; depth: number }) {
const { openPreview, previewPath, removeFile } = useStore();
const confirmDelete = (n: FileNode) => {
const msg =
n.type === "dir"
? `Supprimer le dossier ${n.path} et tout son contenu ?`
: `Supprimer ${n.path} ?`;
if (window.confirm(msg)) void removeFile(n.path);
};
return (
<>
{nodes.map((n) => {
const active = n.type === "file" && n.path === previewPath;
return (
n.type === "file" && openPreview(n.path)}
className={`group mb-[3px] flex items-center gap-2 px-2 py-[5px] ${
n.type === "file"
? active
? "cursor-pointer border-2 border-line bg-card-deep text-white"
: "cursor-pointer text-ink-2 hover:bg-base"
: "text-muted"
}`}
style={{ paddingLeft: 8 + depth * 14 }}
>
{n.type === "dir" ? (
▾
) : (
)}
{n.name}
{n.type === "file" && (
)}
{n.children &&
}
);
})}
>
);
}