"use client"; import { useRef, useState } from "react"; import { FolderIcon, PlusIcon } from "@/components/icons"; import { createFolder } from "@/lib/folders"; import { useI18n } from "@/lib/i18n"; import { ALL_FOLDERS } from "@/lib/nav"; import type { Folder } from "@/lib/schemas"; import { cn } from "@/lib/utils"; export { ALL_FOLDERS }; /** * Folder switcher. Reads like a row of quiet pills (ChatGPT sidebar items): * the active one is filled, the rest are text with a hover wash. */ export function FolderBar({ folders, counts, selected, onSelect, onCreated, className, }: { folders: Folder[]; counts: Record; selected: string; onSelect: (id: string) => void; onCreated: (id: string) => void; className?: string; }) { const [creating, setCreating] = useState(false); const [draft, setDraft] = useState(""); const [error, setError] = useState(null); const inputRef = useRef(null); const { t } = useI18n(); const submit = () => { const result = createFolder(draft); if ("error" in result) { setError(result.error); return; } onCreated(result.folder.id); setDraft(""); setError(null); setCreating(false); }; const pill = (active: boolean) => cn( "folder-pill inline-flex shrink-0 items-center gap-2 rounded-full px-3.5 py-1.5 text-[13px] font-medium transition", active ? "bg-[var(--surface-sunken)] text-[var(--text)]" : "text-[var(--text-muted)] hover:bg-[var(--hover)] hover:text-[var(--text)]", ); return (
{folders.map((folder) => ( ))} {creating ? ( setDraft(event.target.value)} onKeyDown={(event) => { event.stopPropagation(); if (event.key === "Enter") submit(); if (event.key === "Escape") { setCreating(false); setDraft(""); setError(null); } }} placeholder={t("common.folderName")} aria-label={t("common.newFolderName")} maxLength={60} className="w-28 bg-transparent text-[13px] text-[var(--text)] outline-none placeholder:text-[var(--text-subtle)]" /> ) : ( )}
{error ?

{error}

: null}
); }