Files
supabase/apps/www/components/Contribute/RepliesList.tsx
549ca3677e feat: add similar threads on contribute (#42638)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

This adds a component showing a list of AI curated related threads to
the detail thread view.

## What is the current behavior?

This is not available.

## What is the new behavior?

A new component on the thread view.

## Additional context

Add any other context or screenshots.

---------

Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-03-05 12:06:55 -05:00

106 lines
3.6 KiB
TypeScript

'use client'
import Link from 'next/link'
import { useState } from 'react'
import ReactMarkdown from 'react-markdown'
import remarkGfm from 'remark-gfm'
import { Badge, Button, Card, CardContent, CardFooter, CardHeader, CardTitle } from 'ui'
import { markdownComponents } from './markdownComponents'
interface Reply {
id: string
content: string | null
author: string | null
ts: string | null
external_activity_url: string | null
}
interface RepliesListProps {
replies: Reply[]
questionAuthor: string | null
totalReplyCount?: number
}
export function RepliesList({ replies, questionAuthor, totalReplyCount }: RepliesListProps) {
const [isExpanded, setIsExpanded] = useState(false)
const hasMoreThanThree = replies.length > 3
const displayedReplies = isExpanded ? replies : replies.slice(0, 3)
if (replies.length === 0) {
return null
}
const displayCount = totalReplyCount || replies.length
return (
<div className="flex flex-col gap-3">
<Card className="relative">
<CardHeader>
<CardTitle>
Replies{' '}
<span className="text-foreground-muted tabular-nums font-normal">({displayCount})</span>
</CardTitle>
</CardHeader>
<CardContent className="flex flex-col p-0">
{displayedReplies.map((reply, index) => {
const timestamp = reply.ts ? new Date(reply.ts).toLocaleString() : null
const isOP = reply.author === questionAuthor
return (
<div key={reply.id} className="border-b border-border last:border-b-0">
<div className="px-6 py-6">
<div className="text-sm text-foreground mb-3 min-w-0">
<ReactMarkdown components={markdownComponents} remarkPlugins={[remarkGfm]}>
{reply.content || ''}
</ReactMarkdown>
</div>
<div className="flex items-center gap-x-1 text-xs text-foreground-lighter">
{reply.author && (
<>
{isOP && <Badge variant="success">OP</Badge>}
<Link
href={`/contribute/u/${encodeURIComponent(reply.author)}`}
className="hover:text-foreground transition-colors"
>
{reply.author}
</Link>
</>
)}
{reply.author && timestamp && <span>·</span>}
{timestamp && reply.external_activity_url ? (
<a
href={reply.external_activity_url}
target="_blank"
rel="noopener noreferrer"
className="hover:text-foreground transition-colors"
>
{timestamp}
</a>
) : (
timestamp && <span>{timestamp}</span>
)}
</div>
</div>
</div>
)
})}
</CardContent>
{hasMoreThanThree && (
<CardFooter className="flex justify-center">
<Button
type="default"
size="tiny"
onClick={() => setIsExpanded(!isExpanded)}
className="w-min"
>
{isExpanded
? 'Show fewer replies'
: `Show ${replies.length - 3} more ${replies.length - 3 === 1 ? 'reply' : 'replies'}`}
</Button>
</CardFooter>
)}
</Card>
</div>
)
}