Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: add empty screen with prompts

Marc Seitz2f86624cf869
diff --git a/components/chat/chat-input.tsx b/components/chat/chat-input.tsx
index 05ffb4d1..e0a3b8ca 100644
--- a/components/chat/chat-input.tsx
+++ b/components/chat/chat-input.tsx
@@ -11,6 +11,7 @@ export function ChatInput({
status,
error,
input,
+ setInput,
handleInputChange,
submitMessage,
messages,
@@ -18,6 +19,7 @@ export function ChatInput({
status: AssistantStatus;
error: unknown;
input: string;
+ setInput: (input: string) => void;
handleInputChange: (e: any) => void;
submitMessage: (e: any) => Promise<void>;
messages: Message[];
@@ -51,7 +53,6 @@ export function ChatInput({
<div className="absolute bottom-3 right-3">
<Button
type="submit"
- // size="icon"
disabled={status === "in_progress" || input === ""}
title="Send message"
className="rounded-md p-1 md:p-2 h-10 w-10"
diff --git a/components/chat/chat-list.tsx b/components/chat/chat-list.tsx
index b840df70..a6434cb1 100644
--- a/components/chat/chat-list.tsx
+++ b/components/chat/chat-list.tsx
@@ -16,7 +16,7 @@ export function ChatList({ messages, status }: ChatList) {
}
return (
- <div className="relative mx-auto max-w-xl px-4">
+ <div className="relative mx-auto max-w-2xl px-4">
{messages.map((message, index) => (
<div key={index}>
<ChatMessage message={message} />
@@ -30,7 +30,7 @@ export function ChatList({ messages, status }: ChatList) {
<Separator className="my-4 bg-background" />
<div
key={"loading-message"}
- className="group relative mb-4 flex items-start md:-ml-12 whitespace-pre-wrap"
+ className="group relative mb-4 flex items-start ml-5 whitespace-pre-wrap"
>
<div className="flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-md border shadow bg-primary text-primary-foreground">
<PapermarkSparkle />
diff --git a/components/chat/chat-message.tsx b/components/chat/chat-message.tsx
index e6d0ae1e..6218922e 100644
--- a/components/chat/chat-message.tsx
+++ b/components/chat/chat-message.tsx
@@ -14,7 +14,7 @@ export function ChatMessage({ message, ...props }: ChatMessageProps) {
<div
key={message.id}
className={cn(
- "group relative mb-4 flex items-start md:-ml-12 whitespace-pre-wrap",
+ "group relative mb-4 flex items-start md:ml-5 whitespace-pre-wrap",
)}
{...props}
>
diff --git a/components/chat/chat.tsx b/components/chat/chat.tsx
index 415fcc7e..a7a9d342 100644
--- a/components/chat/chat.tsx
+++ b/components/chat/chat.tsx
@@ -6,23 +6,28 @@ import {
} from "ai/react";
import { cn } from "@/lib/utils";
-import { ChatList } from "@/components/chat/chat-list";
-import { ChatInput } from "@/components/chat/chat-input";
-// import { EmptyScreen } from "@/components/empty-screen";
-import { ChatScrollAnchor } from "@/components/chat/chat-scroll-anchor";
+import { ChatList } from "./chat-list";
+import { ChatInput } from "./chat-input";
+import { ChatScrollAnchor } from "./chat-scroll-anchor";
+import { EmptyScreen } from "./empty-screen";
import { useEffect, useState } from "react";
-import Sparkle from "../shared/icons/sparke";
export interface ChatProps extends React.ComponentProps<"div"> {
initialMessages: Message[];
threadId: string;
+ firstPage: string;
}
-export function Chat({ initialMessages, threadId, className }: ChatProps) {
+export function Chat({
+ initialMessages,
+ threadId,
+ firstPage,
+ className,
+}: ChatProps) {
const {
status,
messages: hookMessages,
- input,
+ input: hookInput,
submitMessage,
handleInputChange,
error,
@@ -47,51 +52,33 @@ export function Chat({ initialMessages, threadId, className }: ChatProps) {
isLoading = true;
}
+ const [_, setInput] = useState<string>(hookInput);
+
return (
<>
- <Nav />
<div className={cn("pb-[100px] pt-24", className)}>
{combinedMessages.length ? (
<>
<ChatList messages={combinedMessages} status={status} />
<ChatScrollAnchor trackVisibility={isLoading} />
</>
- ) : // <EmptyScreen handleInputChange={handleInputChange} />
- null}
+ ) : (
+ <EmptyScreen
+ firstPage={firstPage}
+ handleInputChange={handleInputChange}
+ setInput={setInput}
+ />
+ )}
</div>
<ChatInput
status={status}
error={error}
messages={combinedMessages}
- input={input}
+ input={hookInput}
+ setInput={setInput}
submitMessage={submitMessage}
handleInputChange={handleInputChange}
/>
</>
);
}
-
-function Nav() {
- return (
- <nav className="bg-black fixed top-0 inset-x-0 z-10">
- <div className="mx-auto px-2 sm:px-6 lg:px-8">
- <div className="relative flex h-16 items-center justify-between">
- <div className="flex flex-1 items-center justify-center sm:items-stretch sm:justify-start">
- <div className="flex flex-shrink-0 items-center gap-x-2">
- <p className="text-2xl font-bold tracking-tighter text-white">
- Papermark
- </p>
- <Sparkle className="h-5 w-5 text-white" />
- </div>
- </div>
- <div className="absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0">
- <div className="bg-gray-900 text-white rounded-md px-3 py-2 text-sm font-medium">
- {/* <span>{pageNumber}</span>
- <span className="text-gray-400"> / {numPages}</span> */}
- </div>
- </div>
- </div>
- </div>
- </nav>
- );
-}
diff --git a/components/chat/empty-screen.tsx b/components/chat/empty-screen.tsx
new file mode 100644
index 00000000..56d46f95
--- /dev/null
+++ b/components/chat/empty-screen.tsx
@@ -0,0 +1,76 @@
+import { Button } from "@/components/ui/button";
+import Image from "next/image";
+
+const exampleMessages = [
+ {
+ heading: "Summarize the document",
+ message: "Summarize the document in a few sentences and bullet points.",
+ },
+ {
+ heading: "Tell me about the team",
+ message:
+ "Tell me more about the team behind the company. If there's no team page in the document, then let me know.",
+ },
+ {
+ heading: "Ask a question",
+ message: "What does the company do?",
+ },
+ {
+ heading: "What is this document about?",
+ message: "Please tell me in one sentence what this document is about.",
+ },
+];
+
+export function EmptyScreen({
+ firstPage,
+ setInput,
+ handleInputChange,
+}: {
+ firstPage: string;
+ setInput: (input: string) => void;
+ handleInputChange: (e: any) => void;
+}) {
+ const manageInput = (message: string) => {
+ console.log(message);
+ setInput(message);
+ handleInputChange(message);
+ };
+
+ return (
+ <>
+ <div className="mx-auto w-1/2 md:w-1/3">
+ <div className="flex items-center justify-center">
+ <Image
+ src={firstPage}
+ width={768}
+ height={100}
+ className="object-contain rounded-md ring-1 ring-gray-700"
+ alt="First page of the document"
+ />
+ </div>
+ <div className="flex justify-center text-lg mt-4">
+ What would you like to know?
+ </div>
+ </div>
+ <div className="mx-auto max-w-2xl px-4 fixed bottom-28 inset-x-0">
+ <div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
+ {exampleMessages.map((message, index) => (
+ <Button
+ key={index}
+ variant="outline"
+ className="h-auto p-4 text-sm"
+ onClick={() => {
+ console.log(message.message);
+ return handleInputChange({
+ target: { value: message.message },
+ });
+ }}
+ >
+ {message.heading}
+ </Button>
+ ))}
+ </div>
+ </div>
+ </>
+ );
+}
diff --git a/pages/view/[linkId]/chat.tsx b/pages/view/[linkId]/chat.tsx
index c11bde77..5200debf 100644
--- a/pages/view/[linkId]/chat.tsx
+++ b/pages/view/[linkId]/chat.tsx
@@ -4,6 +4,7 @@ import { getServerSession } from "next-auth";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { CustomUser } from "@/lib/types";
import { Chat } from "@/components/chat/chat";
+import Sparkle from "@/components/shared/icons/sparke";
export const getServerSideProps = async (context: any) => {
const { linkId } = context.params;
@@ -18,17 +19,34 @@ export const getServerSideProps = async (context: any) => {
};
}
- const document = await prisma.link.findUnique({
+ const link = await prisma.link.findUnique({
where: { id: linkId },
select: {
document: {
select: {
id: true,
+ versions: {
+ where: { isPrimary: true },
+ select: {
+ pages: {
+ where: { pageNumber: 1 },
+ select: {
+ file: true,
+ },
+ },
+ },
+ },
},
},
},
});
+ if (!link) {
+ return {
+ notFound: true,
+ };
+ }
+
// create or fetch threadId
const res = await fetch(
`${process.env.NEXTAUTH_URL}/api/assistants/threads`,
@@ -38,7 +56,7 @@ export const getServerSideProps = async (context: any) => {
"Content-Type": "application/json",
},
body: JSON.stringify({
- documentId: document!.document.id,
+ documentId: link!.document.id,
userId: (session.user as CustomUser).id,
}),
},
@@ -52,16 +70,11 @@ export const getServerSideProps = async (context: any) => {
const { threadId, messages } = await res.json();
- if (!document) {
- return {
- notFound: true,
- };
- }
-
return {
props: {
threadId,
messages: messages || [],
+ firstPage: link.document.versions[0].pages[0].file,
},
};
};
@@ -69,15 +82,45 @@ export const getServerSideProps = async (context: any) => {
export default function ChatPage({
threadId,
messages,
+ firstPage,
}: {
threadId: string;
messages: Message[];
+ firstPage: string;
}) {
return (
<>
- <div>
- <Chat initialMessages={messages} threadId={threadId} />
- </div>
+ <Nav />
+ <Chat
+ initialMessages={messages}
+ threadId={threadId}
+ firstPage={firstPage}
+ />
</>
);
}
+
+function Nav() {
+ return (
+ <nav className="bg-black fixed top-0 inset-x-0 z-10">
+ <div className="mx-auto px-2 sm:px-6 lg:px-8">
+ <div className="relative flex h-16 items-center justify-between">
+ <div className="flex flex-1 items-center justify-center sm:items-stretch sm:justify-start">
+ <div className="flex flex-shrink-0 items-center gap-x-2">
+ <p className="text-2xl font-bold tracking-tighter text-white">
+ Papermark
+ </p>
+ <Sparkle className="h-5 w-5 text-white" />
+ </div>
+ </div>
+ <div className="absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0">
+ <div className="bg-gray-900 text-white rounded-md px-3 py-2 text-sm font-medium">
+ {/* <span>{pageNumber}</span>
+ <span className="text-gray-400"> / {numPages}</span> */}
+ </div>
+ </div>
+ </div>
+ </div>
+ </nav>
+ );
+}