refactor(router): introduce app navigation manager
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
*/
|
||||
import type { ReactNode } from "react";
|
||||
import { Lock, Menu } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { ROUTES } from "@/router/routes";
|
||||
import { useAppNavigator } from "@/router/use-app-navigator";
|
||||
|
||||
import styles from "./chat-header.module.css";
|
||||
|
||||
@@ -19,7 +19,7 @@ export interface ChatHeaderProps {
|
||||
}
|
||||
|
||||
export function ChatHeader({ isGuest, offerBanner }: ChatHeaderProps) {
|
||||
const router = useRouter();
|
||||
const navigator = useAppNavigator();
|
||||
|
||||
if (isGuest) {
|
||||
return (
|
||||
@@ -27,7 +27,7 @@ export function ChatHeader({ isGuest, offerBanner }: ChatHeaderProps) {
|
||||
<button
|
||||
type="button"
|
||||
className={styles.guestBanner}
|
||||
onClick={() => router.push(ROUTES.auth)}
|
||||
onClick={() => navigator.openAuth(ROUTES.chat)}
|
||||
aria-label="Sign up to unlock more features"
|
||||
>
|
||||
<Lock className={styles.guestBannerIcon} size={16} aria-hidden="true" />
|
||||
@@ -46,7 +46,7 @@ export function ChatHeader({ isGuest, offerBanner }: ChatHeaderProps) {
|
||||
<button
|
||||
type="button"
|
||||
className={styles.menuButton}
|
||||
onClick={() => router.push(ROUTES.sidebar)}
|
||||
onClick={() => navigator.push(ROUTES.sidebar)}
|
||||
aria-label="Menu"
|
||||
>
|
||||
<Menu className={styles.menuIcon} size={24} aria-hidden="true" />
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
* 不做的事:
|
||||
* - 不直接管理 state machine(chat 机器不感知 UI 层)
|
||||
*/
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import { ROUTE_BUILDERS } from "@/router/routes";
|
||||
import { useAppNavigator } from "@/router/use-app-navigator";
|
||||
|
||||
import styles from "./chat-insufficient-credits-banner.module.css";
|
||||
|
||||
@@ -26,7 +24,7 @@ export interface ChatInsufficientCreditsBannerProps {
|
||||
title?: string;
|
||||
ctaLabel?: string;
|
||||
/**
|
||||
* 自定义点击回调(不传则默认 router.push(topup subscription))
|
||||
* 自定义点击回调(不传则默认走统一订阅导航)
|
||||
* - 测试时可传 mock
|
||||
* - 嵌入其他场景时(如 nested overlay)可传自定义
|
||||
*/
|
||||
@@ -38,7 +36,7 @@ export function ChatInsufficientCreditsBanner({
|
||||
ctaLabel = "Top up credits to continue",
|
||||
onUnlock,
|
||||
}: ChatInsufficientCreditsBannerProps) {
|
||||
const router = useRouter();
|
||||
const navigator = useAppNavigator();
|
||||
const titleLines = title.split("\n");
|
||||
|
||||
const handleClick = () => {
|
||||
@@ -46,7 +44,7 @@ export function ChatInsufficientCreditsBanner({
|
||||
onUnlock();
|
||||
return;
|
||||
}
|
||||
router.push(ROUTE_BUILDERS.subscription("topup"));
|
||||
navigator.openSubscription({ type: "topup", returnTo: "chat" });
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user