diff --git a/src/components/public/AiConsultant.tsx b/src/components/public/AiConsultant.tsx index 0226915..e9a9dec 100644 --- a/src/components/public/AiConsultant.tsx +++ b/src/components/public/AiConsultant.tsx @@ -27,6 +27,7 @@ export default function AiConsultant({ const tm = useTranslations('menu'); const locale = useLocale(); const [question, setQuestion] = useState(''); + const [asked, setAsked] = useState(''); // the submitted question, shown above the answer const [loading, setLoading] = useState(false); const [answer, setAnswer] = useState<{ intro?: string; recommendations: Recommendation[] } | null>( null, @@ -43,7 +44,10 @@ export default function AiConsultant({ }, [buildSuggestions, seed, answer, resolveDish]); async function ask() { - if (!question.trim() || loading) return; + const q = question.trim(); + if (!q || loading) return; + setAsked(q); // show it above the answer (chat-style) + setQuestion(''); // clear the input automatically setLoading(true); setError(false); setAnswer(null); @@ -51,7 +55,7 @@ export default function AiConsultant({ const res = await fetch(`/api/${slug}/ai-consult`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ question, locale }), + body: JSON.stringify({ question: q, locale }), }); if (!res.ok) throw new Error('failed'); setAnswer(await res.json()); @@ -101,8 +105,16 @@ export default function AiConsultant({ -
{t('intro')}
} +{t('intro')}
} + {asked && ( +{t('thinking')}
} {error &&⚠️
} {answer && (