import { sessionUser } from '@/auth'; import { Card } from '../ui/Card'; import { IconExclamationTriangle } from '../ui/Icons'; import Link from 'next/link'; import { ChatWithMessages } from '@/lib/types'; import { dbGetUser } from '@/lib/db/functions'; import Avatar from '../Avatar'; export interface TopPrompt { chat: ChatWithMessages; userId?: string | null; } export default async function TopPrompt({ chat, userId }: TopPrompt) { const authorId = chat.userId; // 1. Viewer logged in, Viewer = Author if (userId && authorId === userId) { return null; } // 2. Viewer logged in, No Author if (userId && !authorId) { return null; } // 3. Author, but is not Viewer if (authorId && authorId !== userId) { const chatAuthor = authorId ? await dbGetUser(authorId) : null; return ( Authored by {chatAuthor?.name ?? 'Unknown'} ); } // 4. No author, Viewer not logged in if (!userId && !authorId) { return ( {process.env.NEXT_PUBLIC_IS_HUGGING_FACE ? ( Visit Landing AI{"'"}s website ) : ( Sign in )}{' '} to save and revisit your chat history! ); } return null; }
Authored by
{chatAuthor?.name ?? 'Unknown'}
{process.env.NEXT_PUBLIC_IS_HUGGING_FACE ? ( Visit Landing AI{"'"}s website ) : ( Sign in )}{' '} to save and revisit your chat history!