Skip to content

An AI-powered search engine with a generative UI

refactor: Add skeleton for search section

Yoshiki Miura557afde410d7
diff --git a/components/default-skeleton.tsx b/components/default-skeleton.tsx
index 0cc587bf..68d0f5d7 100644
--- a/components/default-skeleton.tsx
+++ b/components/default-skeleton.tsx
@@ -1,6 +1,5 @@
'use client'
-import React from 'react'
import { Skeleton } from './ui/skeleton'
export const DefaultSkeleton = () => {
@@ -11,3 +10,18 @@ export const DefaultSkeleton = () => {
</div>
)
}
+
+export function SearchSkeleton() {
+ return (
+ <div className="flex flex-wrap gap-2 pb-0.5">
+ {[...Array(4)].map((_, index) => (
+ <div
+ key={index}
+ className="w-[calc(50%-0.5rem)] md:w-[calc(25%-0.5rem)]"
+ >
+ <Skeleton className="h-20 w-full" />
+ </div>
+ ))}
+ </div>
+ )
+}
diff --git a/components/related-questions.tsx b/components/related-questions.tsx
index 82b8a2ec..a63e4170 100644
--- a/components/related-questions.tsx
+++ b/components/related-questions.tsx
@@ -49,11 +49,11 @@ export const RelatedQuestions: React.FC<RelatedQuestionsProps> = ({
)
const relatedQuestions = lastRelatedQuestionsAnnotation?.data
- if ((!relatedQuestions || relatedQuestions.items.length < 3) && !isLoading) {
+ if ((!relatedQuestions || !relatedQuestions.items) && !isLoading) {
return null
}
- if (!relatedQuestions && isLoading) {
+ if (relatedQuestions.items.length === 0 && isLoading) {
return (
<CollapsibleMessage
role="assistant"
diff --git a/components/search-section.tsx b/components/search-section.tsx
index 695dace2..41c710e4 100644
--- a/components/search-section.tsx
+++ b/components/search-section.tsx
@@ -5,7 +5,7 @@ import type { SearchResults as TypeSearchResults } from '@/lib/types'
import { ToolInvocation } from 'ai'
import { useChat } from 'ai/react'
import { CollapsibleMessage } from './collapsible-message'
-import { DefaultSkeleton } from './default-skeleton'
+import { SearchSkeleton } from './default-skeleton'
import { SearchResults } from './search-results'
import { SearchResultsImageSection } from './search-results-image'
import { Section, ToolArgsSection } from './section'
@@ -59,7 +59,7 @@ export function SearchSection({
</Section>
)}
{isLoading && isToolLoading ? (
- <DefaultSkeleton />
+ <SearchSkeleton />
) : searchResults?.results ? (
<Section title="Sources">
<SearchResults results={searchResults.results} />