Skip to content

An AI-powered search engine with a generative UI

chore: Refactor SearchRelated component and update UI Stream

Yoshiki Miura341fefeea575
diff --git a/app/actions.tsx b/app/actions.tsx
index a1163249..9ec52331 100644
--- a/app/actions.tsx
+++ b/app/actions.tsx
@@ -402,9 +402,7 @@ export const getUIStateFromAIState = (aiState: Chat) => {
return {
id,
component: (
- <Section title="Related" separator={true}>
- <SearchRelated relatedQueries={relatedQueries.value} />
- </Section>
+ <SearchRelated relatedQueries={relatedQueries.value} />
)
}
case 'followup':
diff --git a/components/search-related.tsx b/components/search-related.tsx
index d5846a11..554b9218 100644
--- a/components/search-related.tsx
+++ b/components/search-related.tsx
@@ -12,6 +12,8 @@ import {
import { AI } from '@/app/actions'
import { UserMessage } from './user-message'
import { PartialRelated } from '@/lib/schema/related'
+import { Section } from './section'
+import { Skeleton } from './ui/skeleton'
export interface SearchRelatedProps {
relatedQueries: StreamableValue<PartialRelated>
@@ -26,6 +28,7 @@ export const SearchRelated: React.FC<SearchRelatedProps> = ({
const [related, setRelated] = useState<PartialRelated>()
useEffect(() => {
+ console.log('data', data)
if (!data) return
setRelated(data)
}, [data])
@@ -56,25 +59,31 @@ export const SearchRelated: React.FC<SearchRelatedProps> = ({
])
}
- return (
- <form onSubmit={handleSubmit} className="flex flex-wrap">
- {related?.items
- ?.filter(item => item?.query !== '')
- .map((item, index) => (
- <div className="flex items-start w-full" key={index}>
- <ArrowRight className="h-4 w-4 mr-2 mt-1 flex-shrink-0 text-accent-foreground/50" />
- <Button
- variant="link"
- className="flex-1 justify-start px-0 py-1 h-fit font-semibold text-accent-foreground/50 whitespace-normal text-left"
- type="submit"
- name={'related_query'}
- value={item?.query}
- >
- {item?.query}
- </Button>
- </div>
- ))}
- </form>
+ return related ? (
+ <Section title="Related" separator={true}>
+ <form onSubmit={handleSubmit} className="flex flex-wrap">
+ {related?.items
+ ?.filter(item => item?.query !== '')
+ .map((item, index) => (
+ <div className="flex items-start w-full" key={index}>
+ <ArrowRight className="h-4 w-4 mr-2 mt-1 flex-shrink-0 text-accent-foreground/50" />
+ <Button
+ variant="link"
+ className="flex-1 justify-start px-0 py-1 h-fit font-semibold text-accent-foreground/50 whitespace-normal text-left"
+ type="submit"
+ name={'related_query'}
+ value={item?.query}
+ >
+ {item?.query}
+ </Button>
+ </div>
+ ))}
+ </form>
+ </Section>
+ ) : error ? null : (
+ <Section title="Related" separator={true}>
+ <Skeleton className="w-full h-6" />
+ </Section>
)
}
diff --git a/lib/agents/query-suggestor.tsx b/lib/agents/query-suggestor.tsx
index dbd5e938..f396e854 100644
--- a/lib/agents/query-suggestor.tsx
+++ b/lib/agents/query-suggestor.tsx
@@ -1,7 +1,6 @@
import { createStreamableUI, createStreamableValue } from 'ai/rsc'
import { CoreMessage, streamObject } from 'ai'
import { PartialRelated, relatedSchema } from '@/lib/schema/related'
-import { Section } from '@/components/section'
import SearchRelated from '@/components/search-related'
import { getModel } from '../utils'
@@ -10,11 +9,7 @@ export async function querySuggestor(
messages: CoreMessage[]
) {
const objectStream = createStreamableValue<PartialRelated>()
- uiStream.append(
- <Section title="Related" separator={true}>
- <SearchRelated relatedQueries={objectStream.value} />
- </Section>
- )
+ uiStream.append(<SearchRelated relatedQueries={objectStream.value} />)
const lastMessages = messages.slice(-1).map(message => {
return {