fix(web): leave chat with a document load for chart, ephemeris, and reports
Independent Staging Quality Gate / validate (pull_request) Failing after 9m45s
Independent Staging Quality Gate / publish (pull_request) Skipped
Independent Staging Quality Gate / validate (push) Failing after 9m14s
Independent Staging Quality Gate / publish (push) Skipped

Session URLs are written with history.pushState, so App Router
router.push cannot leave the home page. Sidebar destinations now
assign the document and stash the current conversation for return.
This commit is contained in:
jesse-ux
2026-09-15 19:29:41 +08:00
parent 298a73e8e5
commit c6ecb86fb4
3 changed files with 26 additions and 9 deletions
+11 -6
View File
@@ -18,9 +18,10 @@ import {
UserRound,
Users,
} from "lucide-react";
import { usePathname, useRouter } from "next/navigation";
import { usePathname } from "next/navigation";
import { useEffect, useRef } from "react";
import type { Ref } from "react";
import { persistLoginSessionReturn } from "@/lib/chat-session-url";
import {
Sidebar,
SidebarContent,
@@ -102,7 +103,7 @@ export function AppSidebar({
sessionControls,
onAccountMenuOpenChange,
onNewChat,
onOpenReports,
onOpenReports: _onOpenReports,
onSelectSession,
onSelectChart,
onAddChart,
@@ -113,7 +114,6 @@ export function AppSidebar({
onOpenLogout,
}: AppSidebarProps) {
const { isMobile, setOpen, setOpenMobile, state, viewport } = useSidebar();
const router = useRouter();
const pathname = usePathname();
const firstSessionRef = useRef<HTMLButtonElement>(null);
const historyHeadingRef = useRef<HTMLElement>(null);
@@ -149,18 +149,23 @@ export function AppSidebar({
if (isMobile) setOpenMobile(false);
}
function leaveChat(path: "/chart" | "/ephemeris" | "/reports") {
persistLoginSessionReturn();
window.location.assign(path);
}
function handleOpenReports() {
onOpenReports();
leaveChat("/reports");
if (isMobile) setOpenMobile(false);
}
function handleOpenChart() {
router.push("/chart");
leaveChat("/chart");
if (isMobile) setOpenMobile(false);
}
function handleOpenEphemeris() {
router.push("/ephemeris");
leaveChat("/ephemeris");
if (isMobile) setOpenMobile(false);
}