refactor: 深化前端入口作品流与作品架模块

This commit is contained in:
2026-06-03 15:34:52 +08:00
parent 1eeb14c50f
commit cf0840d9e9
8 changed files with 434 additions and 157 deletions

View File

@@ -0,0 +1,27 @@
# 【前端架构】Work Shelf Module 收口计划
## 背景
创作中心作品架需要同时展示 RPG、拼图、抓大鹅、方洞、跳一跳、敲木鱼、视觉小说、Bark Battle 和宝贝识物等作品。`creationWorkShelf.ts` 已经统一了卡片标题、摘要、封面、发布码、分享路径、指标、生成态和动作 Adapter`CustomWorldCreationHub.tsx` 仍在点击作品卡时按玩法 `kind` 再写一遍打开逻辑,导致调用方仍须理解每种玩法。
## 决策
`CreationWorkShelfItem.actions.open` 是打开作品的正式 **Interface**`CustomWorldCreationHub.tsx` 只负责卡片点击与 `onOpenShelfItem` 通知,然后调用 `item.actions.open()`,不再根据 `item.source.kind` 分发玩法。
此决策让 `creationWorkShelf.ts`**Module** 更 deep
- **Implementation**:玩法差异、草稿 / 已发布分支、profileId 进入方式和回调绑定都留在 Work Shelf Adapter 内。
- **Interface**Hub 只需要 `CreationWorkShelfItem`,不需要知道每种玩法的打开规则。
- **Leverage**:新增玩法时只补 shelf item 映射与 AdapterHub 不再新增 switch 分支。
- **Locality**:作品架点击行为的错误集中在 `creationWorkShelf.ts` 与其测试里定位。
## 后续深化
下一步可把 `buildCreationWorkShelfItems` 当前的长参数列表继续收口为 per-kind Source Adapter registry。届时 Hub / 平台壳传入玩法数据源和回调时,可逐步减少按玩法平铺的参数数量。删除、刷新和直达恢复也可沿同一 seam 收口。
## 验证
- `npm run test -- src/components/custom-world-home/creationWorkShelf.test.ts src/components/custom-world-home/CustomWorldCreationHub.interaction.test.tsx`
- `npm run typecheck`
- `npm run check:encoding`
- 针对变更文件执行 ESLint

View File

@@ -0,0 +1,35 @@
# 【前端架构】平台入口 Public Gallery Flow Module 收口计划
## 背景
`PlatformEntryFlowShellImpl.tsx` 同时承载平台入口、推荐流、公开作品详情、运行态启动和作品架刷新。公开作品列表中的身份识别、跨玩法去重、时间排序和推荐运行态类型判定原本散落在入口巨型实现中,后续每新增一种玩法都需要在巨型文件内追加判断,影响前端架构的复用、统一和扩展。
## 决策
新增 `src/components/platform-entry/platformPublicGalleryFlow.ts`,作为平台入口公开作品流的 **Module**。该 Module 的 **Interface** 固定收口为:
- `getPlatformPublicGalleryEntryKey(entry)`:按玩法类型、作者和 `profileId` 生成公开作品身份。
- `getPlatformRecommendRuntimeKind(entry)`:把公开作品卡映射为推荐运行态 kind。
- `isSamePlatformPublicGalleryEntry(left, right)`:按公开作品身份比较。
- `mergePlatformPublicGalleryEntries(rpgEntries, puzzleEntries)`:统一完成 RPG 与各玩法公开作品去重、覆盖和倒序排序。
入口壳层只调用这些函数,不再在 `PlatformEntryFlowShellImpl.tsx` 内手写公开作品身份和排序规则。`isRecommendRuntimeReadyForEntry` 暂留入口壳层,因为它依赖各运行态 run 状态,直接抽出会把更多 runtime 状态类型拖入这个 Module降低本次改造的 locality。
## 玩法身份规则
- `big-fish``puzzle``jump-hop``wooden-fish``match3d``square-hole``visual-novel``bark-battle` 使用自身 `sourceType` 作为 key kind。
- `edutainment` 使用 `edutainment:${templateId}` 作为 key kind避免后续幼教类模板共用 `sourceType` 时互相覆盖。
- 没有 `sourceType` 的 RPG 公开作品回退为 `rpg`
- 最终 key 格式为 `${kind}:${ownerUserId}:${profileId}`
- 合并时后进入的相同 key 会覆盖先进入的卡片,然后按 `publishedAt ?? updatedAt` 新到旧排序;非法时间按 `0` 处理。
## 后续深化
下一步可继续把平台入口的作品架刷新、删除确认和直达恢复逻辑收口成更深的 Work Shelf **Module**。当前 `platformPublicGalleryFlow` 先提供一个稳定 seam使公开作品 identity 与 runtime kind 的修改集中在一处。
## 验证
- `npm run test -- src/components/platform-entry/platformPublicGalleryFlow.test.ts`
- `npm run typecheck`
- `npm run check:encoding`
- 针对变更文件执行 ESLint