From 6ad77faaa874616f83161f217ee46bab4487ad6d Mon Sep 17 00:00:00 2001 From: mrevanzak Date: Sun, 30 Jun 2024 12:31:48 +0700 Subject: [PATCH] fix: on new chat doesnt create new chat room --- apps/web/src/app/(app)/@user/card.tsx | 4 ++-- apps/web/src/components/sidebar/sidebar-user.tsx | 7 +++++-- packages/ui/src/chat.tsx | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/web/src/app/(app)/@user/card.tsx b/apps/web/src/app/(app)/@user/card.tsx index 57566cb..74cf2d7 100644 --- a/apps/web/src/app/(app)/@user/card.tsx +++ b/apps/web/src/app/(app)/@user/card.tsx @@ -21,7 +21,7 @@ export function ChatCard() { const { data } = api.chat.show.useQuery( { id: searchParams.get("id") ?? "" }, - { enabled: searchParams.has("id") }, + { enabled: searchParams.has("id") && !searchParams.has("new") }, ); const initialMessages = data?.messages as Message[] | undefined; @@ -35,7 +35,7 @@ export function ChatCard() { onFinish={() => utils.chat.get.invalidate()} initialMessages={initialMessages} placeholder={"/ : " + t("chooseTopic")} - id={data?.id} + id={searchParams.get("id") ?? undefined} /> diff --git a/apps/web/src/components/sidebar/sidebar-user.tsx b/apps/web/src/components/sidebar/sidebar-user.tsx index acb44c6..e5cfbac 100644 --- a/apps/web/src/components/sidebar/sidebar-user.tsx +++ b/apps/web/src/components/sidebar/sidebar-user.tsx @@ -1,7 +1,7 @@ "use client"; import { useState } from "react"; -import { useRouter } from "next/navigation"; +import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { Drawer, DrawerContent, DrawerTrigger } from "@/components/drawer"; import { HistoryList } from "@/components/history-list"; import { api } from "@/trpc/react"; @@ -59,6 +59,7 @@ function Content() { export function SidebarUser() { const [open, setOpen] = useState(false); const router = useRouter(); + const searchParams = useSearchParams(); const isMobile = useMediaQuery("(max-width: 768px)"); const t = useTranslations("Home.history"); @@ -114,7 +115,9 @@ export function SidebarUser() { className="relative min-w-10 justify-start overflow-clip px-0 transition-all group-data-[open=true]:min-w-20 group-data-[open=false]:-translate-x-3.5" onClick={() => { setOpen(false); - router.push("/"); + searchParams.has("id") + ? router.push("/") + : router.push(`/?id=${crypto.randomUUID()}&new`); }} > diff --git a/packages/ui/src/chat.tsx b/packages/ui/src/chat.tsx index a19d791..a2d5e3c 100644 --- a/packages/ui/src/chat.tsx +++ b/packages/ui/src/chat.tsx @@ -63,7 +63,7 @@ export function Chat({ sendExtraMessageFields: true, onFinish, initialMessages, - id, + id: chatId, }); const chatContainerRef = useChatScroll(messages);