An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
fix: Update Copilot component to use object state
Yoshiki Miura34e1391bade6
diff --git a/components/copilot.tsx b/components/copilot.tsxindex ca1fac1a..8d6fc6da 100644--- a/components/copilot.tsx+++ b/components/copilot.tsx@@ -33,6 +33,7 @@ export const Copilot: React.FC<CopilotProps> = ({ inquiry }: CopilotProps) => {const [, setMessages] = useUIState<typeof AI>()const { submit } = useActions()const { setIsGenerating } = useAppState()+ const [object, setObject] = useState<PartialInquiry>()const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {setQuery(event.target.value)@@ -67,6 +68,11 @@ export const Copilot: React.FC<CopilotProps> = ({ inquiry }: CopilotProps) => {// eslint-disable-next-line react-hooks/exhaustive-deps}, [query])+ useEffect(() => {+ if (!data) return+ setObject(data)+ }, [data])+const onFormSubmit = async (e: React.FormEvent<HTMLFormElement>,skip?: boolean@@ -122,12 +128,12 @@ export const Copilot: React.FC<CopilotProps> = ({ inquiry }: CopilotProps) => {<Card className="p-4 rounded-lg w-full mx-auto"><div className="mb-4"><p className="text-lg text-foreground text-semibold ml-2">- {data?.question}+ {object?.question}</p></div><form onSubmit={onFormSubmit}><div className="flex flex-wrap justify-start mb-4">- {data?.options?.map((option, index) => (+ {object?.options?.map((option, index) => (<divkey={`option-${index}`}className="flex items-center space-x-1.5 mb-2"@@ -148,17 +154,17 @@ export const Copilot: React.FC<CopilotProps> = ({ inquiry }: CopilotProps) => {</div>))}</div>- {data?.allowsInput && (+ {object?.allowsInput && (<div className="mb-6 flex flex-col space-y-2 text-sm"><label className="text-muted-foreground" htmlFor="query">- {data?.inputLabel}+ {object?.inputLabel}</label><Inputtype="text"name="additional_query"className="w-full"id="query"- placeholder={data?.inputPlaceholder}+ placeholder={object?.inputPlaceholder}value={query}onChange={handleInputChange}/>