Skip to content

An AI-powered search engine with a generative UI

Clean up UI layout for collapsible message components

Yoshiki Miura0c11fcce1909
diff --git a/components/answer-section.tsx b/components/answer-section.tsx
index 8e1c02c3..19f34b0b 100644
--- a/components/answer-section.tsx
+++ b/components/answer-section.tsx
@@ -43,6 +43,7 @@ export function AnswerSection({
isOpen={isOpen}
onOpenChange={onOpenChange}
showBorder={false}
+ showIcon={false}
>
{message}
</CollapsibleMessage>
diff --git a/components/collapsible-message.tsx b/components/collapsible-message.tsx
index 774d633a..045a735d 100644
--- a/components/collapsible-message.tsx
+++ b/components/collapsible-message.tsx
@@ -32,7 +32,7 @@ export function CollapsibleMessage({
const content = <div className="py-2 flex-1">{children}</div>
return (
- <div className="flex gap-3">
+ <div className="flex">
{showIcon && (
<div className="relative flex flex-col items-center">
<div className={cn('mt-[10px] w-5', role === 'assistant' && 'mt-4')}>
diff --git a/components/related-questions.tsx b/components/related-questions.tsx
index f20bd379..fc8ae10b 100644
--- a/components/related-questions.tsx
+++ b/components/related-questions.tsx
@@ -3,9 +3,10 @@
import { CHAT_ID } from '@/lib/constants'
import { JSONValue } from 'ai'
import { useChat } from 'ai/react'
-import { ArrowRight, Repeat2 } from 'lucide-react'
+import { ArrowRight } from 'lucide-react'
import React from 'react'
import { CollapsibleMessage } from './collapsible-message'
+import { Section } from './section'
import { Button } from './ui/button'
import { Skeleton } from './ui/skeleton'
@@ -41,13 +42,6 @@ export const RelatedQuestions: React.FC<RelatedQuestionsProps> = ({
annotations.length - 1
] as RelatedQuestionsAnnotation
- const header = (
- <div className="flex items-center gap-1">
- <Repeat2 size={16} />
- <div>Related</div>
- </div>
- )
-
const relatedQuestions = lastRelatedQuestionsAnnotation?.data
if ((!relatedQuestions || !relatedQuestions.items) && !isLoading) {
return null
@@ -57,10 +51,10 @@ export const RelatedQuestions: React.FC<RelatedQuestionsProps> = ({
return (
<CollapsibleMessage
role="assistant"
- isCollapsible={true}
- header={header}
+ isCollapsible={false}
isOpen={isOpen}
onOpenChange={onOpenChange}
+ showIcon={false}
>
<Skeleton className="w-full h-6" />
</CollapsibleMessage>
@@ -70,35 +64,37 @@ export const RelatedQuestions: React.FC<RelatedQuestionsProps> = ({
return (
<CollapsibleMessage
role="assistant"
- isCollapsible={true}
- header={header}
+ isCollapsible={false}
isOpen={isOpen}
onOpenChange={onOpenChange}
showIcon={false}
+ showBorder={false}
>
- <div className="flex flex-wrap">
- {Array.isArray(relatedQuestions.items) ? (
- relatedQuestions.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}
- onClick={() => onQuerySelect(item?.query)}
- >
- {item?.query}
- </Button>
- </div>
- ))
- ) : (
- <div>Not an array</div>
- )}
- </div>
+ <Section title="Related" className="pt-0 pb-8">
+ <div className="flex flex-col">
+ {Array.isArray(relatedQuestions.items) ? (
+ relatedQuestions.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}
+ onClick={() => onQuerySelect(item?.query)}
+ >
+ {item?.query}
+ </Button>
+ </div>
+ ))
+ ) : (
+ <div>Not an array</div>
+ )}
+ </div>
+ </Section>
</CollapsibleMessage>
)
}
diff --git a/components/section.tsx b/components/section.tsx
index b20ab490..77812f24 100644
--- a/components/section.tsx
+++ b/components/section.tsx
@@ -13,7 +13,6 @@ import {
} from 'lucide-react'
import React from 'react'
import { ToolBadge } from './tool-badge'
-import { Badge } from './ui/badge'
import { Separator } from './ui/separator'
import { StatusIndicator } from './ui/status-indicator'
@@ -64,18 +63,15 @@ export const Section: React.FC<SectionProps> = ({
{separator && <Separator className="my-2 bg-primary/10" />}
<section
className={cn(
- ` ${size === 'sm' ? 'py-1' : size === 'lg' ? 'py-4' : 'py-1'}`,
+ ` ${size === 'sm' ? 'py-1' : size === 'lg' ? 'py-4' : 'py-2'}`,
className
)}
>
{title && (
- <Badge
- variant="secondary"
- className="flex items-center leading-none w-fit my-1"
- >
+ <h2 className="flex items-center leading-none py-2">
{icon}
{title}
- </Badge>
+ </h2>
)}
{children}
</section>