"use client" import { useMemo, useState } from "react" import { ChevronRight, Folder, Loader2, Shapes } from "lucide-react" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { useDriveList } from "@/lib/api/hooks/use-drive-queries" import type { DriveFileInfo } from "@/lib/api/types" import { displayFileName } from "@/lib/drive/display-file-name" import { DRIVE_BTN_GHOST, DRIVE_DIALOG_CONTENT, DRIVE_DIALOG_DIVIDER, DRIVE_DIALOG_OVERLAY, DRIVE_TEXT_PRIMARY, DRIVE_TEXT_SECONDARY, DRIVE_TEXT_TITLE, } from "@/lib/drive/drive-dialog-styles" import { normalizeDriveFolderPath } from "@/lib/drive/drive-sidebar-tree" import { isExcalidrawFile } from "@/lib/drive/ultidraw-formats" import { cn } from "@/lib/utils" export function DocsDriveDrawPickerDialog({ open, onOpenChange, onPickDraw, }: { open: boolean onOpenChange: (open: boolean) => void onPickDraw: (file: DriveFileInfo) => void | Promise }) { const [browsePath, setBrowsePath] = useState("/") const [loadingPath, setLoadingPath] = useState(null) const list = useDriveList(browsePath, 1, "", open) const folders = useMemo( () => (list.data?.files ?? []).filter((f) => f.type === "directory"), [list.data?.files] ) const drawings = useMemo( () => (list.data?.files ?? []).filter((f) => f.type === "file" && isExcalidrawFile(f)), [list.data?.files] ) const crumbs = useMemo(() => { const normalized = normalizeDriveFolderPath(browsePath) if (normalized === "/") return [{ path: "/", label: "Mon Drive" }] const parts = normalized.slice(1).split("/") const out: { path: string; label: string }[] = [{ path: "/", label: "Mon Drive" }] for (let i = 0; i < parts.length; i++) { const path = "/" + parts.slice(0, i + 1).join("/") out.push({ path, label: displayFileName(parts[i]!) }) } return out }, [browsePath]) const pickDraw = async (file: DriveFileInfo) => { setLoadingPath(file.path) try { await onPickDraw(file) onOpenChange(false) } catch { window.alert("Impossible de charger ce dessin depuis le Drive.") } finally { setLoadingPath(null) } } return ( Dessin depuis Drive Choisissez un fichier UltiDraw (.excalidraw) dans votre Drive.
{crumbs.map((crumb, index) => ( {index > 0 ? : null} ))}
{list.isLoading ? (
) : folders.length === 0 && drawings.length === 0 ? (

Aucun dessin dans ce dossier.

) : (
    {folders.map((folder) => (
  • ))} {drawings.map((file) => (
  • ))}
)}
) }