File size: 2,200 Bytes
04735a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ba9285c
 
 
04735a9
ba9285c
04735a9
 
 
 
 
 
 
 
 
 
 
 
 
d360551
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
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 (
      <Card className="group py-2 px-4 flex flex-row items-center">
        <p className="leading-normal text-sm">Authored by</p>
        <div className="flex-1 px-1 ml-2 flex flex-row items-center space-x-2">
          <Avatar name={chatAuthor?.name} avatar={chatAuthor?.avatar} />
          <p className="font-medium">{chatAuthor?.name ?? 'Unknown'}</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">
            {process.env.NEXT_PUBLIC_IS_HUGGING_FACE ? (
              <Link
                href="https://va.landing.ai"
                target="_blank"
                className="underline"
              >
                Visit Landing AI{"'"}s website
              </Link>
            ) : (
              <Link href="/sign-in" className="underline">
                Sign in
              </Link>
            )}{' '}
            to save and revisit your chat history!
          </p>
        </div>
      </Card>
    );
  }
  return null;
}