diff --git a/apps/web/app/(dash)/home/history.tsx b/apps/web/app/(dash)/home/history.tsx new file mode 100644 index 00000000..3d8d5a28 --- /dev/null +++ b/apps/web/app/(dash)/home/history.tsx @@ -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 ( + <> + + + + + ); + } + + return ( + + ); +}); + +export default History; diff --git a/apps/web/app/(dash)/home/page.tsx b/apps/web/app/(dash)/home/page.tsx index 7bbe35c0..3d999e6b 100644 --- a/apps/web/app/(dash)/home/page.tsx +++ b/apps/web/app/(dash)/home/page.tsx @@ -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 }) { }} initialSpaces={spaces} /> + +
diff --git a/apps/web/app/actions/fetchers.ts b/apps/web/app/actions/fetchers.ts index 1838ee1c..7071ecb3 100644 --- a/apps/web/app/actions/fetchers.ts +++ b/apps/web/app/actions/fetchers.ts @@ -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 {