diff --git a/app/components/Chatbot/index.tsx b/app/components/Chatbot/index.tsx index 2261a790..b3c4a84b 100644 --- a/app/components/Chatbot/index.tsx +++ b/app/components/Chatbot/index.tsx @@ -51,6 +51,7 @@ type QuestionInputProps = { initial?: string onChange?: (val: string) => void onAsk?: (val: string) => void + onSuggestedAsk?: (followup: Followup) => void fixed?: boolean placeholder?: string } @@ -58,6 +59,7 @@ const QuestionInput = ({ initial, onChange, onAsk, + onSuggestedAsk, fixed, placeholder = 'Ask Stampy a question...', }: QuestionInputProps) => { @@ -71,6 +73,12 @@ const QuestionInput = ({ setQuestion('') } + const handleSuggestedAsk = (followUp: Followup) => { + clear() + onSuggestedAsk && onSuggestedAsk(followUp) + setQuestion('') + } + const handleChange = (val: string) => { search(val, 0.7) setQuestion(val) @@ -83,7 +91,10 @@ const QuestionInput = ({ ref={clickDetectorRef} > {results.length > 0 ? ( - ) : undefined} @@ -184,10 +195,10 @@ const Followups = ({title, followups, onSelect, className}: FollowupsProps) => { const SplashScreen = ({ questions, - onQuestion, + onSelection, }: { - questions?: string[] - onQuestion: (v: string) => void + questions?: Followup[] + onSelection: (followup: Followup) => void }) => (
@@ -197,15 +208,15 @@ const SplashScreen = ({
({text}))} - onSelect={({text}: Followup) => onQuestion(text)} + followups={questions} + onSelect={onSelection} /> ) type ChatbotProps = { question?: string - questions?: string[] + questions?: Followup[] settings?: ChatSettings } export const Chatbot = ({question, questions, settings}: ChatbotProps) => { @@ -217,6 +228,9 @@ export const Chatbot = ({question, questions, settings}: ChatbotProps) => { const fetcher = useFetcher({key: 'followup-fetcher'}) const {search, resultsForRef, waitForResults, loadedQuestions} = useSearch(1) + // When a page needs to be loaded fetcher.load(url) is called and then this + // effect takes care of filling in the content of the StampyArticle ChatEntry + // once it has been loaded. useEffect(() => { if (!fetcher.data || fetcher.state !== 'idle') return @@ -248,7 +262,7 @@ export const Chatbot = ({question, questions, settings}: ChatbotProps) => { ) }, [fetcher.data, fetcher.state]) - const showFollowup = async ({text, pageid}: Followup) => { + const showArticleByID = async ({text, pageid}: Followup) => { if (pageid) fetcher.load(questionUrl({pageid})) setHistory((prev) => [ ...prev, @@ -323,7 +337,7 @@ export const Chatbot = ({question, questions, settings}: ChatbotProps) => { return (
{history.length === 0 ? ( - + ) : undefined} {history.map((item, i) => ( @@ -334,13 +348,14 @@ export const Chatbot = ({question, questions, settings}: ChatbotProps) => { ) : undefined}
0 ? 'Message Stampy' : undefined} fixed /> diff --git a/app/routes/chat.tsx b/app/routes/chat.tsx index abe2e440..74635b76 100644 --- a/app/routes/chat.tsx +++ b/app/routes/chat.tsx @@ -38,9 +38,9 @@ export default function App() {