feat: 顶栏显示当前页名,去掉独立标题行;Logo回首页/页名回顶部
- 新增 PageTitleContext:页面上报标题,顶栏 brand 位显示当前页名(全部资料/ 热门资料/最新/官方/分类名/搜索/我的收藏),未上报则回退品牌名 - AssetStreamPage、Favorites 上报标题;移除资料流内单独的标题行,省出空间 - 顶栏拆分点击:Logo→首页(首页则回顶部);页名文字→回到当前页顶部 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
41
src/components/PageTitleContext.tsx
Normal file
41
src/components/PageTitleContext.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
createContext,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
type PropsWithChildren,
|
||||
} from "react";
|
||||
|
||||
type PageTitleCtx = {
|
||||
title: string | null;
|
||||
setTitle: (title: string | null) => void;
|
||||
};
|
||||
|
||||
const PageTitleContext = createContext<PageTitleCtx | null>(null);
|
||||
|
||||
/**
|
||||
* Lets a page publish its title to the global header so the header can show the
|
||||
* current page name (e.g. "全部资料" / "热门资料") in place of the brand, avoiding
|
||||
* a separate on-page title row. Pages that don't set one fall back to the brand.
|
||||
*/
|
||||
export function PageTitleProvider({ children }: PropsWithChildren) {
|
||||
const [title, setTitle] = useState<string | null>(null);
|
||||
return (
|
||||
<PageTitleContext.Provider value={{ title, setTitle }}>
|
||||
{children}
|
||||
</PageTitleContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function usePageTitle(): string | null {
|
||||
return useContext(PageTitleContext)?.title ?? null;
|
||||
}
|
||||
|
||||
/** Publish the current page's title; clears it again when the page unmounts. */
|
||||
export function useSetPageTitle(title: string | null): void {
|
||||
const setTitle = useContext(PageTitleContext)?.setTitle;
|
||||
useEffect(() => {
|
||||
setTitle?.(title);
|
||||
return () => setTitle?.(null);
|
||||
}, [setTitle, title]);
|
||||
}
|
||||
Reference in New Issue
Block a user