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
Error fetching chat threads
; + } -function Header() { return (
@@ -22,10 +30,33 @@ function Header() {
- +
+ + +
+ + +
+
+ {chatThreads.data.map((thread) => ( + + {thread.firstMessage} + + ))} +
+
+
+
); 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": [