import "@mantine/core/styles.css"; import { navigate } from "vike/client/router"; import { AppShell, Burger, Group, Image, MantineProvider, NavLink, } from "@mantine/core"; import { IconHome2, IconChevronRight, IconActivity, IconTrash, IconCircle, IconCircleFilled, IconTrashFilled, IconPlus, } from "@tabler/icons-react"; import { useDisclosure } from "@mantine/hooks"; import theme from "./theme.js"; import logoUrl from "../assets/logo.svg"; import { useStore } from "../state.js"; import { useEffect } from "react"; import { trpc } from "../trpc/client.js"; import { usePageContext } from "vike-react/usePageContext"; import "./hover.css"; import type { ConversationsId } from "../database/generated/public/Conversations.js"; export default function LayoutDefault({ children, }: { children: React.ReactNode }) { const pageContext = usePageContext(); const { urlPathname } = pageContext; const [opened, { toggle }] = useDisclosure(); const conversations = useStore((state) => state.conversations); const setConversations = useStore((state) => state.setConversations); const addConversation = useStore((state) => state.addConversation); const removeConversation = useStore((state) => state.removeConversation); const conversationId = useStore((state) => state.selectedConversationId); useEffect(() => { trpc.chat.listConversations.query().then((res) => { setConversations(res); }); }, [setConversations]); // useEffect(() => { // if (isConversationListExpanded) { // trpc.chat.listConversations.query().then((res) => { // setConversations(res); // }); // } // }, [isConversationListExpanded]); function handleDeleteConversation(conversationId: ConversationsId) { removeConversation(conversationId); trpc.chat.deleteConversation.mutate({ id: conversationId }); } return ( {" "} {" "} } rightSection={ <> { e.preventDefault(); e.stopPropagation(); trpc.chat.createConversation.mutate().then((res) => { if (!res?.id) return; addConversation(res); navigate(`/chat/${res.id}`); }); }} /> } variant="subtle" active={urlPathname.startsWith("/chat")} > {conversations.map((conversation) => ( } rightSection={ <> { e.stopPropagation(); e.preventDefault(); handleDeleteConversation(conversation.id); }} className="show-by-default" /> { e.stopPropagation(); e.preventDefault(); handleDeleteConversation(conversation.id); }} className="show-on-hover border-on-hover" /> } variant="subtle" active={conversation.id === conversationId} /> ))} {children} ); }