Skip to content
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
50 changes: 28 additions & 22 deletions web/src/components/public-dock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import type { AuthStatus } from "@/lib/nav-store";
import type { Scene } from "@/lib/types";

/**
* 公共页右下角固定坞(顶栏移除后的场景与操作入口):
* 公共页右下角固定坞(顶栏移除后的场景与操作入口)。
*
* - 上部:场景胶囊组(数据源由调用方给:未登录只有公开场景、登录全量;
* 组件内不做可见性判断)。场景多时在**组内**纵向滚动,不把坞撑高。
* - 下部:按钮组纵向排列 —— 主题三态切换,然后是登录态三态的操作:
* 探活未回(pending)时不渲染任何登录态按钮(不闪「登录」),
* 已登录是「后台」+「退出」,未登录是「登录」(仍由公共页弹 LoginDialog)。
* 竖排图标轨道,宽度正好一个图标按钮(`w-11`,44px),不再有横向文字:
* - 上部:场景图标按钮组(数据源由调用方给:未登录只有公开场景、登录全量;
* 组件内不做可见性判断)。没设图标的场景由 SceneSwitcher 回退「首字圆」;
* 场景多时在**组内**纵向滚动(`max-h-40`),不把坞撑高。
* - 下部:主题三态 + 登录态三态,各一个图标按钮:探活未回(pending)时不渲染
* 任何登录态按钮(不闪「登录」),已登录是「后台」+「退出」,未登录是「登录」
* (仍由公共页弹 LoginDialog)。
*
* 布局:`fixed` 贴右下、层级高于页面内容;外层不吃点击(`pointer-events-none`),
* 只有两块面板各自 `pointer-events-auto` —— 坞占的那片透明区域不会挡住下面的链接。
* 宽度固定 `w-28`,窄屏(390px 级)贴右下角也不会溢出视口。
* 窄屏(390px 级)也只有 44px 宽,不会盖住正文。
*/
export function PublicDock({
scenes,
Expand All @@ -36,58 +38,62 @@ export function PublicDock({
onLogin: () => void;
onLogout: () => void;
}) {
// 只有一个场景(仅「通用」)时不显示胶囊:与场景维度上线前的公共页一致
// 只有一个场景(仅「通用」)时不显示场景图标:与场景维度上线前的公共页一致
const showScenes = scenes.length > 1 && activeScene !== null;

return (
<aside
aria-label="场景与快捷操作"
className="pointer-events-none fixed inset-x-0 bottom-4 z-30 flex flex-col items-end gap-2 px-4"
className="pointer-events-none fixed right-4 bottom-4 z-30 flex w-11 flex-col items-center gap-2"
>
{showScenes && (
<SceneSwitcher
scenes={scenes}
value={activeScene}
onValueChange={onSceneChange}
ariaLabel="切换场景"
className="no-scrollbar pointer-events-auto max-h-32 w-28 flex-col flex-nowrap overflow-y-auto"
itemClassName="w-full min-w-0 justify-start"
iconOnly
className="no-scrollbar pointer-events-auto max-h-40 w-full flex-col flex-nowrap gap-1 overflow-y-auto"
itemClassName="size-11 rounded-full p-0"
/>
)}
<div className="pointer-events-auto flex w-28 flex-col gap-1">
<div className="pointer-events-auto flex w-full flex-col gap-1">
{/* 主题是访客本机偏好,不受登录态影响:pending 期间照常可点 */}
<ThemeToggle showLabel className="w-full justify-start" />
<ThemeToggle className="size-11 rounded-full" />
{authStatus === "pending" ? null : authStatus === "authenticated" ? (
<>
<Button
variant="ghost"
size="sm"
className="glass w-full justify-start gap-1.5 text-foreground hover:text-foreground"
size="icon"
className="glass size-11 rounded-full text-foreground hover:text-foreground"
aria-label="后台"
title="后台"
onClick={onOpenAdmin}
>
<Settings className="size-4" aria-hidden="true" />
后台
</Button>
<Button
variant="ghost"
size="sm"
className="glass w-full justify-start gap-1.5 text-foreground hover:text-foreground"
size="icon"
className="glass size-11 rounded-full text-foreground hover:text-foreground"
aria-label="退出"
title="退出"
onClick={onLogout}
>
<LogOut className="size-4" aria-hidden="true" />
退出
</Button>
</>
) : (
// 低调登录入口:仍走 LoginDialog(弹窗由公共页持有)
<Button
variant="ghost"
size="sm"
className="glass w-full justify-start gap-1.5 text-foreground hover:text-foreground"
size="icon"
className="glass size-11 rounded-full text-foreground hover:text-foreground"
aria-label="登录"
title="登录"
onClick={onLogin}
>
<LogIn className="size-4" aria-hidden="true" />
登录
</Button>
)}
</div>
Expand Down
19 changes: 10 additions & 9 deletions web/src/components/public-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import {
/**
* 公开页(/):背景图 + 顶部居中时钟块(站点标题/Logo + 时间)+ 毛玻璃搜索框
* + 「我的导航」图标网格 + 登录后的私有区。**没有顶栏**(2026-11-06 移除):
* 场景胶囊与登录态操作都在右下角的固定坞里(`PublicDock`)。
* 场景图标与登录态操作都在右下角的固定图标坞里(`PublicDock`)。
*
* 场景(与分类正交):胶囊在坞的上部、竖向排列,选中值来自本机偏好 `nav.scene`,
* 切换只过滤前端已拿到的数据、不发请求。胶囊只列当前视角的 `scenes`(未登录只有
* 公开场景、登录全量),组件内不做可见性判断 —— 两层取与由数据层完成。
* 场景(与分类正交):场景图标在坞的上部、竖向排列(单图标宽),选中值来自本机偏好
* `nav.scene`,切换只过滤前端已拿到的数据、不发请求。图标只列当前视角的 `scenes`
* (未登录只有公开场景、登录全量,组件内不再判断)—— 两层取与由数据层完成。
*
* 链接呈现形态由站点设置 `linkStyle` 决定(缺省 classic),由数据层解析后传给
* 分类区块,公共页与访客都无法在这里改。
Expand Down Expand Up @@ -63,7 +63,7 @@ export function PublicPage({ onOpenAdmin }: { onOpenAdmin: () => void }) {
const settings = siteData?.settings;
const categories = siteData?.categories ?? [];
// 当前视角的场景全集:未登录只有公开场景、登录全量(数据层过滤,组件不再判断)。
// 旧后端 / 浏览器旧缓存没有 scenes:按「无场景概念」平铺展示,不渲染胶囊。
// 旧后端 / 浏览器旧缓存没有 scenes:按「无场景概念」平铺展示,不渲染场景图标。
const scenes = siteData?.scenes ?? [];
// 偏好命中可用场景就用它,否则回落默认场景;没有场景时 null(不做场景过滤)。
// 本机偏好若指向私有场景,未登录时它不在 scenes 里 → 自然落回公开的默认场景。
Expand All @@ -87,10 +87,11 @@ export function PublicPage({ onOpenAdmin }: { onOpenAdmin: () => void }) {

{/*
正文:时钟块 → 搜索 → 分类区块。
底部留白 pb-80(320px)大于右下角坞的最大高度(场景组封顶 128 + 间距 8 +
按钮组 92 = 228px):滚到页面底部时最后一行链接完整露出,不会被固定坞盖住。
底部留白 pb-88(352px)大于右下角坞的最大高度(场景组封顶 160 + 间距 8 +
按钮组 140 = 308px,再加坞离底边的 16px):滚到页面底部时最后一行链接
完整露出,不会被固定坞盖住。
*/}
<main className="mx-auto flex max-w-7xl flex-col gap-10 px-4 pb-80 sm:px-8">
<main className="mx-auto flex max-w-7xl flex-col gap-10 px-4 pb-88 sm:px-8">
<FadeIn className="pt-10 sm:pt-16">
<SiteClock
siteTitle={settings?.siteTitle ?? "我的导航"}
Expand Down Expand Up @@ -122,7 +123,7 @@ export function PublicPage({ onOpenAdmin }: { onOpenAdmin: () => void }) {
</div>
</main>

{/* 右下角固定坞:上部场景胶囊、下部主题与登录态操作 */}
{/* 右下角固定坞:上部场景图标、下部主题与登录态图标按钮 */}
<PublicDock
scenes={scenes}
activeScene={activeScene}
Expand Down
79 changes: 68 additions & 11 deletions web/src/components/scene-switcher.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import * as React from "react";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import { cn } from "@/lib/utils";
import { hashColor, initialOf } from "@/lib/icons";
import type { Scene } from "@/lib/types";
import { cn } from "@/lib/utils";

/**
* 场景切换胶囊(前后台共用,冻结契约 #16 §七 / nav #19 §A1–A2)。
* 场景切换(前后台共用,冻结契约 #16 §七 / nav #19 §A1–A2)。
*
* 只列真实场景,没有「全部」聚合项。`scenes` 由调用方按当前视角传入 ——
* 前台未登录只有公开场景、登录全量,后台全量;组件内不做可见性判断。
*
* 视觉:毛玻璃胶囊行(.glass),默认 `flex-wrap`(后台内容区场景多时换行)。
* 前台公共页把它放进右下角竖排坞:调用方用 `className` 覆盖为
* `w-28 max-h-32 flex-col flex-nowrap overflow-y-auto`(竖向、组内滚动),
* 并用 `itemClassName` 让每一段占满宽度、名称过长时截断。
* 两种外观:
* - 缺省:毛玻璃胶囊行(.glass),每段显示场景名,默认 `flex-wrap`(后台内容区换行)。
* - `iconOnly`:前台右下角坞用的图标轨道 —— 每段只显场景图标;没设图标(或图标
* 加载失败)时回退「首字圆」(场景名首字 + 哈希底色,与 SiteIcon 同一套回退口径)。
* 名称走 `title`/`aria-label`,悬停与读屏都能辨认。图标态不再包外层玻璃卡,
* 选中态由每一段的 `glass-scene-trigger` 自己表达。
*
* 单选组由 Radix ToggleGroup(type="single")表达:再点一次当前段 Radix 会回调空串,
* 这里忽略空串(场景必须有一个生效值,取消选中没有意义)。
Expand All @@ -23,15 +27,18 @@ export function SceneSwitcher({
ariaLabel = "切换场景",
className,
itemClassName,
iconOnly = false,
}: {
scenes: readonly Scene[];
/** 当前生效的场景 id */
value: string;
onValueChange: (value: string) => void;
ariaLabel?: string;
className?: string;
/** 追加到每一段上的类(坞里用 `w-full justify-start` 竖排定宽) */
/** 追加到每一段上的类(坞里用 `size-11 rounded-full p-0` 竖排图标) */
itemClassName?: string;
/** 只显图标(无图标场景回退首字圆),不显场景名 */
iconOnly?: boolean;
}) {
return (
<ToggleGroup
Expand All @@ -43,22 +50,72 @@ export function SceneSwitcher({
onValueChange(next);
}}
aria-label={ariaLabel}
className={cn("glass flex-wrap gap-1 rounded-2xl p-1.5", className)}
className={cn(
"flex-wrap gap-1",
// 图标态不要外层玻璃卡:每个场景按钮自己承担选中态(底色/描边)
iconOnly ? "flex-col flex-nowrap" : "glass rounded-2xl p-1.5",
className,
)}
>
{scenes.map((scene) => (
// 场景段只显名称:图标属于后台管理信息,不挤进前台胶囊
<ToggleGroupItem
key={scene.id}
value={scene.id}
// 图标态没有可见文字:功能名走 title / aria-label(悬停与读屏可辨)
aria-label={iconOnly ? scene.name : undefined}
title={iconOnly ? scene.name : undefined}
className={cn(
"glass-scene-trigger rounded-full px-3 text-foreground/70",
iconOnly && "p-0",
itemClassName,
)}
>
{/* 名称过长时截断(后台不设宽度约束,视觉与改动前一致) */}
<span className="truncate">{scene.name}</span>
{iconOnly ? (
<SceneAvatar scene={scene} />
) : (
// 名称过长时截断(后台不设宽度约束,视觉与改动前一致)
<span className="truncate">{scene.name}</span>
)}
</ToggleGroupItem>
))}
</ToggleGroup>
);
}

/**
* 场景图标(坞里的图标按钮内容):设了图标就用图片,没设或加载失败回退首字圆。
* 首字圆复用站点图标的现成口径(`hashColor` 稳定着色 + `initialOf` 取首字),
* 不引入新的配色或绘制逻辑。
*/
function SceneAvatar({ scene }: { scene: Scene }) {
const icon = scene.icon;
// 记录加载失败的地址:换上新地址(后台改了图标)后自动重试
const [brokenIcon, setBrokenIcon] = React.useState<string | null>(null);

if (icon && brokenIcon !== icon) {
return (
<img
// src 变化时换元素:被中止的旧请求的 error 不会落到新地址头上
key={icon}
src={icon}
alt=""
width={28}
height={28}
loading="lazy"
decoding="async"
onError={() => setBrokenIcon(icon)}
className="size-7 shrink-0 rounded-full object-contain"
/>
);
}

return (
<span
aria-hidden="true"
className="inline-flex size-7 shrink-0 select-none items-center justify-center rounded-full text-sm font-semibold leading-none text-white"
style={{ background: hashColor(scene.id || scene.name) }}
>
{initialOf(scene.name, scene.id)}
</span>
);
}
21 changes: 5 additions & 16 deletions web/src/components/theme-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@ const THEME_LABELS: Record<ThemeMode, string> = {
* 点击按「跟随系统 → 浅色 → 深色 → 跟随系统」循环,选择写入本机 localStorage,
* 只影响这个浏览器。没有本机偏好时默认跟随系统,所以按钮任何时刻都可渲染可点。
*
* 两种形态:缺省是顶栏用的纯图标按钮(`icon-sm`);`showLabel` 时是带档位文案的
* 行(公共页右下角坞里用),`aria-label`/`title` 与点击循环两种形态完全一致。
* 纯图标按钮(`icon-sm`):当前档位由图标表达(显示器/太阳/月亮),
* 功能名与下一档写在 `aria-label`/`title` 里,悬停与读屏都能辨认。
*/
export function ThemeToggle({
className,
showLabel = false,
}: {
className?: string;
showLabel?: boolean;
}) {
export function ThemeToggle({ className }: { className?: string }) {
const { mode, cycle } = useThemeCycle();

const Icon = THEME_ICONS[mode];
Expand All @@ -35,18 +29,13 @@ export function ThemeToggle({
return (
<Button
variant="ghost"
size={showLabel ? "sm" : "icon-sm"}
className={cn(
"glass text-foreground hover:text-foreground",
showLabel && "w-full justify-start gap-1.5",
className,
)}
size="icon-sm"
className={cn("glass text-foreground hover:text-foreground", className)}
aria-label={label}
title={label}
onClick={cycle}
>
<Icon className="size-4" aria-hidden="true" />
{showLabel && <span className="truncate">{THEME_LABELS[mode]}</span>}
</Button>
);
}
Loading
Loading