import { useState } from 'react'; import { tr } from '../lib/i18n'; import { chooseChatFolder, setChatFolder, useChatFolder } from '../lib/chat-folder'; import { pushToast } from '../lib/store'; import { plainFailureText } from '../lib/plain-errors'; import { Icon } from './ui'; /** * The chat's project folder, above the message box on the left: its name (the full path on hover), or "Select a folder". A click opens the * system folder picker; the small x goes back to the default folder. The assistant works inside this folder and nowhere else. */ export function FolderChip({ chatId, disabled }: { chatId: string | null | undefined; disabled?: boolean }) { const folder = useChatFolder(chatId); const [busy, setBusy] = useState(false); if (!chatId) return null; const run = async (fn: () => Promise) => { setBusy(true); try { await fn(); } catch (e) { pushToast('error', tr("The folder was not changed"), plainFailureText(e instanceof Error ? e.message : String(e)).message); } finally { setBusy(false); } }; const label = folder ? folder.name : tr("Select a folder"); return
{folder ? : null}
; }