From eea321f3ee4908db6f099d05f5f97c5c5098a783 Mon Sep 17 00:00:00 2001 From: codetorso Date: Fri, 19 Jul 2024 02:18:38 +0530 Subject: [PATCH] skeleton loaders for recent chats --- apps/web/app/(dash)/home/history.tsx | 50 ++++++++++++++++++++++++++++ apps/web/app/(dash)/home/page.tsx | 47 ++++---------------------- packages/ui/shadcn/skeleton.tsx | 15 +++++++++ 3 files changed, 71 insertions(+), 41 deletions(-) create mode 100644 apps/web/app/(dash)/home/history.tsx create mode 100644 packages/ui/shadcn/skeleton.tsx diff --git a/apps/web/app/(dash)/home/history.tsx b/apps/web/app/(dash)/home/history.tsx new file mode 100644 index 00000000..9c6757e5 --- /dev/null +++ b/apps/web/app/(dash)/home/history.tsx @@ -0,0 +1,50 @@ +import { getRecentChats } from "@/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"; + +const History = memo(() => { + const [chatThreads, setChatThreads] = useState(null); + + useEffect(() => { + (async () => { + const chatThreads = await getRecentChats(); + + // @ts-ignore + setChatThreads(chatThreads); + })(); + }, []); + + if (!chatThreads) { + return ( + <> + + + + + ); + } + + // @ts-ignore, time wastage + if (!chatThreads.success || !chatThreads.data) { + return
Error fetching chat threads
; + } + + return ( + + ); +}); + +export default History; \ No newline at end of file diff --git a/apps/web/app/(dash)/home/page.tsx b/apps/web/app/(dash)/home/page.tsx index 7572056a..2b9e3d63 100644 --- a/apps/web/app/(dash)/home/page.tsx +++ b/apps/web/app/(dash)/home/page.tsx @@ -1,9 +1,8 @@ "use client"; -import React, { Suspense, memo, use, useEffect, useState } from "react"; +import React, { useEffect, useState } from "react"; import QueryInput from "./queryinput"; import { - getRecentChats, getSessionAuthToken, getSpaces, } from "@/app/actions/fetchers"; @@ -11,8 +10,7 @@ import { useRouter } from "next/navigation"; import { createChatThread, linkTelegramToUser } from "@/app/actions/doers"; import { toast } from "sonner"; import { Heading } from "./heading"; -import { ArrowLongRightIcon } from "@heroicons/react/24/outline"; -import Link from "next/link"; +import History from "./history"; const linkTelegram = async (telegramUser: string) => { const response = await linkTelegramToUser(telegramUser); @@ -87,45 +85,12 @@ function Page({ initialSpaces={spaces} /> - +
+

Recent Searches

+ +
); } -const History = memo(() => { - const [chatThreads, setChatThreads] = useState(null); - - useEffect(() => { - (async () => { - const chatThreads = await getRecentChats(); - - setChatThreads(chatThreads); - })(); - }, []); - - if (!chatThreads){ - return
Loading
; - } - - if (!chatThreads.success || !chatThreads.data) { - return
Error fetching chat threads
; - } - - return ( -
-

Recent Searches

-
    - {chatThreads.data.map((thread) => ( -
  • - {" "} - - {thread.firstMessage} - -
  • - ))} -
-
- ); -}); - export default Page; diff --git a/packages/ui/shadcn/skeleton.tsx b/packages/ui/shadcn/skeleton.tsx new file mode 100644 index 00000000..001c280d --- /dev/null +++ b/packages/ui/shadcn/skeleton.tsx @@ -0,0 +1,15 @@ +import { cn } from "../lib/utils" + +function Skeleton({ + className, + ...props +}: React.HTMLAttributes) { + return ( +
+ ) +} + +export { Skeleton }