mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-09 03:18:04 +00:00
chathistory
This commit is contained in:
parent
dcf5cffdf0
commit
eee719651b
4 changed files with 70 additions and 9 deletions
|
|
@ -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>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
database_name = "dev-d1-anycontext"
|
||||
database_id = "fc562605-157a-4f60-b439-2a24ffed5b4c"
|
||||
|
|
@ -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": [
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue