mirror of
https://github.com/bitbaum/substrata.git
synced 2026-12-03 22:27:28 +01:00
* Every prose field gets chatkit's microphone (DictationField via TextBox) The desk settings, sweep settings, lead review form and X-ray holdings box now use one app wrapper, components/forms/TextBox, around chatkit's DictationField with the microphone on the app's own /api/transcribe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmwCTyVzo77nrcRfTsa * Changelog: a microphone in every prose field Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmwCTyVzo77nrcRfTsa --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
'use client';
|
|
|
|
import { useState } from 'react';
|
|
import { DictationField, type DictationFieldProps } from '@bitbaum/chatkit/react';
|
|
|
|
/**
|
|
* Every place a person types words in substrata, outside a conversation: one
|
|
* chatkit `DictationField` with the microphone on the app's own
|
|
* `/api/transcribe` (which transcribes and returns the words, nothing kept).
|
|
*
|
|
* Two shapes, the same box:
|
|
* - controlled: `value` + `onValueChange`;
|
|
* - uncontrolled, for a server-action `<form>`: `name` + `defaultValue`. The
|
|
* words post under `name` like a native textarea.
|
|
*
|
|
* Pass `label` and `hint`; never wrap it in a `<label>`.
|
|
*/
|
|
type Shared = Omit<DictationFieldProps, 'value' | 'onValueChange' | 'voice'> & {
|
|
voice?: DictationFieldProps['voice'];
|
|
};
|
|
export type TextBoxProps =
|
|
| (Shared & { value: string; onValueChange: (next: string) => void; defaultValue?: never })
|
|
| (Shared & { defaultValue?: string; value?: never; onValueChange?: never });
|
|
|
|
const VOICE = { transcribeUrl: '/api/transcribe' } as const;
|
|
|
|
export function TextBox(props: TextBoxProps) {
|
|
const { value, onValueChange, defaultValue, voice, ...rest } = props;
|
|
const [own, setOwn] = useState(defaultValue ?? '');
|
|
const controlled = value !== undefined;
|
|
return (
|
|
<DictationField
|
|
{...rest}
|
|
voice={voice ?? VOICE}
|
|
value={controlled ? value : own}
|
|
onValueChange={controlled ? onValueChange! : setOwn}
|
|
/>
|
|
);
|
|
}
|