Skip to content

[Nebula] Fix page not redirected to new chat page when deleting active chat #5712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,13 @@ export function ChatPageContent(props: {
// update page URL without reloading
window.history.replaceState({}, "", `/chat/${sessionId}`);

const url = new URL(window.location.origin);

// if the current page is landing page, link to /chat
// if current page is new /chat page, link to landing page
if (props.type === "landing") {
url.pathname = "/chat";
newChatPageUrlStore.setValue("/chat");
} else {
url.pathname = "/";
newChatPageUrlStore.setValue("/");
}

newChatPageUrlStore.setValue(url.href);
}

const messagesEndRef = useRef<HTMLDivElement>(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"use client";
import { ScrollShadow } from "@/components/ui/ScrollShadow/ScrollShadow";
import { Button } from "@/components/ui/button";
import { useStore } from "@/lib/reactive";
import type { Account } from "@3rdweb-sdk/react/hooks/useApi";
import { ChevronRightIcon, MessageSquareDashedIcon } from "lucide-react";
import Link from "next/link";
import type { TruncatedSessionInfo } from "../api/types";
import { useNewChatPageLink } from "../hooks/useNewChatPageLink";
import { useSessionsWithLocalOverrides } from "../hooks/useSessionsWithLocalOverrides";
import { NebulaIcon } from "../icons/NebulaIcon";
import { newChatPageUrlStore } from "../stores";
import { ChatSidebarLink } from "./ChatSidebarLink";
import { NebulaAccountButton } from "./NebulaAccountButton";

Expand Down Expand Up @@ -80,8 +79,3 @@ export function ChatSidebar(props: {
</div>
);
}

export function useNewChatPageLink() {
const newChatPage = useStore(newChatPageUrlStore);
return newChatPage || "/chat";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { EllipsisIcon, TrashIcon } from "lucide-react";
import { usePathname } from "next/navigation";
import { toast } from "sonner";
import { deleteSession } from "../api/session";
import { useNewChatPageLink } from "../hooks/useNewChatPageLink";
import { deletedSessionsStore } from "../stores";

// TODO - add delete chat confirmation dialog
Expand All @@ -27,6 +28,7 @@ export function ChatSidebarLink(props: {
const pathname = usePathname();
const linkPath = `/chat/${props.sessionId}`;
const isDeletingCurrentPage = pathname === linkPath;
const newChatLink = useNewChatPageLink();
const deleteChat = useMutation({
mutationFn: () => {
return deleteSession({
Expand All @@ -38,7 +40,7 @@ export function ChatSidebarLink(props: {
const prev = deletedSessionsStore.getValue();
deletedSessionsStore.setValue([...prev, props.sessionId]);
if (isDeletingCurrentPage) {
router.replace("/");
router.replace(newChatLink);
}
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { MenuIcon } from "lucide-react";
import Link from "next/link";
import { useState } from "react";
import type { TruncatedSessionInfo } from "../api/types";
import { ChatSidebar, useNewChatPageLink } from "./ChatSidebar";
import { useNewChatPageLink } from "../hooks/useNewChatPageLink";
import { ChatSidebar } from "./ChatSidebar";

export function MobileNav(props: {
sessions: TruncatedSessionInfo[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use client";

import { useStore } from "@/lib/reactive";
import { newChatPageUrlStore } from "../stores";

export function useNewChatPageLink() {
const newChatPage = useStore(newChatPageUrlStore);
return newChatPage || "/chat";
}
Loading