refactor: 收口公开作品详情策略

This commit is contained in:
2026-06-03 22:22:13 +08:00
parent caac418e0e
commit 00820e6571
6 changed files with 506 additions and 53 deletions

View File

@@ -0,0 +1,41 @@
# PlatformPublicWorkDetailFlow 收口计划
## 背景
`PlatformEntryFlowShellImpl.tsx` 已把公开作品身份、去重和推荐 runtime kind 收口到 `platformPublicGalleryFlow.ts`,但统一作品详情入口仍在壳层 Implementation 内直接判断 RPG、拼图、跳一跳、敲木鱼、视觉小说和其它玩法。壳层既要知道哪些公开详情可直接使用当前 entry又要知道哪些玩法必须先补读完整详情还要按当前用户判断详情按钮是“编辑”还是“改造”。这些是纯决策规则继续留在巨型壳层会削弱 Locality。
## 决策
- 新增 `src/components/platform-entry/platformPublicWorkDetailFlow.ts` 作为 Platform Public Work Detail Flow Module。
- Module Interface 收口:
- `getPlatformPublicWorkDetailKind(entry)`
- `resolvePlatformPublicWorkDetailOpenStrategy(entry)`
- `resolvePlatformPublicWorkActionMode(entry, viewerUserId)`
- `PlatformEntryFlowShellImpl.tsx` 继续作为 Adapter根据 open strategy 调用 `openPublicWorkDetail``openPuzzlePublicWorkDetail``openJumpHopPublicWorkDetail``openWoodenFishPublicWorkDetail``openVisualNovelPublicWorkDetail``openRpgPublicWorkDetail`
- 本次不抽 `startSelectedPublicWork``likePublicWork``remixPublicWork``editOwnedPublicWork`。这些函数牵涉运行态启动、计数写入、草稿恢复、作品架缓存和多路错误 setter若直接搬进一个 Hook会形成浅 Interface。
## Interface 约束
- `getPlatformPublicWorkDetailKind` 只根据 `PlatformPublicGalleryCard` 的玩法判定 helper 归一 kind没有 `sourceType` 的公开 RPG 作品回退为 `rpg`
- `resolvePlatformPublicWorkDetailOpenStrategy` 只表达“如何打开详情”,不执行网络请求或 state setter。
- 拼图、跳一跳、敲木鱼、视觉小说需要按 `profileId` 补读完整详情;返回对应 `load-*` strategy。
- 大鱼吃小鱼、抓大鹅、方洞挑战、汪汪声浪、宝贝识物和其它可直接展示的公开 entry 返回 `use-entry` strategy。
- RPG 返回 `load-rpg-detail` strategy由壳层 Adapter 继续调用 RPG 详情读取流程。
- `resolvePlatformPublicWorkActionMode` 只比较 `entry.ownerUserId` 与当前 viewer user id当前用户拥有该公开作品时返回 `edit`,否则返回 `remix`
## Depth / Leverage / Locality
- **Depth**:壳层传入公开作品 entry 和当前用户 id即可得到详情打开策略和动作模式玩法判定细则藏在 Module Implementation 内。
- **Leverage**:新增玩法公开详情时先补 Strategy 单测,再接壳层 Adapter不必在多个 JSX / callback 位置重复 sourceType 判断。
- **Locality**:公开作品详情入口的纯策略集中到一个小 Module启动运行态、点赞、改造、编辑等副作用仍留在壳层避免伪 Seam。
## 验收
- `npm run test -- src/components/platform-entry/platformPublicWorkDetailFlow.test.ts`
- `npm run test -- src/components/platform-entry/platformPublicGalleryFlow.test.ts`
- `npm run test -- src/components/platform-entry/PlatformWorkDetailView.test.tsx`
- `npm run test -- src/components/rpg-entry/RpgEntryFlowShell.agent.interaction.test.tsx -t "public detail|owned public puzzle detail|direct missing public work detail"`
- `npx eslint src/components/platform-entry/platformPublicWorkDetailFlow.ts src/components/platform-entry/platformPublicWorkDetailFlow.test.ts --max-warnings 0`
- `npx eslint src/components/platform-entry/PlatformEntryFlowShellImpl.tsx --quiet`
- `npm run typecheck`
- `npm run check:encoding`