From d2d631032c7c370f6aca137b5bee0e49fc92bbb5 Mon Sep 17 00:00:00 2001 From: Myles Date: Fri, 7 Jun 2024 22:45:14 -0400 Subject: [PATCH 1/2] search by pageid instead of question --- app/components/Chatbot/index.tsx | 31 +++++++++++++++++++++++-------- app/routes/chat.tsx | 6 +++--- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/app/components/Chatbot/index.tsx b/app/components/Chatbot/index.tsx index 2261a790..35c2e830 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 @@ -323,7 +337,7 @@ export const Chatbot = ({question, questions, settings}: ChatbotProps) => { return (
{history.length === 0 ? ( - + ) : undefined} {history.map((item, i) => ( @@ -341,6 +355,7 @@ export const Chatbot = ({question, questions, settings}: ChatbotProps) => { 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() { From a60d4410429cae5009132f01a5479cc35d78ffd5 Mon Sep 17 00:00:00 2001 From: Myles Date: Fri, 7 Jun 2024 22:56:53 -0400 Subject: [PATCH 2/2] rename symbol --- app/components/Chatbot/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/components/Chatbot/index.tsx b/app/components/Chatbot/index.tsx index 35c2e830..b3c4a84b 100644 --- a/app/components/Chatbot/index.tsx +++ b/app/components/Chatbot/index.tsx @@ -262,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, @@ -337,7 +337,7 @@ export const Chatbot = ({question, questions, settings}: ChatbotProps) => { return (
{history.length === 0 ? ( - + ) : undefined} {history.map((item, i) => ( @@ -348,14 +348,14 @@ export const Chatbot = ({question, questions, settings}: ChatbotProps) => { ) : undefined}
0 ? 'Message Stampy' : undefined} fixed />