11import React from "react" ;
2+ import React from "react" ;
23import { useSuggestedQuestions } from "../../utils/hooks/useSuggestedQuestions" ;
34import { useChatState } from "../../utils/hooks/chat-context" ;
45import {
56 AiQuestion ,
67 isAiQuestion ,
8+ isDefaultSearchQuery ,
79 useModalState ,
810} from "../../utils/hooks/modal-context" ;
911import { cn } from "../../utils/styles" ;
1012import { useAutoAnimate } from "@formkit/auto-animate/react" ;
1113import { ArrowRotateRightIcon , SparklesIcon } from "../icons" ;
1214import { AIInitialMessage } from "./AIInitalMessage" ;
15+ import { DefaultSearchQuery } from "trieve-ts-sdk" ;
1316
1417export const SuggestedQuestions = ( {
1518 onMessageSend,
@@ -20,21 +23,37 @@ export const SuggestedQuestions = ({
2023 const { suggestedQuestions, isLoadingSuggestedQueries, getQuestions } =
2124 useSuggestedQuestions ( ) ;
2225
23- const { props, trieveSDK, fingerprint, abTreatment } = useModalState ( ) ;
26+ const { props, trieveSDK, fingerprint, abTreatment } =
27+ useModalState ( ) ;
2428 const [ parent ] = useAutoAnimate ( { duration : 100 } ) ;
2529
2630 if ( messages . length ) {
2731 return null ;
2832 }
2933
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- ) ;
34+ const handleSuggestedQuestion = async (
35+ q : AiQuestion | DefaultSearchQuery | string ,
36+ ) => {
37+ console . log ( "q" , q ) ;
38+ setCurrentQuestion ( isAiQuestion ( q ) ? q . questionText : isDefaultSearchQuery ( q ) ? q . query ?? "" : q ) ;
39+
40+ if ( ! isDefaultSearchQuery ( q ) ) {
41+ askQuestion (
42+ isAiQuestion ( q ) ? q . questionText : q ,
43+ undefined ,
44+ isAiQuestion ( q ) ? ( q . products ?. map ( ( p ) => p . groupId ) ?? [ ] ) : undefined ,
45+ isAiQuestion ( q ) && q . promptForAI !== "" ? q . promptForAI : undefined ,
46+ ) ;
47+ } else {
48+ askQuestion (
49+ isAiQuestion ( q ) ? q . questionText : isDefaultSearchQuery ( q ) ? q . query ?? "" : q ,
50+ undefined ,
51+ isAiQuestion ( q ) ? ( q . products ?. map ( ( p ) => p . groupId ) ?? [ ] ) : undefined ,
52+ isAiQuestion ( q ) && q . promptForAI !== "" ? q . promptForAI : undefined ,
53+ undefined ,
54+ q . imageUrl ?? "" ,
55+ ) ;
56+ }
3857
3958 const requestId =
4059 messages [ messages . length - 1 ] ?. queryId ??
@@ -46,7 +65,7 @@ export const SuggestedQuestions = ({
4665 user_id : fingerprint ,
4766 location : window . location . href ,
4867 metadata : {
49- followup_query : q ,
68+ followup_query : isAiQuestion ( q ) ? q . questionText : isDefaultSearchQuery ( q ) ? q . query ?? "" : q ,
5069 component_props : props ,
5170 ab_treatment : abTreatment ,
5271 } ,
@@ -100,17 +119,17 @@ export const SuggestedQuestions = ({
100119 onClick = { ( ) => {
101120 handleSuggestedQuestion ( q ) ;
102121 } }
103- key = { isAiQuestion ( q ) ? q . questionText : q }
122+ key = { isAiQuestion ( q ) ? q . questionText : isDefaultSearchQuery ( q ) ? q . query ?? "" : q }
104123 className = { `suggested-question tv-flex tv-gap-1 tv-items-center${
105124 isLoadingSuggestedQueries ? " loading" : ""
106125 } `}
107126 >
108127 < SparklesIcon fill = "none" width = { 15 } height = { 15 } />
109- { isAiQuestion ( q ) ? q . questionText : q }
128+ { isAiQuestion ( q ) ? q . questionText : isDefaultSearchQuery ( q ) ? q . query ?? "" : q }
110129 </ button >
111130 ) ) }
112131 </ div >
113132 </ div >
114133 </ div >
115134 ) ;
116- } ;
135+ } ;
0 commit comments