Skip to content

An AI-powered search engine with a generative UI

feat: add DataSection component for unified data part handling

Yoshiki Miura58b7e6141221
diff --git a/components/data-section.tsx b/components/data-section.tsx
new file mode 100644
index 00000000..bd6d9939
--- /dev/null
+++ b/components/data-section.tsx
@@ -0,0 +1,29 @@
+'use client'
+
+import React from 'react'
+
+import { RelatedQuestions } from './related-questions'
+
+interface DataSectionProps {
+ part: {
+ type: string
+ data: any
+ id?: string
+ }
+ onQuerySelect?: (query: string) => void
+}
+
+export function DataSection({ part, onQuerySelect }: DataSectionProps) {
+ switch (part.type) {
+ case 'data-relatedQuestions':
+ if (onQuerySelect) {
+ return (
+ <RelatedQuestions data={part.data} onQuerySelect={onQuerySelect} />
+ )
+ }
+ return null
+
+ default:
+ return null
+ }
+}
diff --git a/components/related-questions.tsx b/components/related-questions.tsx
index 4e8606c1..5d03f2b4 100644
--- a/components/related-questions.tsx
+++ b/components/related-questions.tsx
@@ -4,16 +4,13 @@ import React from 'react'
import { ArrowRight } from 'lucide-react'
+import type { RelatedQuestionsData } from '@/lib/types/ai'
+
import { Button } from './ui/button'
import { Skeleton } from './ui/skeleton'
import { CollapsibleMessage } from './collapsible-message'
import { Section } from './section'
-interface RelatedQuestionsData {
- status: 'loading' | 'success' | 'error'
- questions?: Array<{ question: string }>
-}
-
interface RelatedQuestionsProps {
data: RelatedQuestionsData
onQuerySelect: (query: string) => void
diff --git a/components/render-message.tsx b/components/render-message.tsx
index 82ced01c..751af4bf 100644
--- a/components/render-message.tsx
+++ b/components/render-message.tsx
@@ -4,9 +4,9 @@ import type { UIDataTypes, UIMessage, UITools } from '@/lib/types/ai'
import type { DynamicToolPart } from '@/lib/types/dynamic-tools'
import { AnswerSection } from './answer-section'
+import { DataSection } from './data-section'
import { DynamicToolDisplay } from './dynamic-tool-display'
import { ReasoningSection } from './reasoning-section'
-import { RelatedQuestions } from './related-questions'
import { ToolSection } from './tool-section'
import { UserFileSection } from './user-file-section'
import { UserTextSection } from './user-text-section'
@@ -135,13 +135,12 @@ export function RenderMessage({
)
case 'data-relatedQuestions':
return (
- <RelatedQuestions
- key={`${messageId}-related-${index}`}
- data={part.data}
+ <DataSection
+ key={`${messageId}-${part.type}-${index}`}
+ part={part}
onQuerySelect={onQuerySelect}
/>
)
- // Add other part types as needed
default:
return null
}
diff --git a/lib/types/ai.ts b/lib/types/ai.ts
index 14af4ac5..4ca0db14 100644
--- a/lib/types/ai.ts
+++ b/lib/types/ai.ts
@@ -10,12 +10,14 @@ export type UIMessage<
TTools = UITools
> = AIMessage
+export interface RelatedQuestionsData {
+ status: 'loading' | 'success' | 'error'
+ questions?: Array<{ question: string }>
+}
+
export type UIDataTypes = {
sources?: any[]
- relatedQuestions?: {
- status: 'loading' | 'success' | 'error'
- questions?: Array<{ question: string }>
- }
+ relatedQuestions?: RelatedQuestionsData
}
export type UITools = {