mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-23 15:36:33 +00:00
123e27643d
The three AI addons share one tile in the integration column; a dialog holds the connection, the assistant's limits and AI parsing, which now reads with the assistant's connection unless an install keeps its own. Existing parsing configs stay where they are and keep winning. The chat sees the map on screen, offers next questions under an answer, shows its live step in the window head, previews waiting changes inside the day list, checks whether a day still works, folds a multi-day plan into a week grid, keeps per-trip notes and can estimate costs. An empty or cut-off answer gets one push instead of ending silently, and the assistant's own step and size limits are raised.
113 lines
3.8 KiB
TypeScript
113 lines
3.8 KiB
TypeScript
import { NotebookPen, Plus } from 'lucide-react';
|
|
import { useId, useState } from 'react';
|
|
|
|
import { useTranslation } from '../../i18n';
|
|
import {
|
|
DialogButton,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogShell,
|
|
DialogTile,
|
|
FooterSpacer,
|
|
NEUTRAL_TINT,
|
|
} from '../shared/DialogShell';
|
|
import { TEXTAREA } from '../shared/dialogParts';
|
|
import { MAX_MEMORY_CHARS, useTripMemory } from './useTripMemory';
|
|
|
|
/** What travellers most often want minded, one tap to add each. */
|
|
const QUICK = ['vegetarian', 'kids', 'budget', 'slow', 'accessible', 'noMuseums'] as const;
|
|
|
|
/**
|
|
* The trip's notes for the assistant: a few lines it follows in every
|
|
* suggestion on this trip, written once instead of in every question. The
|
|
* common ones are a tap away; the rest is free text.
|
|
*/
|
|
export default function AssistantMemoryDialog({ tripId, onClose }: { tripId: number; onClose: () => void }) {
|
|
const { t } = useTranslation();
|
|
const labelId = useId();
|
|
const memory = useTripMemory(tripId);
|
|
const [draft, setDraft] = useState(memory.text);
|
|
const [saving, setSaving] = useState(false);
|
|
|
|
const add = (line: string) =>
|
|
setDraft((prev) => (prev.includes(line) ? prev : `${prev.trimEnd()}${prev.trim() ? '\n' : ''}${line}`));
|
|
|
|
const save = async () => {
|
|
setSaving(true);
|
|
const done = await memory.save(draft);
|
|
setSaving(false);
|
|
if (done) onClose();
|
|
};
|
|
|
|
return (
|
|
<DialogShell
|
|
onClose={onClose}
|
|
labelledBy={labelId}
|
|
width="narrow"
|
|
discardGuard={draft}
|
|
header={
|
|
<DialogHeader
|
|
tile={
|
|
<DialogTile>
|
|
<NotebookPen size={20} strokeWidth={2} />
|
|
</DialogTile>
|
|
}
|
|
tint={NEUTRAL_TINT}
|
|
labelId={labelId}
|
|
eyebrow={t('assistant.launcher.tooltip')}
|
|
title={t('assistant.memory.title')}
|
|
sub={t('assistant.memory.sub')}
|
|
subWraps
|
|
onClose={onClose}
|
|
/>
|
|
}
|
|
footer={
|
|
<DialogFooter>
|
|
<span className="text-caption tabular-nums text-content-faint">
|
|
{draft.length}/{MAX_MEMORY_CHARS}
|
|
</span>
|
|
<FooterSpacer />
|
|
<DialogButton onClick={onClose}>{t('common.cancel')}</DialogButton>
|
|
<DialogButton variant="primary" disabled={saving} onClick={() => void save()}>
|
|
{t(saving ? 'common.saving' : 'common.save')}
|
|
</DialogButton>
|
|
</DialogFooter>
|
|
}
|
|
>
|
|
<DialogSection label={t('assistant.memory.quick')}>
|
|
<div className="flex flex-wrap gap-1.5">
|
|
{QUICK.map((key, i) => {
|
|
const line = t(`assistant.memory.quick.${key}`);
|
|
const taken = draft.includes(line);
|
|
return (
|
|
<button
|
|
key={key}
|
|
type="button"
|
|
disabled={taken}
|
|
onClick={() => add(line)}
|
|
className="trek-assistant-enter inline-flex items-center gap-1 rounded-full bg-surface-card px-2.5 py-1 text-caption font-medium text-content-secondary shadow-sm ring-1 ring-edge-faint transition-all hover:-translate-y-px hover:text-content hover:shadow-md disabled:translate-y-0 disabled:opacity-40 disabled:shadow-none"
|
|
style={{ animationDelay: `${i * 40}ms` }}
|
|
>
|
|
<Plus size={11} aria-hidden="true" />
|
|
{line}
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
</DialogSection>
|
|
<DialogSection label={t('assistant.memory.notes')}>
|
|
<textarea
|
|
aria-label={t('assistant.memory.notes')}
|
|
rows={6}
|
|
maxLength={MAX_MEMORY_CHARS}
|
|
value={draft}
|
|
onChange={(e) => setDraft(e.target.value)}
|
|
placeholder={t('assistant.memory.placeholder')}
|
|
className={TEXTAREA}
|
|
/>
|
|
</DialogSection>
|
|
</DialogShell>
|
|
);
|
|
}
|