1- import React , { useEffect , useState } from "react" ;
1+ import React from "react" ;
22import { useSuggestedQuestions } from "../../utils/hooks/useSuggestedQuestions" ;
33import { useChatState } from "../../utils/hooks/chat-context" ;
44import {
55 AiQuestion ,
66 isAiQuestion ,
7- isDefaultSearchQuery ,
87 useModalState ,
98} from "../../utils/hooks/modal-context" ;
109import { cn } from "../../utils/styles" ;
1110import { useAutoAnimate } from "@formkit/auto-animate/react" ;
1211import { ArrowRotateRightIcon , SparklesIcon } from "../icons" ;
1312import { AIInitialMessage } from "./AIInitalMessage" ;
14- import { DefaultSearchQuery } from "trieve-ts-sdk" ;
1513
1614export const SuggestedQuestions = ( {
1715 onMessageSend,
@@ -22,44 +20,21 @@ export const SuggestedQuestions = ({
2220 const { suggestedQuestions, isLoadingSuggestedQueries, getQuestions } =
2321 useSuggestedQuestions ( ) ;
2422
25- const { props, trieveSDK, fingerprint, abTreatment, imageUrl, setImageUrl } =
26- useModalState ( ) ;
23+ const { props, trieveSDK, fingerprint, abTreatment } = useModalState ( ) ;
2724 const [ parent ] = useAutoAnimate ( { duration : 100 } ) ;
28- const [ selectedQuestion , setSelectedQuestion ] = useState <
29- AiQuestion | DefaultSearchQuery | null
30- > ( null ) ;
31-
32- useEffect ( ( ) => {
33- if ( selectedQuestion && imageUrl ) {
34- askQuestion (
35- isAiQuestion ( selectedQuestion )
36- ? selectedQuestion . questionText
37- : ( selectedQuestion . query as string ) ,
38- undefined ,
39- isAiQuestion ( selectedQuestion )
40- ? ( selectedQuestion . products ?. map ( ( p ) => p . groupId ) ?? [ ] )
41- : undefined ,
42- isAiQuestion ( selectedQuestion ) && selectedQuestion . promptForAI !== ""
43- ? selectedQuestion . promptForAI
44- : undefined ,
45- ) ;
46- }
47- } , [ imageUrl , selectedQuestion ] ) ;
4825
4926 if ( messages . length ) {
5027 return null ;
5128 }
5229
53- const handleSuggestedQuestion = async (
54- q : AiQuestion | DefaultSearchQuery ,
55- ) => {
56- console . log ( "q" , q ) ;
57- setCurrentQuestion ( isAiQuestion ( q ) ? q . questionText : ( q . query ?? "" ) ) ;
58-
59- if ( isDefaultSearchQuery ( q ) && q . imageUrl ) {
60- setSelectedQuestion ( q ) ;
61- setImageUrl ( q . imageUrl ) ;
62- }
30+ const handleSuggestedQuestion = async ( q : string | AiQuestion ) => {
31+ setCurrentQuestion ( isAiQuestion ( q ) ? q . questionText : q ) ;
32+ askQuestion (
33+ isAiQuestion ( q ) ? q . questionText : q ,
34+ undefined ,
35+ isAiQuestion ( q ) ? ( q . products ?. map ( ( p ) => p . groupId ) ?? [ ] ) : undefined ,
36+ isAiQuestion ( q ) && q . promptForAI !== "" ? q . promptForAI : undefined ,
37+ ) ;
6338
6439 const requestId =
6540 messages [ messages . length - 1 ] ?. queryId ??
@@ -71,7 +46,7 @@ export const SuggestedQuestions = ({
7146 user_id : fingerprint ,
7247 location : window . location . href ,
7348 metadata : {
74- followup_query : isAiQuestion ( q ) ? q . questionText : q . query ,
49+ followup_query : q ,
7550 component_props : props ,
7651 ab_treatment : abTreatment ,
7752 } ,
@@ -83,7 +58,6 @@ export const SuggestedQuestions = ({
8358 } ) ;
8459 if ( onMessageSend ) {
8560 onMessageSend ( ) ;
86- setImageUrl ( "" ) ;
8761 }
8862 } ;
8963
@@ -126,13 +100,13 @@ export const SuggestedQuestions = ({
126100 onClick = { ( ) => {
127101 handleSuggestedQuestion ( q ) ;
128102 } }
129- key = { isAiQuestion ( q ) ? q . questionText : q . query }
103+ key = { isAiQuestion ( q ) ? q . questionText : q }
130104 className = { `suggested-question tv-flex tv-gap-1 tv-items-center${
131105 isLoadingSuggestedQueries ? " loading" : ""
132106 } `}
133107 >
134108 < SparklesIcon fill = "none" width = { 15 } height = { 15 } />
135- { isAiQuestion ( q ) ? q . questionText : q . query }
109+ { isAiQuestion ( q ) ? q . questionText : q }
136110 </ button >
137111 ) ) }
138112 </ div >
0 commit comments