Spaces:
Sleeping
Sleeping
File size: 2,072 Bytes
04735a9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
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;
console.log('[Ming] ~ TopPrompt ~ authorId:', authorId);
// 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 (
<Card className="group py-2 px-4 flex items-center">
<div className="bg-background flex size-8 shrink-0 select-none items-center justify-center rounded-md">
<Avatar name={chatAuthor?.name} avatar={chatAuthor?.avatar} />
</div>
<div className="flex-1 px-1 ml-2 overflow-hidden">
<p className="leading-normal">
Code author:{' '}
<span className="font-medium">{chatAuthor?.name ?? 'Unknown'}</span>
</p>
</div>
</Card>
);
}
// 4. No author, Viewer not logged in
if (!userId && !authorId) {
return (
<Card className="group py-2 px-4 flex items-center">
<div className="bg-background flex size-8 shrink-0 select-none items-center justify-center rounded-md">
<IconExclamationTriangle className="font-medium" />
</div>
<div className="flex-1 px-1 ml-2 overflow-hidden">
<p className="leading-normal font-medium">
<Link href="/sign-in" className="underline">
Sign in
</Link>{' '}
to save and revisit your chat history!
</p>
</div>
</Card>
);
}
return null;
}
|