Skip to content

Commit

Permalink
fix: on new chat doesnt create new chat room
Browse files Browse the repository at this point in the history
  • Loading branch information
mrevanzak committed Jun 30, 2024
1 parent 6589559 commit 6ad77fa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions apps/web/src/app/(app)/@user/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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}
/>
</CardContent>
<CardFooter>
Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/components/sidebar/sidebar-user.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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`);
}}
>
<FaPlus className="translate-x-3/4 transition-all" />
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function Chat({
sendExtraMessageFields: true,
onFinish,
initialMessages,
id,
id: chatId,
});
const chatContainerRef = useChatScroll(messages);

Expand Down

0 comments on commit 6ad77fa

Please sign in to comment.