Skip to content

Commit f7e6041

Browse files
committed
[Nebula] Fix page not redirected to new chat page when deleting active chat (#5712)
Fixes: DASH-613 <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on refactoring the usage of the `newChatPageUrlStore` by introducing a custom hook, `useNewChatPageLink`, to manage the chat page URL more effectively across different components. ### Detailed summary - Added `useNewChatPageLink` hook in `useNewChatPageLink.ts` to retrieve the chat page URL. - Updated imports of `useNewChatPageLink` in `NebulaMobileNav.tsx`, `ChatSidebarLink.tsx`, and `ChatSidebar.tsx`. - Removed duplicate `useNewChatPageLink` function from `ChatSidebar.tsx`. - Set `newChatPageUrlStore` value directly in `ChatPageContent.tsx` based on the current page type. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 0842045 commit f7e6041

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,13 @@ export function ChatPageContent(props: {
6666
// update page URL without reloading
6767
window.history.replaceState({}, "", `/chat/${sessionId}`);
6868

69-
const url = new URL(window.location.origin);
70-
7169
// if the current page is landing page, link to /chat
7270
// if current page is new /chat page, link to landing page
7371
if (props.type === "landing") {
74-
url.pathname = "/chat";
72+
newChatPageUrlStore.setValue("/chat");
7573
} else {
76-
url.pathname = "/";
74+
newChatPageUrlStore.setValue("/");
7775
}
78-
79-
newChatPageUrlStore.setValue(url.href);
8076
}
8177

8278
const messagesEndRef = useRef<HTMLDivElement>(null);

apps/dashboard/src/app/nebula-app/(app)/components/ChatSidebar.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
"use client";
22
import { ScrollShadow } from "@/components/ui/ScrollShadow/ScrollShadow";
33
import { Button } from "@/components/ui/button";
4-
import { useStore } from "@/lib/reactive";
54
import type { Account } from "@3rdweb-sdk/react/hooks/useApi";
65
import { ChevronRightIcon, MessageSquareDashedIcon } from "lucide-react";
76
import Link from "next/link";
87
import type { TruncatedSessionInfo } from "../api/types";
8+
import { useNewChatPageLink } from "../hooks/useNewChatPageLink";
99
import { useSessionsWithLocalOverrides } from "../hooks/useSessionsWithLocalOverrides";
1010
import { NebulaIcon } from "../icons/NebulaIcon";
11-
import { newChatPageUrlStore } from "../stores";
1211
import { ChatSidebarLink } from "./ChatSidebarLink";
1312
import { NebulaAccountButton } from "./NebulaAccountButton";
1413

@@ -80,8 +79,3 @@ export function ChatSidebar(props: {
8079
</div>
8180
);
8281
}
83-
84-
export function useNewChatPageLink() {
85-
const newChatPage = useStore(newChatPageUrlStore);
86-
return newChatPage || "/chat";
87-
}

apps/dashboard/src/app/nebula-app/(app)/components/ChatSidebarLink.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { EllipsisIcon, TrashIcon } from "lucide-react";
1414
import { usePathname } from "next/navigation";
1515
import { toast } from "sonner";
1616
import { deleteSession } from "../api/session";
17+
import { useNewChatPageLink } from "../hooks/useNewChatPageLink";
1718
import { deletedSessionsStore } from "../stores";
1819

1920
// TODO - add delete chat confirmation dialog
@@ -27,6 +28,7 @@ export function ChatSidebarLink(props: {
2728
const pathname = usePathname();
2829
const linkPath = `/chat/${props.sessionId}`;
2930
const isDeletingCurrentPage = pathname === linkPath;
31+
const newChatLink = useNewChatPageLink();
3032
const deleteChat = useMutation({
3133
mutationFn: () => {
3234
return deleteSession({
@@ -38,7 +40,7 @@ export function ChatSidebarLink(props: {
3840
const prev = deletedSessionsStore.getValue();
3941
deletedSessionsStore.setValue([...prev, props.sessionId]);
4042
if (isDeletingCurrentPage) {
41-
router.replace("/");
43+
router.replace(newChatLink);
4244
}
4345
},
4446
});

apps/dashboard/src/app/nebula-app/(app)/components/NebulaMobileNav.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { MenuIcon } from "lucide-react";
1212
import Link from "next/link";
1313
import { useState } from "react";
1414
import type { TruncatedSessionInfo } from "../api/types";
15-
import { ChatSidebar, useNewChatPageLink } from "./ChatSidebar";
15+
import { useNewChatPageLink } from "../hooks/useNewChatPageLink";
16+
import { ChatSidebar } from "./ChatSidebar";
1617

1718
export function MobileNav(props: {
1819
sessions: TruncatedSessionInfo[];
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use client";
2+
3+
import { useStore } from "@/lib/reactive";
4+
import { newChatPageUrlStore } from "../stores";
5+
6+
export function useNewChatPageLink() {
7+
const newChatPage = useStore(newChatPageUrlStore);
8+
return newChatPage || "/chat";
9+
}

0 commit comments

Comments
 (0)