From bae032aa75b3b1045f60d6016c81719ed2fbbb0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorem=20Ju=C3=A1rez?= Date: Fri, 26 Jun 2026 18:38:11 -0600 Subject: [PATCH] Consultant: clear input on send and show the asked question above the answer The question stayed in the input after sending. Now it clears automatically and the submitted question appears as a chat bubble above the response, so the panel reads like a normal prompt/chat (your message on top, the assistant's answer below). --- src/components/public/AiConsultant.tsx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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({ -
- {!answer && !loading &&

{t('intro')}

} +
+ {!asked && !loading &&

{t('intro')}

} + {asked && ( +
+ {asked} +
+ )} {loading &&

{t('thinking')}

} {error &&

⚠️

} {answer && (