okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-split-int' into f-split-vision7c5e84612

main
1.9 KiB28 linesraw
1import { useState } from 'react';
2import { tr } from '../lib/i18n';
3import { chooseChatFolder, setChatFolder, useChatFolder } from '../lib/chat-folder';
4import { pushToast } from '../lib/store';
5import { plainFailureText } from '../lib/plain-errors';
6import { Icon } from './ui';
7
8/**
9 * 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
10 * system folder picker; the small x goes back to the default folder. The assistant works inside this folder and nowhere else.
11 */
12export function FolderChip({ chatId, disabled }: { chatId: string | null | undefined; disabled?: boolean }) {
13  const folder = useChatFolder(chatId);
14  const [busy, setBusy] = useState(false);
15  if (!chatId) return null;
16  const run = async (fn: () => Promise<unknown>) => {
17    setBusy(true);
18    try { await fn(); } catch (e) { pushToast('error', tr("The folder was not changed"), plainFailureText(e instanceof Error ? e.message : String(e)).message); }
19    finally { setBusy(false); }
20  };
21  const label = folder ? folder.name : tr("Select a folder");
22  return <div className="folderchip" data-set={folder ? 'true' : undefined} data-missing={folder && !folder.exists ? 'true' : undefined}>
23    <button type="button" className="folderchip__pick" disabled={busy || disabled} title={folder ? folder.path : tr("Choose the folder this chat works in")} aria-label={folder ? tr("Project folder: {0}. Change it.", [folder.name]) : tr("Select a folder")} onClick={() => void run(() => chooseChatFolder(chatId))}>
24      <Icon name="folder" size={15}/><span>{label}</span>
25    </button>
26    {folder ? <button type="button" className="folderchip__x" disabled={busy || disabled} title={tr("Use the default folder")} aria-label={tr("Use the default folder")} onClick={() => void run(() => setChatFolder(chatId, null))}><Icon name="x" size={12}/></button> : null}
27  </div>;
28}