aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/web/app/(dash)/header.tsx41
-rw-r--r--apps/web/app/actions/fetchers.ts29
-rw-r--r--apps/web/wrangler.toml8
-rw-r--r--package.json1
4 files changed, 70 insertions, 9 deletions
diff --git a/apps/web/app/(dash)/header.tsx b/apps/web/app/(dash)/header.tsx
index 91c00125..7eb15c8b 100644
--- a/apps/web/app/(dash)/header.tsx
+++ b/apps/web/app/(dash)/header.tsx
@@ -5,8 +5,16 @@ import Logo from "../../public/logo.svg";
import { AddIcon, ChatIcon } from "@repo/ui/icons";
import DynamicIsland from "./dynamicisland";
+import { db } from "@/server/db";
+import { getChatHistory } from "../actions/fetchers";
+
+async function Header() {
+ const chatThreads = await getChatHistory();
+
+ if (!chatThreads.success || !chatThreads.data) {
+ return <div>Error fetching chat threads</div>;
+ }
-function Header() {
return (
<div className="p-4 relative z-30 h-16 flex items-center">
<div className="w-full flex items-center justify-between">
@@ -22,10 +30,33 @@ function Header() {
<DynamicIsland />
</div>
- <button className="flex duration-200 items-center text-[#7D8994] hover:bg-[#1F2429] text-[13px] gap-2 px-3 py-2 rounded-xl">
- <Image src={ChatIcon} alt="Chat icon" className="w-5" />
- Start new chat
- </button>
+ <div className="flex items-center gap-2">
+ <button className="flex duration-200 items-center text-[#7D8994] hover:bg-[#1F2429] text-[13px] gap-2 px-3 py-2 rounded-xl">
+ <Image src={ChatIcon} alt="Chat icon" className="w-5" />
+ Start new chat
+ </button>
+
+ <div className="relative group">
+ <button className="flex duration-200 items-center text-[#7D8994] hover:bg-[#1F2429] text-[13px] gap-2 px-3 py-2 rounded-xl">
+ History
+ </button>
+
+ <div className="absolute p-4 hidden group-hover:block right-0 max-h-svh overflow-auto">
+ <div className="bg-[#1F2429] rounded-xl p-2 flex flex-col shadow-lg">
+ {chatThreads.data.map((thread) => (
+ <Link
+ prefetch={false}
+ href={`/chat/${thread.id}`}
+ key={thread.id}
+ className="p-2 rounded-md hover:bg-secondary"
+ >
+ {thread.firstMessage}
+ </Link>
+ ))}
+ </div>
+ </div>
+ </div>
+ </div>
</div>
</div>
);
diff --git a/apps/web/app/actions/fetchers.ts b/apps/web/app/actions/fetchers.ts
index af11836e..664c20ac 100644
--- a/apps/web/app/actions/fetchers.ts
+++ b/apps/web/app/actions/fetchers.ts
@@ -4,6 +4,7 @@ import { and, asc, eq, inArray, not, sql } from "drizzle-orm";
import { db } from "../../server/db";
import {
chatHistory,
+ ChatThread,
chatThreads,
Content,
contentToSpace,
@@ -13,6 +14,7 @@ import {
import { ServerActionReturnType, Space } from "./types";
import { auth } from "../../server/auth";
import { ChatHistory, SourceZod } from "@repo/shared-types";
+import { ChatHistory as ChatHistoryType } from "../../server/db/schema";
import { z } from "zod";
import { redirect } from "next/navigation";
@@ -160,3 +162,30 @@ export const getFullChatThread = async (
data: accumulatedChatHistory,
};
};
+
+export const getChatHistory = async (): ServerActionReturnType<
+ ChatThread[]
+> => {
+ const data = await auth();
+
+ if (!data || !data.user || !data.user.id) {
+ redirect("/signin");
+ return { error: "Not authenticated", success: false };
+ }
+
+ try {
+ const chatHistorys = await db.query.chatThreads.findMany({
+ where: eq(chatThreads.userId, data.user.id),
+ });
+
+ return {
+ success: true,
+ data: chatHistorys,
+ };
+ } catch (e) {
+ return {
+ success: false,
+ error: (e as Error).message,
+ };
+ }
+};
diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml
index a2ac88d0..da9cd616 100644
--- a/apps/web/wrangler.toml
+++ b/apps/web/wrangler.toml
@@ -14,8 +14,8 @@ bucket_name = "dev-r2-anycontext"
[[d1_databases]]
binding = "DATABASE"
-database_name = "prod-d1-supermemory"
-database_id = "f527a727-c472-41d4-8eaf-3d7ba0f2f395"
+# database_name = "prod-d1-supermemory"
+# database_id = "f527a727-c472-41d4-8eaf-3d7ba0f2f395"
-# database_name = "dev-d1-anycontext"
-# database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" \ No newline at end of file
+database_name = "dev-d1-anycontext"
+database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c" \ No newline at end of file
diff --git a/package.json b/package.json
index 5fd9360a..c5cade74 100644
--- a/package.json
+++ b/package.json
@@ -93,6 +93,7 @@
"tailwind-scrollbar": "^3.1.0",
"tldraw": "^2.1.4",
"uploadthing": "^6.10.4",
+ "vaul": "^0.9.1",
"zod": "^3.23.8"
},
"trustedDependencies": [