fix: split recommendation layouts by breakpoint

This commit is contained in:
2026-05-25 21:10:20 +08:00
parent bdb81466ce
commit ae66776fa9
8 changed files with 139 additions and 81 deletions

View File

@@ -16,6 +16,14 @@
--- ---
## 2026-05-25 平台首页推荐按桌面与移动断点分流
- 背景:平台首页的推荐页在桌面与移动端之间原先共用同一套推荐运行态逻辑,容易让桌面和移动两套内容同时启动,也让首页的推荐卡与桌面发现壳互相抢状态。
- 决策:`RpgEntryHomeView` 只接受同一个 `isDesktopLayout` 断点判断;桌面端首页渲染桌面发现壳(`今日游戏``推荐``作品分类` 等),不挂移动推荐嵌入运行态;移动端 `home` 才渲染推荐卡与嵌入运行态。平台壳和首页视图都必须共用 `usePlatformDesktopLayout()`,不能在不同文件里各自判断断点。
- 影响范围:`src/components/platform-entry/platformEntryResponsive.ts``src/components/platform-entry/PlatformEntryFlowShellImpl.tsx``src/components/rpg-entry/RpgEntryHomeView.tsx`、首页推荐相关测试与 `docs/【玩法创作】平台入口与玩法链路-2026-05-15.md`
- 验证方式:桌面宽度下首页应只看到桌面发现壳,窄屏下首页应只看到移动推荐流;`npm run test -- src/components/rpg-entry/RpgEntryHomeView.recharge.test.tsx -t "recommend"``npm run test -- src/components/rpg-entry/RpgEntryFlowShell.agent.interaction.test.tsx -t "home recommendation"``npm run typecheck``npm run check:encoding` 通过。
- 关联文档:`docs/【玩法创作】平台入口与玩法链路-2026-05-15.md`
## 2026-05-24 创作 Tab banner 轮播只展示主题赛 ## 2026-05-24 创作 Tab banner 轮播只展示主题赛
- 背景:创作 Tab banner 曾经把后端入口配置里的默认活动横幅和两个主题赛一起轮播,导致首屏出现 58000 奖池活动卡,和当前只强调拼图 / 抓大鹅主题赛的产品口径不一致。 - 背景:创作 Tab banner 曾经把后端入口配置里的默认活动横幅和两个主题赛一起轮播,导致首屏出现 58000 奖池活动卡,和当前只强调拼图 / 抓大鹅主题赛的产品口径不一致。

View File

@@ -23,6 +23,14 @@
- 验证:点拼图 / 抓大鹅 / 汪汪声浪卡片后,应看到各自既有工作台内容,例如测试中的 `拼图工作区missing-session``抓大鹅工作区missing-session``汪汪声浪配置表单`并且不再出现“X 创作入口”空白页。 - 验证:点拼图 / 抓大鹅 / 汪汪声浪卡片后,应看到各自既有工作台内容,例如测试中的 `拼图工作区missing-session``抓大鹅工作区missing-session``汪汪声浪配置表单`并且不再出现“X 创作入口”空白页。
- 关联:`src/components/platform-entry/platformEntryTypes.ts``src/routing/appPageRoutes.ts``src/components/platform-entry/PlatformEntryFlowShellImpl.tsx``src/components/rpg-entry/RpgEntryFlowShell.agent.interaction.test.tsx` - 关联:`src/components/platform-entry/platformEntryTypes.ts``src/routing/appPageRoutes.ts``src/components/platform-entry/PlatformEntryFlowShellImpl.tsx``src/components/rpg-entry/RpgEntryFlowShell.agent.interaction.test.tsx`
## 首页推荐分流参数不能条件性调用 hook
- 现象:桌面首页或移动首页在 HMR、断点切换或重新渲染后直接报 React hook 顺序错误,页面停在“正在加载内容”。
- 原因:`RpgEntryHomeView` 曾经写成 `const isDesktopLayout = isDesktopLayoutProp ?? usePlatformDesktopLayout();`,当 `isDesktopLayoutProp` 存在时会跳过 hook 调用,导致 hook 顺序在不同渲染之间变化。
- 处理:先无条件调用 `usePlatformDesktopLayout()`,再用 `isDesktopLayoutProp ?? detectedDesktopLayout` 合并;不要把 hook 调用藏在条件表达式里。
- 验证:桌面与窄屏各刷新一次首页,控制台不再出现 hook 顺序错误;`npm run typecheck` 和首页推荐相关测试通过。
- 关联:`src/components/rpg-entry/RpgEntryHomeView.tsx``src/components/platform-entry/platformEntryResponsive.ts`
## 草稿页未读点不要继续用红色 literal ## 草稿页未读点不要继续用红色 literal
- 现象:草稿页底部 Tab 和作品架的未读点视觉上仍像红点,或 glow 仍带红色阴影,和平台暖棕体系不一致。 - 现象:草稿页底部 Tab 和作品架的未读点视觉上仍像红点,或 glow 仍带红色阴影,和平台暖棕体系不一致。

View File

@@ -128,7 +128,7 @@ RPG / 拼图等运行态存档选择入口统一在个人中心 `次级入口 >
删除等破坏性动作当前未接入 jump-hop 删除 API如果后续要在作品架提供删除入口必须先补齐后端/SpacetimeDB/前端整条删除链路,再开放按钮。 删除等破坏性动作当前未接入 jump-hop 删除 API如果后续要在作品架提供删除入口必须先补齐后端/SpacetimeDB/前端整条删除链路,再开放按钮。
推荐页匿名游玩不再限定为跳一跳。推荐页嵌入运行态启动时统一先申请短期 Runtime Guest Token并只把它作为局部请求头传给运行态客户端不写入全局登录态、不触发 refresh也不把匿名流量伪装成普通用户。当前覆盖矩阵为跳一跳、视觉小说、抓大鹅 Match3D、方洞挑战、拼图、敲木鱼、大鱼吃小鱼、汪汪声浪。每个模板的启动请求、推荐页内后续运行态动作以及需要上报的 play/finish/leaderboard/next-level 类请求,都必须继续透传 runtime guest token公开读取入口仍可匿名读取创作、个人作品、删除、发布、Remix 等账号/所有权动作仍保持普通用户鉴权。 推荐页匿名游玩不再限定为跳一跳。移动端一级 `推荐` Tab 是内嵌运行态刷卡流,会自动选择推荐作品并启动对应玩法;桌面端首页不启动这套移动推荐运行态,而是渲染桌面发现壳,展示 `今日游戏``推荐``作品分类` 等桌面内容。断点事实统一走 `platformEntryResponsive.ts``usePlatformDesktopLayout()`,平台壳和首页视图必须共用同一个判断,避免桌面发现页与移动推荐页同时挂载、重复触发请求或启动运行态。推荐页嵌入运行态启动时统一先申请短期 Runtime Guest Token并只把它作为局部请求头传给运行态客户端不写入全局登录态、不触发 refresh也不把匿名流量伪装成普通用户。当前覆盖矩阵为跳一跳、视觉小说、抓大鹅 Match3D、方洞挑战、拼图、敲木鱼、大鱼吃小鱼、汪汪声浪。每个模板的启动请求、推荐页内后续运行态动作以及需要上报的 play/finish/leaderboard/next-level 类请求,都必须继续透传 runtime guest token公开读取入口仍可匿名读取创作、个人作品、删除、发布、Remix 等账号/所有权动作仍保持普通用户鉴权。
## 敲木鱼 ## 敲木鱼

View File

@@ -410,6 +410,7 @@ import { PlatformFeedbackView } from './PlatformFeedbackView';
import { PlatformWorkDetailView } from './PlatformWorkDetailView'; import { PlatformWorkDetailView } from './PlatformWorkDetailView';
import { usePlatformCreationAgentFlowController } from './usePlatformCreationAgentFlowController'; import { usePlatformCreationAgentFlowController } from './usePlatformCreationAgentFlowController';
import { usePlatformEntryBootstrap } from './usePlatformEntryBootstrap'; import { usePlatformEntryBootstrap } from './usePlatformEntryBootstrap';
import { usePlatformDesktopLayout } from './platformEntryResponsive';
import { usePlatformEntryLibraryDetail } from './usePlatformEntryLibraryDetail'; import { usePlatformEntryLibraryDetail } from './usePlatformEntryLibraryDetail';
import { usePlatformEntryNavigation } from './usePlatformEntryNavigation'; import { usePlatformEntryNavigation } from './usePlatformEntryNavigation';
@@ -2714,6 +2715,7 @@ export function PlatformEntryFlowShellImpl({
authUi?.platformTheme === 'dark' authUi?.platformTheme === 'dark'
? 'platform-theme--dark' ? 'platform-theme--dark'
: 'platform-theme--light'; : 'platform-theme--light';
const isDesktopLayout = usePlatformDesktopLayout();
const [showCreationTypeModal, setShowCreationTypeModal] = useState(false); const [showCreationTypeModal, setShowCreationTypeModal] = useState(false);
const [selectedDetailEntry, setSelectedDetailEntry] = const [selectedDetailEntry, setSelectedDetailEntry] =
useState<CustomWorldLibraryEntry<CustomWorldProfile> | null>(null); useState<CustomWorldLibraryEntry<CustomWorldProfile> | null>(null);
@@ -11758,6 +11760,7 @@ export function PlatformEntryFlowShellImpl({
const recommendRuntimeContent = useMemo(() => { const recommendRuntimeContent = useMemo(() => {
if ( if (
isDesktopLayout ||
selectionStage !== 'platform' || selectionStage !== 'platform' ||
platformBootstrap.platformTab !== 'home' || platformBootstrap.platformTab !== 'home' ||
!activeRecommendRuntimeKind !activeRecommendRuntimeKind
@@ -12164,10 +12167,12 @@ export function PlatformEntryFlowShellImpl({
visualNovelSession, visualNovelSession,
visualNovelWork, visualNovelWork,
checkpointWoodenFishRuntimeRun, checkpointWoodenFishRuntimeRun,
isDesktopLayout,
]); ]);
useEffect(() => { useEffect(() => {
if ( if (
isDesktopLayout ||
selectionStage !== 'platform' || selectionStage !== 'platform' ||
platformBootstrap.platformTab !== 'home' || platformBootstrap.platformTab !== 'home' ||
platformBootstrap.isLoadingPlatform platformBootstrap.isLoadingPlatform
@@ -12223,6 +12228,7 @@ export function PlatformEntryFlowShellImpl({
match3dRun, match3dRun,
platformBootstrap.isLoadingPlatform, platformBootstrap.isLoadingPlatform,
platformBootstrap.platformTab, platformBootstrap.platformTab,
isDesktopLayout,
puzzleRun, puzzleRun,
recommendRuntimeEntries, recommendRuntimeEntries,
selectRecommendRuntimeEntry, selectRecommendRuntimeEntry,
@@ -13462,6 +13468,7 @@ export function PlatformEntryFlowShellImpl({
isLoadingPlatform={platformBootstrap.isLoadingPlatform} isLoadingPlatform={platformBootstrap.isLoadingPlatform}
isLoadingDashboard={platformBootstrap.isLoadingDashboard} isLoadingDashboard={platformBootstrap.isLoadingDashboard}
hasUnreadDraftUpdate={hasUnreadDraftUpdates} hasUnreadDraftUpdate={hasUnreadDraftUpdates}
isDesktopLayout={isDesktopLayout}
isResumingSaveWorldKey={platformBootstrap.isResumingSaveWorldKey} isResumingSaveWorldKey={platformBootstrap.isResumingSaveWorldKey}
platformError={ platformError={
platformBootstrap.isLoadingPlatform platformBootstrap.isLoadingPlatform

View File

@@ -0,0 +1,47 @@
import { useEffect, useState } from 'react';
export const PLATFORM_DESKTOP_LAYOUT_QUERY = '(min-width: 1024px)';
export function getInitialPlatformDesktopLayout() {
if (
typeof window === 'undefined' ||
typeof window.matchMedia !== 'function'
) {
return false;
}
return window.matchMedia(PLATFORM_DESKTOP_LAYOUT_QUERY).matches;
}
export function usePlatformDesktopLayout() {
const [isDesktopLayout, setIsDesktopLayout] = useState(
getInitialPlatformDesktopLayout,
);
useEffect(() => {
if (
typeof window === 'undefined' ||
typeof window.matchMedia !== 'function'
) {
return;
}
const mediaQuery = window.matchMedia(PLATFORM_DESKTOP_LAYOUT_QUERY);
const updateLayout = (event?: MediaQueryListEvent) => {
setIsDesktopLayout(event?.matches ?? mediaQuery.matches);
};
updateLayout();
// 平台页只挂载当前断点外壳,避免隐藏的移动端/桌面端内容重复抢占查询。
if (typeof mediaQuery.addEventListener === 'function') {
mediaQuery.addEventListener('change', updateLayout);
return () => mediaQuery.removeEventListener('change', updateLayout);
}
mediaQuery.addListener(updateLayout);
return () => mediaQuery.removeListener(updateLayout);
}, []);
return isDesktopLayout;
}

View File

@@ -5,6 +5,7 @@ import userEvent from '@testing-library/user-event';
import { useState } from 'react'; import { useState } from 'react';
import { afterEach, beforeEach, expect, test, vi } from 'vitest'; import { afterEach, beforeEach, expect, test, vi } from 'vitest';
import type { PublicUserSummary } from '../../../packages/shared/src/contracts/auth';
import type { BarkBattleWorkSummary } from '../../../packages/shared/src/contracts/barkBattle'; import type { BarkBattleWorkSummary } from '../../../packages/shared/src/contracts/barkBattle';
import type { BigFishWorkSummary } from '../../../packages/shared/src/contracts/bigFishWorkSummary'; import type { BigFishWorkSummary } from '../../../packages/shared/src/contracts/bigFishWorkSummary';
import type { CreativeAgentSessionSnapshot } from '../../../packages/shared/src/contracts/creativeAgent'; import type { CreativeAgentSessionSnapshot } from '../../../packages/shared/src/contracts/creativeAgent';
@@ -178,6 +179,35 @@ import {
type SelectionStage, type SelectionStage,
} from './RpgEntryFlowShell'; } from './RpgEntryFlowShell';
const authServiceMocks = vi.hoisted(() => ({
ensureRuntimeGuestToken: vi.fn(async () => ({
token: 'runtime-guest-token',
expiresAt: '2099-01-01T00:00:00.000Z',
})),
getPublicAuthUserByCode: vi.fn(
async (publicUserCode: string): Promise<PublicUserSummary> => ({
id: `public-user-${publicUserCode}`,
publicUserCode,
displayName: '公开作者',
avatarUrl: null,
}),
),
getPublicAuthUserById: vi.fn(
async (userId: string): Promise<PublicUserSummary> => ({
id: userId,
publicUserCode: `code-${userId}`,
displayName: '公开作者',
avatarUrl: null,
}),
),
}));
vi.mock('../../services/authService', () => ({
ensureRuntimeGuestToken: authServiceMocks.ensureRuntimeGuestToken,
getPublicAuthUserByCode: authServiceMocks.getPublicAuthUserByCode,
getPublicAuthUserById: authServiceMocks.getPublicAuthUserById,
}));
async function clickFirstButtonByName( async function clickFirstButtonByName(
user: ReturnType<typeof userEvent.setup>, user: ReturnType<typeof userEvent.setup>,
name: string | RegExp, name: string | RegExp,
@@ -276,6 +306,10 @@ const ISOLATED_RUNTIME_AUTH_OPTIONS = {
notifyAuthStateChange: false, notifyAuthStateChange: false,
clearAuthOnUnauthorized: false, clearAuthOnUnauthorized: false,
}; };
const RECOMMEND_RUNTIME_AUTH_OPTIONS = {
...ISOLATED_RUNTIME_AUTH_OPTIONS,
runtimeGuestToken: 'runtime-guest-token',
};
function getPlatformTabPanel(tab: string) { function getPlatformTabPanel(tab: string) {
const panel = document.getElementById(`platform-tab-panel-${tab}`); const panel = document.getElementById(`platform-tab-panel-${tab}`);
@@ -2235,6 +2269,10 @@ function TestWrapper({
beforeEach(() => { beforeEach(() => {
vi.resetAllMocks(); vi.resetAllMocks();
vi.mocked(authServiceMocks.ensureRuntimeGuestToken).mockResolvedValue({
token: 'runtime-guest-token',
expiresAt: '2099-01-01T00:00:00.000Z',
});
vi.mocked( vi.mocked(
match3dGeneratedModelCache.hasMatch3DGeneratedImageAsset, match3dGeneratedModelCache.hasMatch3DGeneratedImageAsset,
).mockImplementation((assets) => ).mockImplementation((assets) =>
@@ -6121,7 +6159,7 @@ test('home recommendation starts embedded puzzle without global auth reset on lo
profileId: 'puzzle-profile-public-1', profileId: 'puzzle-profile-public-1',
levelId: null, levelId: null,
}, },
ISOLATED_RUNTIME_AUTH_OPTIONS, RECOMMEND_RUNTIME_AUTH_OPTIONS,
); );
}); });
}); });
@@ -6184,7 +6222,7 @@ test('home recommendation Match3D runtime keeps profile generated models when ca
await waitFor(() => { await waitFor(() => {
expect(match3dServerRuntimeAdapterMock.startRun).toHaveBeenCalledWith( expect(match3dServerRuntimeAdapterMock.startRun).toHaveBeenCalledWith(
'match3d-profile-card-1', 'match3d-profile-card-1',
ISOLATED_RUNTIME_AUTH_OPTIONS, RECOMMEND_RUNTIME_AUTH_OPTIONS,
); );
}); });
await waitFor(() => { await waitFor(() => {
@@ -6503,7 +6541,11 @@ test('home recommendation surfaces start failure instead of staying in loading s
expect( expect(
await screen.findByText('作品暂时无法进入,请稍后再试。'), await screen.findByText('作品暂时无法进入,请稍后再试。'),
).toBeTruthy(); ).toBeTruthy();
expect(screen.queryByText('加载中...')).toBeNull(); expect(
within(getPlatformTabPanel('home'))
.queryByText('加载中...')
?.closest('.platform-recommend-runtime-panel'),
).toBeFalsy();
}); });
test('published big fish works stay hidden from platform home and game category channel', async () => { test('published big fish works stay hidden from platform home and game category channel', async () => {

View File

@@ -804,6 +804,7 @@ function renderLoggedOutHomeView(
> >
> = {}, > = {},
activeTab: RpgEntryHomeViewProps['activeTab'] = 'home', activeTab: RpgEntryHomeViewProps['activeTab'] = 'home',
isDesktopLayout = false,
) { ) {
return render( return render(
<AuthUiContext.Provider <AuthUiContext.Provider
@@ -827,6 +828,7 @@ function renderLoggedOutHomeView(
> >
<RpgEntryHomeView <RpgEntryHomeView
activeTab={activeTab} activeTab={activeTab}
isDesktopLayout={isDesktopLayout}
onTabChange={vi.fn()} onTabChange={vi.fn()}
hasSavedGame={false} hasSavedGame={false}
savedSnapshot={null} savedSnapshot={null}
@@ -954,6 +956,7 @@ function renderStatefulLoggedOutHomeView(
| 'onSelectPreviousRecommendEntry' | 'onSelectPreviousRecommendEntry'
> >
> = {}, > = {},
isDesktopLayout = false,
) { ) {
const authSpies = { const authSpies = {
openLoginModal: vi.fn(), openLoginModal: vi.fn(),
@@ -985,6 +988,7 @@ function renderStatefulLoggedOutHomeView(
> >
<RpgEntryHomeView <RpgEntryHomeView
activeTab={activeTab} activeTab={activeTab}
isDesktopLayout={isDesktopLayout}
onTabChange={setActiveTab} onTabChange={setActiveTab}
hasSavedGame={false} hasSavedGame={false}
savedSnapshot={null} savedSnapshot={null}
@@ -2697,7 +2701,7 @@ test('logged out mobile shell defaults to discover tab', () => {
).toBeNull(); ).toBeNull();
}); });
test('logged out recommend tab opens login modal and shows cover only', async () => { test('logged out recommend tab opens embedded runtime without login modal', async () => {
const user = userEvent.setup(); const user = userEvent.setup();
const { container, openLoginModal } = renderStatefulLoggedOutHomeView({ const { container, openLoginModal } = renderStatefulLoggedOutHomeView({
latestEntries: [puzzlePublicEntry], latestEntries: [puzzlePublicEntry],
@@ -2712,20 +2716,18 @@ test('logged out recommend tab opens login modal and shows cover only', async ()
within(bottomNav as HTMLElement).getByRole('button', { name: '推荐' }), within(bottomNav as HTMLElement).getByRole('button', { name: '推荐' }),
); );
expect(openLoginModal).toHaveBeenCalledTimes(1); expect(openLoginModal).not.toHaveBeenCalled();
expect( expect(container.querySelector('.platform-recommend-cover-only')).toBeNull();
container.querySelector('.platform-recommend-cover-only'),
).toBeTruthy();
expect(container.querySelector('.platform-mobile-topbar')).toBeNull(); expect(container.querySelector('.platform-mobile-topbar')).toBeNull();
expect( expect(
container.querySelector('.platform-mobile-entry-shell--recommend'), container.querySelector('.platform-mobile-entry-shell--recommend'),
).toBeTruthy(); ).toBeTruthy();
expect(screen.queryByTestId('recommend-runtime')).toBeNull(); expect(screen.getByTestId('recommend-runtime')).toBeTruthy();
expect(screen.queryByLabelText('奇幻拼图 作品信息')).toBeNull(); expect(screen.getByLabelText('奇幻拼图 作品信息')).toBeTruthy();
expect(screen.getAllByText('奇幻拼图').length).toBeGreaterThan(0); expect(screen.getAllByText('奇幻拼图').length).toBeGreaterThan(0);
}); });
test('logged out recommend cover opens login modal again', async () => { test('logged out recommend runtime keeps detail callback idle', async () => {
const user = userEvent.setup(); const user = userEvent.setup();
const onOpenGalleryDetail = vi.fn(); const onOpenGalleryDetail = vi.fn();
const { openLoginModal } = renderStatefulLoggedOutHomeView({ const { openLoginModal } = renderStatefulLoggedOutHomeView({
@@ -2741,12 +2743,9 @@ test('logged out recommend cover opens login modal again', async () => {
await user.click( await user.click(
within(bottomNav as HTMLElement).getByRole('button', { name: '推荐' }), within(bottomNav as HTMLElement).getByRole('button', { name: '推荐' }),
); );
await user.click(
screen.getByRole('button', { name: / /u }),
);
expect(openLoginModal).toHaveBeenCalledTimes(2); expect(openLoginModal).not.toHaveBeenCalled();
expect(openLoginModal).toHaveBeenLastCalledWith(); expect(screen.getByTestId('recommend-runtime')).toBeTruthy();
expect(onOpenGalleryDetail).not.toHaveBeenCalled(); expect(onOpenGalleryDetail).not.toHaveBeenCalled();
}); });
@@ -2755,16 +2754,15 @@ test('logged out desktop recommend page renders runtime directly', () => {
renderLoggedOutHomeView(vi.fn(), { renderLoggedOutHomeView(vi.fn(), {
latestEntries: [puzzlePublicEntry], latestEntries: [puzzlePublicEntry],
activeRecommendEntryKey: 'puzzle:user-2:puzzle-profile-public-1', activeRecommendEntryKey: 'puzzle:user-2:puzzle-profile-public-1',
}); }, 'home', true);
expect(document.querySelector('.platform-recommend-cover-only')).toBeNull(); expect(document.querySelector('.platform-recommend-cover-only')).toBeNull();
expect(screen.queryByText('今日游戏')).toBeNull(); expect(screen.queryByTestId('recommend-runtime')).toBeNull();
expect(screen.queryByText('作品分类')).toBeNull(); expect(screen.getByText('今日游戏')).toBeTruthy();
expect(screen.getByTestId('recommend-runtime')).toBeTruthy(); expect(screen.getByText('作品分类')).toBeTruthy();
}); });
test('logged out recommend page can enter runtime without login gate', () => { test('logged out recommend page can enter runtime without login gate', () => {
mockDesktopLayout();
const openLoginModal = vi.fn(); const openLoginModal = vi.fn();
const onOpenGalleryDetail = vi.fn(); const onOpenGalleryDetail = vi.fn();
renderLoggedOutHomeView(openLoginModal, { renderLoggedOutHomeView(openLoginModal, {
@@ -3082,7 +3080,7 @@ test('mobile recommend meta loads real author avatar from public user summary',
await waitFor(() => { await waitFor(() => {
expect( expect(
document document
.querySelector('.platform-recommend-cover-only__author img') .querySelector('.platform-recommend-work-meta__avatar img')
?.getAttribute('src'), ?.getAttribute('src'),
).toBe('data:image/png;base64,AUTHOR'); ).toBe('data:image/png;base64,AUTHOR');
}); });

View File

@@ -131,6 +131,7 @@ import {
findPublicWorkForHistoryEntry, findPublicWorkForHistoryEntry,
isEdutainmentEntryEnabled, isEdutainmentEntryEnabled,
} from '../platform-entry/platformEdutainmentVisibility'; } from '../platform-entry/platformEdutainmentVisibility';
import { getInitialPlatformDesktopLayout } from '../platform-entry/platformEntryResponsive';
import { CustomWorldCoverArtwork } from '../CustomWorldCoverArtwork'; import { CustomWorldCoverArtwork } from '../CustomWorldCoverArtwork';
import { ResolvedAssetImage } from '../ResolvedAssetImage'; import { ResolvedAssetImage } from '../ResolvedAssetImage';
import { RpgEntryBrandLogo } from './RpgEntryBrandLogo'; import { RpgEntryBrandLogo } from './RpgEntryBrandLogo';
@@ -166,6 +167,7 @@ export type PlatformHomeTab =
| 'profile'; | 'profile';
export interface RpgEntryHomeViewProps { export interface RpgEntryHomeViewProps {
activeTab: PlatformHomeTab; activeTab: PlatformHomeTab;
isDesktopLayout?: boolean;
onTabChange: (tab: PlatformHomeTab) => void; onTabChange: (tab: PlatformHomeTab) => void;
hasSavedGame: boolean; hasSavedGame: boolean;
savedSnapshot: HydratedSavedGameSnapshot | null; savedSnapshot: HydratedSavedGameSnapshot | null;
@@ -233,7 +235,6 @@ const DESKTOP_PAGE_STAGE_CLASS =
'platform-page-stage platform-remap-surface min-w-0 space-y-5 pb-4'; 'platform-page-stage platform-remap-surface min-w-0 space-y-5 pb-4';
const DESKTOP_DISCOVER_PAGE_STAGE_CLASS = const DESKTOP_DISCOVER_PAGE_STAGE_CLASS =
'platform-remap-surface min-w-0 space-y-5 pb-4'; 'platform-remap-surface min-w-0 space-y-5 pb-4';
const DESKTOP_LAYOUT_QUERY = '(min-width: 1024px)';
const PLATFORM_HOME_TABS: PlatformHomeTab[] = [ const PLATFORM_HOME_TABS: PlatformHomeTab[] = [
'home', 'home',
'category', 'category',
@@ -381,46 +382,6 @@ const PLATFORM_RANKING_TABS: Array<{
emptyText: '公开广场暂时还没有点赞作品。', emptyText: '公开广场暂时还没有点赞作品。',
}, },
]; ];
function usePlatformDesktopLayout() {
const [isDesktopLayout, setIsDesktopLayout] = useState(() => {
if (
typeof window === 'undefined' ||
typeof window.matchMedia !== 'function'
) {
return false;
}
return window.matchMedia(DESKTOP_LAYOUT_QUERY).matches;
});
useEffect(() => {
if (
typeof window === 'undefined' ||
typeof window.matchMedia !== 'function'
) {
return;
}
const mediaQuery = window.matchMedia(DESKTOP_LAYOUT_QUERY);
const updateLayout = (event?: MediaQueryListEvent) => {
setIsDesktopLayout(event?.matches ?? mediaQuery.matches);
};
updateLayout();
// 平台页只挂载当前断点外壳,避免隐藏的移动端/桌面端内容重复抢占查询。
if (typeof mediaQuery.addEventListener === 'function') {
mediaQuery.addEventListener('change', updateLayout);
return () => mediaQuery.removeEventListener('change', updateLayout);
}
mediaQuery.addListener(updateLayout);
return () => mediaQuery.removeListener(updateLayout);
}, []);
return isDesktopLayout;
}
function ResolvedAssetBackdrop({ function ResolvedAssetBackdrop({
src, src,
fallbackSrc, fallbackSrc,
@@ -3852,6 +3813,7 @@ function ProfilePlayedWorksModal({
export function RpgEntryHomeView({ export function RpgEntryHomeView({
activeTab, activeTab,
isDesktopLayout: isDesktopLayoutProp,
onTabChange, onTabChange,
saveEntries, saveEntries,
saveError, saveError,
@@ -4008,7 +3970,8 @@ export function RpgEntryHomeView({
const [isSavingAvatar, setIsSavingAvatar] = useState(false); const [isSavingAvatar, setIsSavingAvatar] = useState(false);
const isAuthenticated = Boolean(authUi?.user); const isAuthenticated = Boolean(authUi?.user);
const edutainmentEntryEnabled = isEdutainmentEntryEnabled(); const edutainmentEntryEnabled = isEdutainmentEntryEnabled();
const isDesktopLayout = usePlatformDesktopLayout(); const [fallbackDesktopLayout] = useState(getInitialPlatformDesktopLayout);
const isDesktopLayout = isDesktopLayoutProp ?? fallbackDesktopLayout;
const openRecommendGalleryDetail = const openRecommendGalleryDetail =
onOpenRecommendGalleryDetail ?? onOpenGalleryDetail; onOpenRecommendGalleryDetail ?? onOpenGalleryDetail;
const generalFeaturedEntries = useMemo( const generalFeaturedEntries = useMemo(
@@ -6581,10 +6544,7 @@ export function RpgEntryHomeView({
); );
const tabContentById = { const tabContentById = {
home: home: isDesktopLayout ? desktopHomeContent : mobileRecommendContent,
!isAuthenticated || !isDesktopLayout
? mobileRecommendContent
: desktopHomeContent,
category: categoryContent, category: categoryContent,
create: createContent, create: createContent,
saves: savesContent, saves: savesContent,
@@ -6761,12 +6721,6 @@ export function RpgEntryHomeView({
return; return;
} }
if (!isAuthenticated && tab === 'home') {
onTabChange(tab);
authUi?.openLoginModal();
return;
}
onTabChange(tab); onTabChange(tab);
}} }}
/> />
@@ -6924,12 +6878,6 @@ export function RpgEntryHomeView({
emphasized={tab === 'create'} emphasized={tab === 'create'}
showDot={tab === 'saves' && hasUnreadDraftUpdate} showDot={tab === 'saves' && hasUnreadDraftUpdate}
onClick={() => { onClick={() => {
if (!isAuthenticated && tab === 'home') {
onTabChange(tab);
authUi?.openLoginModal();
return;
}
onTabChange(tab); onTabChange(tab);
}} }}
/> />