import { useEffect, useState } from "react"; import { Download, FolderOpen, Pencil, Trash2, Upload } from "lucide-react"; import { Button } from "@/components/ui/button"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { formatStamp, listProjects, removeProject, renameProject, type StoredProject, } from "@/lib/studio-storage"; type Props = { open: boolean; onOpenChange: (v: boolean) => void; onOpenProject: (p: StoredProject) => void; onImportFile: () => void; onSaveCurrent: () => void; ownerId: string; }; export default function ProjectsDialog({ open, onOpenChange, onOpenProject, onImportFile, onSaveCurrent, ownerId }: Props) { const [items, setItems] = useState([]); const [toDelete, setToDelete] = useState(null); useEffect(() => { if (open) setItems(listProjects(ownerId)); }, [open, ownerId]); const download = (p: StoredProject) => { const blob = new Blob([JSON.stringify(p.data, null, 2)], { type: "application/json" }); const a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = `${p.title || "proekt"}.json`; a.click(); URL.revokeObjectURL(a.href); }; const rename = (p: StoredProject) => { const title = window.prompt("Новое название проекта", p.title); if (title && title.trim()) setItems(renameProject(p.id, title.trim(), ownerId)); }; return ( <> Мои проекты Схемы, сохранённые в памяти этого браузера.
{items.length === 0 ? (

Пока нет сохранённых проектов. Создайте схему и нажмите «Сохранить текущую схему».

) : (
{items.map((p) => (
{`Превью

{p.title}

{formatStamp(p.updatedAt)} · элементов: {p.elements}

))}
)}
!v && setToDelete(null)}> Удалить проект? Вы уверены, что хотите удалить проект «{toDelete?.title}»? Действие нельзя отменить. Отмена { if (toDelete) setItems(removeProject(toDelete.id, ownerId)); setToDelete(null); }} > Удалить ); }