added history to page

This commit is contained in:
Dhravya Shah 2024-07-20 22:35:23 -05:00
parent a45f785146
commit c24b8728ed
3 changed files with 56 additions and 1 deletions

View file

@ -0,0 +1,53 @@
import { getChatHistory } from '@repo/web/app/actions/fetchers';
import { ArrowLongRightIcon } from '@heroicons/react/24/outline';
import { Skeleton } from '@repo/ui/shadcn/skeleton';
import Link from 'next/link';
import { memo, useEffect, useState } from 'react';
import { motion } from 'framer-motion';
import { chatThreads } from '@/server/db/schema';
const History = memo(() => {
const [chatThreads_, setChatThreads] = useState<
(typeof chatThreads.$inferSelect)[] | null
>(null);
useEffect(() => {
(async () => {
const chatThreads = await getChatHistory();
if (!chatThreads.success || !chatThreads.data) {
console.error(chatThreads.error);
return;
}
setChatThreads(chatThreads.data.reverse().slice(0, 3));
})();
}, []);
if (!chatThreads) {
return (
<>
<Skeleton className="w-[80%] h-4 bg-[#3b444b] "></Skeleton>
<Skeleton className="w-[40%] h-4 bg-[#3b444b] "></Skeleton>
<Skeleton className="w-[60%] h-4 bg-[#3b444b] "></Skeleton>
</>
);
}
return (
<ul className="text-base list-none space-y-3 text-[#b9b9b9] mt-8">
{chatThreads_?.map((thread) => (
<motion.li
initial={{ opacity: 0, filter: 'blur(1px)' }}
animate={{ opacity: 1, filter: 'blur(0px)' }}
className="flex items-center gap-2 truncate"
>
<ArrowLongRightIcon className="h-5" />{' '}
<Link prefetch={false} href={`/chat/${thread.id}`}>
{thread.firstMessage}
</Link>
</motion.li>
))}
</ul>
);
});
export default History;

View file

@ -10,6 +10,7 @@ import { motion } from "framer-motion";
import { ChromeIcon, GithubIcon, TwitterIcon } from "lucide-react";
import Link from "next/link";
import { homeSearchParamsCache } from "@/lib/searchParams";
import History from "./history";
const slap = {
initial: {
@ -121,6 +122,8 @@ function Page({ searchParams }: { searchParams: Record<string, string> }) {
}}
initialSpaces={spaces}
/>
<History />
</div>
<div className="w-full fixed bottom-0 left-0 p-4">

View file

@ -235,7 +235,6 @@ export const getChatHistory = async (): ServerActionReturnType<
if (!data || !data.user || !data.user.id) {
redirect("/signin");
return { error: "Not authenticated", success: false };
}
try {