feat(profile)!: replace sidebar and add avatar navigation

Rename the global Sidebar route, UI, assets, analytics, and payment return context to Profile. Add accessible message-avatar navigation and preserve the source character across auth and logout flows.

BREAKING CHANGE: /sidebar has been removed; use /profile instead.
This commit is contained in:
2026-07-21 18:08:12 +08:00
parent 6cd3a0c2d2
commit 9deb320cf6
67 changed files with 565 additions and 256 deletions
@@ -79,4 +79,34 @@ describe("shared Tailwind components", () => {
expect(guestHtml).toContain('aria-label="Guest avatar"');
expect(guestHtml).toContain("%2Fimages%2Favatar%2Fplaceholder.png");
});
it("renders interactive avatars as accessible buttons", () => {
const characterHtml = renderToStaticMarkup(
<CharacterAvatar
src="/images/avatar/elio.png"
alt="Elio Silvestri"
actionLabel="Open Elio's private room"
analyticsKey="chat.open_private_room_from_avatar"
onClick={() => undefined}
/>,
);
const userHtml = renderToStaticMarkup(
<UserMessageAvatar
actionLabel="Open profile"
analyticsKey="chat.open_profile_from_avatar"
onClick={() => undefined}
/>,
);
expect(characterHtml).toContain('<button type="button"');
expect(characterHtml).toContain(
'aria-label="Open Elio&#x27;s private room"',
);
expect(characterHtml).toContain(
'data-analytics-key="chat.open_private_room_from_avatar"',
);
expect(userHtml).toContain('<button type="button"');
expect(userHtml).toContain('aria-label="Open profile"');
expect(userHtml).toContain("focus-visible:outline-3");
});
});
+11
View File
@@ -0,0 +1,11 @@
export type AvatarInteractionProps =
| {
onClick?: undefined;
actionLabel?: never;
analyticsKey?: never;
}
| {
onClick: () => void;
actionLabel: string;
analyticsKey?: string;
};
+47 -18
View File
@@ -3,7 +3,9 @@
import Image from "next/image";
import type { CSSProperties } from "react";
export interface CharacterAvatarProps {
import type { AvatarInteractionProps } from "./avatar-interaction";
interface CharacterAvatarVisualProps {
src: string;
alt: string;
className?: string;
@@ -12,6 +14,9 @@ export interface CharacterAvatarProps {
priority?: boolean;
}
export type CharacterAvatarProps = CharacterAvatarVisualProps &
AvatarInteractionProps;
export function CharacterAvatar({
src,
alt,
@@ -19,6 +24,9 @@ export function CharacterAvatar({
size = 43,
imageSize,
priority = false,
onClick,
actionLabel,
analyticsKey,
}: CharacterAvatarProps) {
const resolvedImageSize =
imageSize ?? (typeof size === "number" ? size : 96);
@@ -27,24 +35,45 @@ export function CharacterAvatar({
height: size,
};
const avatarClassName = [
"inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full border-0 bg-(--color-avatar-border,#fbf3f5)",
onClick
? "cursor-pointer p-0 transition-transform duration-150 focus-visible:outline-3 focus-visible:outline-offset-3 focus-visible:outline-accent active:scale-96"
: undefined,
className,
]
.filter(Boolean)
.join(" ");
const image = (
<Image
src={src}
alt={alt}
width={resolvedImageSize}
height={resolvedImageSize}
priority={priority}
className="size-full object-cover"
/>
);
if (onClick) {
return (
<button
type="button"
className={avatarClassName}
style={style}
aria-label={actionLabel}
data-analytics-key={analyticsKey}
data-analytics-label={actionLabel}
onClick={onClick}
>
{image}
</button>
);
}
return (
<span
className={[
"inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full bg-(--color-avatar-border,#fbf3f5)",
className,
]
.filter(Boolean)
.join(" ")}
style={style}
>
<Image
src={src}
alt={alt}
width={resolvedImageSize}
height={resolvedImageSize}
priority={priority}
className="size-full object-cover"
/>
<span className={avatarClassName} style={style}>
{image}
</span>
);
}
+1
View File
@@ -3,5 +3,6 @@
*/
export * from "./back-button";
export * from "./avatar-interaction";
export * from "./character-avatar";
export * from "./user-message-avatar";
+34 -20
View File
@@ -2,19 +2,30 @@
import Image from "next/image";
export interface UserMessageAvatarProps {
import type { AvatarInteractionProps } from "./avatar-interaction";
interface UserMessageAvatarVisualProps {
avatarUrl?: string | null;
className?: string;
size?: number | string;
}
export type UserMessageAvatarProps = UserMessageAvatarVisualProps &
AvatarInteractionProps;
export function UserMessageAvatar({
avatarUrl,
className,
size = 43,
onClick,
actionLabel,
analyticsKey,
}: UserMessageAvatarProps) {
const avatarClassName = [
"flex shrink-0 items-center justify-center overflow-hidden rounded-full border-2 border-(--color-avatar-border,#fbf3f5) bg-(--color-avatar-border,#fbf3f5) shadow-(--shadow-input-box,0_1px_2px_rgba(0,0,0,0.1))",
onClick
? "cursor-pointer p-0 transition-transform duration-150 focus-visible:outline-3 focus-visible:outline-offset-3 focus-visible:outline-accent active:scale-96"
: undefined,
className,
]
.filter(Boolean)
@@ -22,21 +33,30 @@ export function UserMessageAvatar({
const avatarStyle = { width: size, height: size };
const imageSize = typeof size === "number" ? size : 64;
if (avatarUrl && avatarUrl.length > 0) {
const hasUserAvatar = Boolean(avatarUrl && avatarUrl.length > 0);
const image = (
<Image
src={hasUserAvatar ? avatarUrl! : "/images/avatar/placeholder.png"}
alt={hasUserAvatar ? "" : "Guest"}
width={imageSize}
height={imageSize}
className="size-full object-cover"
/>
);
if (onClick) {
return (
<div
<button
type="button"
className={avatarClassName}
style={avatarStyle}
aria-label="User avatar"
aria-label={actionLabel}
data-analytics-key={analyticsKey}
data-analytics-label={actionLabel}
onClick={onClick}
>
<Image
src={avatarUrl}
alt=""
width={imageSize}
height={imageSize}
className="size-full object-cover"
/>
</div>
{image}
</button>
);
}
@@ -44,15 +64,9 @@ export function UserMessageAvatar({
<div
className={avatarClassName}
style={avatarStyle}
aria-label="Guest avatar"
aria-label={hasUserAvatar ? "User avatar" : "Guest avatar"}
>
<Image
src="/images/avatar/placeholder.png"
alt="Guest"
width={imageSize}
height={imageSize}
className="size-full object-cover"
/>
{image}
</div>
);
}