import { useQuery } from "@tanstack/react-query" import { PageAssitDatabase, formatToChatHistory, formatToMessage } from "~libs/db" import { Empty, Skeleton } from "antd" import { useMessageOption } from "~hooks/useMessageOption" type Props = {} export const Sidebar = ({}: Props) => { const { setMessages, setHistory, setHistoryId } = useMessageOption() const { data: chatHistories, status } = useQuery({ queryKey: ["fetchChatHistory"], queryFn: async () => { const db = new PageAssitDatabase() const history = await db.getChatHistories() return history } }) return (
{status === "success" && chatHistories.length === 0 && (
)} {status === "pending" && (
)} {status === "error" && (
Error loading history
)} {status === "success" && chatHistories.length > 0 && (
{chatHistories.map((chat, index) => ( ))}
)}
) }