refactor: 收口公开作品详情策略
This commit is contained in:
190
src/components/platform-entry/platformPublicWorkDetailFlow.ts
Normal file
190
src/components/platform-entry/platformPublicWorkDetailFlow.ts
Normal file
@@ -0,0 +1,190 @@
|
||||
import type { CustomWorldGalleryCard } from '../../../packages/shared/src/contracts/runtime';
|
||||
import {
|
||||
isBarkBattleGalleryEntry,
|
||||
isBigFishGalleryEntry,
|
||||
isEdutainmentGalleryEntry,
|
||||
isJumpHopGalleryEntry,
|
||||
isMatch3DGalleryEntry,
|
||||
isPuzzleGalleryEntry,
|
||||
isSquareHoleGalleryEntry,
|
||||
isVisualNovelGalleryEntry,
|
||||
isWoodenFishGalleryEntry,
|
||||
type PlatformPublicGalleryCard,
|
||||
} from '../rpg-entry/rpgEntryWorldPresentation';
|
||||
|
||||
export type PlatformPublicWorkDetailKind =
|
||||
| 'bark-battle'
|
||||
| 'big-fish'
|
||||
| 'edutainment'
|
||||
| 'jump-hop'
|
||||
| 'match3d'
|
||||
| 'puzzle'
|
||||
| 'rpg'
|
||||
| 'square-hole'
|
||||
| 'visual-novel'
|
||||
| 'wooden-fish';
|
||||
|
||||
export type PlatformPublicWorkDetailOpenStrategy =
|
||||
| {
|
||||
type: 'use-entry';
|
||||
kind: Exclude<
|
||||
PlatformPublicWorkDetailKind,
|
||||
'jump-hop' | 'puzzle' | 'rpg' | 'visual-novel' | 'wooden-fish'
|
||||
>;
|
||||
}
|
||||
| {
|
||||
type: 'load-puzzle-detail';
|
||||
profileId: string;
|
||||
}
|
||||
| {
|
||||
type: 'load-jump-hop-detail';
|
||||
profileId: string;
|
||||
}
|
||||
| {
|
||||
type: 'load-wooden-fish-detail';
|
||||
profileId: string;
|
||||
}
|
||||
| {
|
||||
type: 'load-visual-novel-detail';
|
||||
profileId: string;
|
||||
}
|
||||
| {
|
||||
type: 'load-rpg-detail';
|
||||
entry: CustomWorldGalleryCard;
|
||||
};
|
||||
|
||||
export type PlatformPublicWorkActionMode = 'edit' | 'remix';
|
||||
|
||||
export function isRpgPublicWorkDetailEntry(
|
||||
entry: PlatformPublicGalleryCard,
|
||||
): entry is CustomWorldGalleryCard {
|
||||
return !('sourceType' in entry);
|
||||
}
|
||||
|
||||
export function getPlatformPublicWorkDetailKind(
|
||||
entry: PlatformPublicGalleryCard,
|
||||
): PlatformPublicWorkDetailKind {
|
||||
if (isBigFishGalleryEntry(entry)) {
|
||||
return 'big-fish';
|
||||
}
|
||||
|
||||
if (isPuzzleGalleryEntry(entry)) {
|
||||
return 'puzzle';
|
||||
}
|
||||
|
||||
if (isJumpHopGalleryEntry(entry)) {
|
||||
return 'jump-hop';
|
||||
}
|
||||
|
||||
if (isWoodenFishGalleryEntry(entry)) {
|
||||
return 'wooden-fish';
|
||||
}
|
||||
|
||||
if (isMatch3DGalleryEntry(entry)) {
|
||||
return 'match3d';
|
||||
}
|
||||
|
||||
if (isSquareHoleGalleryEntry(entry)) {
|
||||
return 'square-hole';
|
||||
}
|
||||
|
||||
if (isVisualNovelGalleryEntry(entry)) {
|
||||
return 'visual-novel';
|
||||
}
|
||||
|
||||
if (isBarkBattleGalleryEntry(entry)) {
|
||||
return 'bark-battle';
|
||||
}
|
||||
|
||||
if (isEdutainmentGalleryEntry(entry)) {
|
||||
return 'edutainment';
|
||||
}
|
||||
|
||||
return 'rpg';
|
||||
}
|
||||
|
||||
export function resolvePlatformPublicWorkDetailOpenStrategy(
|
||||
entry: PlatformPublicGalleryCard,
|
||||
): PlatformPublicWorkDetailOpenStrategy {
|
||||
if (isBigFishGalleryEntry(entry)) {
|
||||
return {
|
||||
type: 'use-entry',
|
||||
kind: 'big-fish',
|
||||
};
|
||||
}
|
||||
|
||||
if (isPuzzleGalleryEntry(entry)) {
|
||||
return {
|
||||
type: 'load-puzzle-detail',
|
||||
profileId: entry.profileId,
|
||||
};
|
||||
}
|
||||
|
||||
if (isJumpHopGalleryEntry(entry)) {
|
||||
return {
|
||||
type: 'load-jump-hop-detail',
|
||||
profileId: entry.profileId,
|
||||
};
|
||||
}
|
||||
|
||||
if (isWoodenFishGalleryEntry(entry)) {
|
||||
return {
|
||||
type: 'load-wooden-fish-detail',
|
||||
profileId: entry.profileId,
|
||||
};
|
||||
}
|
||||
|
||||
if (isMatch3DGalleryEntry(entry)) {
|
||||
return {
|
||||
type: 'use-entry',
|
||||
kind: 'match3d',
|
||||
};
|
||||
}
|
||||
|
||||
if (isSquareHoleGalleryEntry(entry)) {
|
||||
return {
|
||||
type: 'use-entry',
|
||||
kind: 'square-hole',
|
||||
};
|
||||
}
|
||||
|
||||
if (isVisualNovelGalleryEntry(entry)) {
|
||||
return {
|
||||
type: 'load-visual-novel-detail',
|
||||
profileId: entry.profileId,
|
||||
};
|
||||
}
|
||||
|
||||
if (isBarkBattleGalleryEntry(entry)) {
|
||||
return {
|
||||
type: 'use-entry',
|
||||
kind: 'bark-battle',
|
||||
};
|
||||
}
|
||||
|
||||
if (isEdutainmentGalleryEntry(entry)) {
|
||||
return {
|
||||
type: 'use-entry',
|
||||
kind: 'edutainment',
|
||||
};
|
||||
}
|
||||
|
||||
if (isRpgPublicWorkDetailEntry(entry)) {
|
||||
return {
|
||||
type: 'load-rpg-detail',
|
||||
entry,
|
||||
};
|
||||
}
|
||||
|
||||
const exhaustive: never = entry;
|
||||
return exhaustive;
|
||||
}
|
||||
|
||||
export function resolvePlatformPublicWorkActionMode(
|
||||
entry: PlatformPublicGalleryCard,
|
||||
viewerUserId: string | null | undefined,
|
||||
): PlatformPublicWorkActionMode {
|
||||
return viewerUserId?.trim() && entry.ownerUserId === viewerUserId.trim()
|
||||
? 'edit'
|
||||
: 'remix';
|
||||
}
|
||||
Reference in New Issue
Block a user