Files
t3tui/src/ui/SettingsView.tsx
T
Callum Alpass 2b31804f8e Add attachments, usage limits and automation editing
Attachments upload like the web composer's (signed URL, then bytes) and ride on the next message or a draft's first message; pending names show above the composer and removal deletes the unsent upload. Settings shows provider limit windows, banked reset credits and the last 30 days' usage summary, with a status-line note near a limit and a confirmed reset-credit command. Automations can be created and edited in $EDITOR from a template parsed back against the web form's rules, and deleted behind a confirm. Asks for the diagnostics:read and providers:manage scopes the new RPCs need.
2026-11-02 20:47:54 +11:00

56 lines
2.8 KiB
TypeScript

import type { SettingRow } from "../model/settings.ts";
import { colors } from "./theme.ts";
/** Settings in place of the conversation: tui3's own (cycled with enter or a click), then the server's, read-only. */
export function SettingsView(props: {
readonly rows: readonly SettingRow[];
readonly server: readonly { label: string; value: string }[];
readonly serverStatus: "loading" | "live" | "error";
/** Usage limits and the last 30 days' totals, read-only; left out until known. */
readonly usage?: readonly { label: string; value: string }[];
readonly selected: number;
readonly path: string;
readonly onCycle: (index: number) => void;
}) {
const usage = props.usage ?? [];
const labelWidth = Math.max(...props.rows.map((row) => row.label.length), ...props.server.map((line) => line.label.length), ...usage.map((line) => line.label.length)) + 2;
return (
<box flexGrow={1} minHeight={0} flexDirection="column" paddingLeft={2} paddingRight={1}>
<box flexDirection="row" flexShrink={0} height={1}>
<text fg={colors.text}>
<strong>Settings</strong>
</text>
<box flexGrow={1} />
<text fg={colors.faint}>esc close</text>
</box>
<text fg={colors.faint} marginTop={1}>{`tui3 · ${props.path}`}</text>
{props.rows.map((row, index) => {
const selected = index === props.selected;
return (
<box key={row.key} flexDirection="row" height={1} backgroundColor={selected ? colors.selectedBg : "transparent"} onMouseDown={() => props.onCycle(index)}>
<text fg={colors.muted} flexShrink={0}>{`${selected ? "▸ " : " "}${row.label.padEnd(labelWidth)}`}</text>
<text fg={colors.text} flexShrink={0}>{row.value}</text>
<text fg={colors.faint} wrapMode="none">{` ${row.help}`}</text>
</box>
);
})}
<text fg={colors.faint} marginTop={1}>T3 Code · change these in the app</text>
{props.serverStatus === "loading" ? <text fg={colors.muted}> Loading…</text> : null}
{props.serverStatus === "error" ? <text fg={colors.bad}> Could not read the server's settings.</text> : null}
{props.server.map((line) => (
<box key={line.label} flexDirection="row" height={1}>
<text fg={colors.muted} flexShrink={0}>{` ${line.label.padEnd(labelWidth)}`}</text>
<text fg={colors.text}>{line.value}</text>
</box>
))}
{usage.length > 0 ? <text fg={colors.faint} marginTop={1}>Usage</text> : null}
{usage.map((line) => (
<box key={`${line.label}:${line.value}`} flexDirection="row" height={1}>
<text fg={colors.muted} flexShrink={0}>{` ${line.label.padEnd(labelWidth)}`}</text>
<text fg={colors.text}>{line.value}</text>
</box>
))}
</box>
);
}