feat(navigation): add favorite entry and Menu tab

This commit is contained in:
Codex
2026-07-22 19:31:06 +08:00
parent 318e4991be
commit 469512df18
23 changed files with 794 additions and 118 deletions
+1 -8
View File
@@ -38,7 +38,6 @@ import {
} from "./chat-image-overlay-url";
import {
deriveIsGuest,
shouldStartExternalBrowserPrompt,
} from "./chat-screen.helpers";
import { useFirstRechargeOfferBanner } from "./hooks/use-first-recharge-offer-banner";
import { useChatUnlockCoordinator } from "./hooks/use-chat-unlock-coordinator";
@@ -118,12 +117,6 @@ export function ChatScreen() {
});
const shouldShowPwaInstall =
state.historyLoaded && state.historyMessages.length >= 10;
const shouldShowBrowserHint = shouldStartExternalBrowserPrompt({
hasInitialized: authState.hasInitialized,
isLoading: authState.isLoading,
loginStatus: authState.loginStatus,
});
useChatGuestLogin({
dispatch: authDispatch,
hasInitialized: authState.hasInitialized,
@@ -276,13 +269,13 @@ export function ChatScreen() {
<div className="relative z-1 flex min-h-0 flex-[1_1_auto] flex-col">
<ChatHeader
isGuest={isGuest}
showBrowserHint={shouldShowBrowserHint}
offerBanner={
<FirstRechargeOfferBanner
visible={firstRechargeOfferBanner.visible}
discountPercent={firstRechargeOfferBanner.discountPercent}
onClick={firstRechargeOfferBanner.claim}
onClose={firstRechargeOfferBanner.close}
variant="compact"
/>
}
/>
@@ -242,12 +242,6 @@ describe("chat Tailwind components", () => {
const memberHtml = renderWithCharacter(
<ChatHeader isGuest={false} offerBanner={<div>Offer</div>} />,
);
const memberWithHintHtml = renderWithCharacter(
<ChatHeader isGuest={false} showBrowserHint />,
);
const guestWithHintHtml = renderWithCharacter(
<ChatHeader isGuest={true} showBrowserHint />,
);
expect(guestHtml).toContain('aria-label="Sign up to unlock more features"');
expect(guestHtml).toContain("bg-accent");
@@ -257,50 +251,33 @@ describe("chat Tailwind components", () => {
expect(guestHtml).toContain('data-analytics-key="chat.back_to_home"');
expect(guestHtml).toContain("px-(--chat-inline-padding,16px)");
expect(guestHtml).not.toContain('aria-label="Profile"');
expect(guestHtml).toContain('aria-label="Save CozSweet"');
expect(memberHtml).toContain("Offer");
expect(memberHtml).toContain('href="/characters/elio/splash"');
expect(memberHtml).toContain('aria-label="Back to home"');
expect(memberHtml).toContain('aria-label="Profile"');
expect(memberHtml).toContain('data-analytics-key="chat.open_profile"');
expect(memberHtml).toContain('aria-label="Save CozSweet"');
expect(memberHtml).toContain('data-analytics-key="favorite.favorite"');
expect(memberHtml).toContain('data-analytics-key="chat.back_to_home"');
expect(memberHtml).toContain("px-(--chat-inline-padding,16px)");
expect(memberHtml).not.toContain("px-(--spacing-md,12px)");
expect(memberHtml).toContain("bg-[rgba(13,11,20,0.7)]");
expect(memberHtml).toContain("size-(--responsive-icon-button-size,42px)");
expect(memberHtml).toContain("lucide-user-round");
expect(memberWithHintHtml).toContain(
'data-analytics-key="chat.external_browser_hint"',
);
expect(memberWithHintHtml).toContain(
expect(memberHtml).toContain(
"grid-cols-[auto_minmax(0,1fr)_auto]",
);
expect(memberWithHintHtml.indexOf('aria-label="Back to home"')).toBeLessThan(
memberWithHintHtml.indexOf(
'data-analytics-key="chat.external_browser_hint"',
),
);
expect(
memberWithHintHtml.indexOf(
'data-analytics-key="chat.external_browser_hint"',
),
).toBeLessThan(memberWithHintHtml.indexOf('aria-label="Profile"'));
expect(guestWithHintHtml).not.toContain(
expect(memberHtml).not.toContain(
'data-analytics-key="chat.external_browser_hint"',
);
});
it("renders the user avatar in the ChatHeader Profile action", () => {
it("replaces the ChatHeader Profile avatar with the favorite action", () => {
userMocks.avatarUrl = "/images/avatar/profile-user.png";
const html = renderWithCharacter(<ChatHeader isGuest={false} />);
expect(html).toContain("%2Fimages%2Favatar%2Fprofile-user.png");
expect(html).toContain('aria-label="Profile"');
expect(html).toContain('data-analytics-key="chat.open_profile"');
expect(html).toContain(
"var(--responsive-icon-button-size, 42px)",
);
expect(html).not.toContain("lucide-user-round");
expect(html).not.toContain("%2Fimages%2Favatar%2Fprofile-user.png");
expect(html).not.toContain('aria-label="Profile"');
expect(html).not.toContain('data-analytics-key="chat.open_profile"');
expect(html).toContain('aria-label="Save CozSweet"');
expect(html).toContain("lucide-star");
});
it("links guest chat back to the active character splash", () => {
@@ -315,6 +292,7 @@ describe("chat Tailwind components", () => {
expect(html).toContain('href="/characters/maya/splash"');
expect(html).not.toContain('aria-label="Profile"');
expect(html).toContain('aria-label="Save CozSweet"');
expect(html).not.toContain(
'data-analytics-key="chat.external_browser_hint"',
);
+16 -52
View File
@@ -2,37 +2,31 @@
/**
* ChatHeader 顶部栏
*
* Profile 优先展示用户头像;头像缺失时回退到 lucide-react <UserRound />
* 顶部保持返回、首充优惠、收藏入口三段结构
*/
import type { ReactNode } from "react";
import { Lock, UserRound } from "lucide-react";
import { Lock } from "lucide-react";
import { BackButton, UserMessageAvatar } from "@/app/_components";
import { useActiveCharacterRoutes } from "@/providers/character-provider";
import { buildGlobalPageUrl } from "@/router/global-route-context";
import { ROUTES } from "@/router/routes";
import { BackButton } from "@/app/_components";
import { FavoriteEntryButton } from "@/app/_components/core";
import {
useActiveCharacter,
useActiveCharacterRoutes,
} from "@/providers/character-provider";
import { useAppNavigator } from "@/router/use-app-navigator";
import { useUserSelector } from "@/stores/user/user-context";
import { BrowserHintOverlay } from "./browser-hint-overlay";
export interface ChatHeaderProps {
isGuest: boolean;
offerBanner?: ReactNode;
showBrowserHint?: boolean;
}
export function ChatHeader({
isGuest,
offerBanner,
showBrowserHint = false,
}: ChatHeaderProps) {
const navigator = useAppNavigator();
const character = useActiveCharacter();
const characterRoutes = useActiveCharacterRoutes();
const avatarUrl = useUserSelector((state) => state.context.avatarUrl);
const handleOpenProfile = () => {
navigator.push(buildGlobalPageUrl(ROUTES.profile, characterRoutes.chat));
};
return (
<header className="flex shrink-0 flex-col items-stretch bg-transparent p-0">
@@ -52,17 +46,9 @@ export function ChatHeader({
/>
<span>Sign up to unlock more features</span>
</button>
) : (
offerBanner
)}
) : null}
<div
className={
isGuest
? "flex items-center px-(--chat-inline-padding,16px) py-(--spacing-sm,8px)"
: "grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-(--spacing-sm,8px) px-(--chat-inline-padding,16px) py-(--spacing-sm,8px)"
}
>
<div className="grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-(--spacing-sm,8px) px-(--chat-inline-padding,16px) py-(--spacing-sm,8px)">
<BackButton
href={characterRoutes.splash}
variant="dark"
@@ -70,34 +56,12 @@ export function ChatHeader({
analyticsKey="chat.back_to_home"
/>
{!isGuest ? (
<>
<div className="flex min-w-0 justify-center">
{showBrowserHint ? <BrowserHintOverlay /> : null}
</div>
<div className="flex min-w-0 justify-center">{offerBanner}</div>
{avatarUrl ? (
<UserMessageAvatar
avatarUrl={avatarUrl}
size="var(--responsive-icon-button-size, 42px)"
actionLabel="Profile"
analyticsKey="chat.open_profile"
onClick={handleOpenProfile}
/>
) : (
<button
type="button"
data-analytics-key="chat.open_profile"
data-analytics-label="Open profile"
className="flex size-(--responsive-icon-button-size,42px) cursor-pointer items-center justify-center rounded-full border border-[rgba(255,255,255,0.12)] bg-[rgba(13,11,20,0.7)] text-(--color-text-primary,#fff) shadow-[0_10px_24px_rgba(0,0,0,0.2)] backdrop-blur-md transition-[background,transform] duration-150 hover:bg-[rgba(28,24,39,0.82)] active:scale-96 focus-visible:outline-2 focus-visible:outline-offset-3 focus-visible:outline-[#f657a0]"
onClick={handleOpenProfile}
aria-label="Profile"
>
<UserRound size={24} aria-hidden="true" />
</button>
)}
</>
) : null}
<FavoriteEntryButton
characterSlug={character.slug}
tone="dark"
/>
</div>
</header>
);
@@ -121,8 +121,73 @@
cursor: pointer;
}
.compactButton {
display: grid;
min-width: 0;
max-width: 224px;
min-height: 44px;
grid-template-columns: auto minmax(0, 1fr) auto;
align-items: center;
gap: 7px;
padding: 5px 8px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.42);
border-radius: 16px;
background:
radial-gradient(circle at 15% 0%, rgba(255, 255, 255, 0.68), transparent 38%),
linear-gradient(135deg, #fff0b8 0%, #ffd0df 50%, #ff6cab 100%);
color: #2c111d;
cursor: pointer;
font: inherit;
text-align: left;
box-shadow: 0 9px 24px rgba(114, 21, 63, 0.2);
animation: firstRechargeBannerIn 260ms ease-out both;
}
.compactIcon {
display: inline-flex;
width: 28px;
height: 28px;
align-items: center;
justify-content: center;
border-radius: 10px;
background: rgba(255, 255, 255, 0.55);
color: #f90073;
}
.compactCopy {
display: flex;
min-width: 0;
flex-direction: column;
gap: 2px;
font-size: 10px;
font-weight: 800;
line-height: 1.05;
text-transform: uppercase;
}
.compactCopy span,
.compactCopy strong {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.compactCopy span {
color: rgba(44, 17, 29, 0.68);
letter-spacing: 0.03em;
}
.compactCopy strong {
color: #ec006d;
font-size: 15px;
font-weight: 950;
letter-spacing: -0.02em;
}
.contentButton:focus-visible,
.closeButton:focus-visible {
.closeButton:focus-visible,
.compactButton:focus-visible {
outline: 2px solid rgba(255, 255, 255, 0.94);
outline-offset: -3px;
}
@@ -144,4 +209,14 @@
flex-direction: column;
gap: 2px;
}
.compactButton {
gap: 5px;
padding-inline: 6px;
}
.compactIcon {
width: 26px;
height: 26px;
}
}
@@ -9,6 +9,7 @@ export interface FirstRechargeOfferBannerProps {
discountPercent: number;
onClick: () => void;
onClose: () => void;
variant?: "banner" | "compact";
}
export function FirstRechargeOfferBanner({
@@ -16,9 +17,32 @@ export function FirstRechargeOfferBanner({
discountPercent,
onClick,
onClose,
variant = "banner",
}: FirstRechargeOfferBannerProps) {
if (!visible) return null;
if (variant === "compact") {
return (
<button
type="button"
data-analytics-key="chat.first_recharge_offer"
data-analytics-label="Open first recharge offer"
className={styles.compactButton}
aria-label={`First recharge offer, ${discountPercent}% off`}
onClick={onClick}
>
<span className={styles.compactIcon} aria-hidden="true">
<Sparkles size={14} strokeWidth={2.4} />
</span>
<span className={styles.compactCopy}>
<span>First recharge</span>
<strong>{discountPercent}% OFF</strong>
</span>
<ChevronRight size={14} strokeWidth={2.4} aria-hidden="true" />
</button>
);
}
return (
<section className={styles.banner} aria-label="First recharge offer">
<button