refactor: 深化公开作品详情状态策略
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { CustomWorldGalleryCard } from '../../../packages/shared/src/contracts/runtime';
|
||||
import { buildPublicWorkStagePath } from '../../routing/appPageRoutes';
|
||||
import {
|
||||
isBarkBattleGalleryEntry,
|
||||
isBigFishGalleryEntry,
|
||||
@@ -11,6 +12,10 @@ import {
|
||||
isWoodenFishGalleryEntry,
|
||||
type PlatformPublicGalleryCard,
|
||||
} from '../rpg-entry/rpgEntryWorldPresentation';
|
||||
import {
|
||||
canExposePublicWork,
|
||||
EDUTAINMENT_HIDDEN_MESSAGE,
|
||||
} from './platformEdutainmentVisibility';
|
||||
|
||||
export type PlatformPublicWorkDetailKind =
|
||||
| 'bark-battle'
|
||||
@@ -55,6 +60,34 @@ export type PlatformPublicWorkDetailOpenStrategy =
|
||||
|
||||
export type PlatformPublicWorkActionMode = 'edit' | 'remix';
|
||||
|
||||
export type PlatformPublicWorkDetailOpenDecision =
|
||||
| {
|
||||
type: 'blocked';
|
||||
selectedDetail: null;
|
||||
errorMessage: string;
|
||||
selectionStage: 'platform';
|
||||
historyPath: null;
|
||||
}
|
||||
| {
|
||||
type: 'open';
|
||||
selectedDetail: PlatformPublicGalleryCard;
|
||||
errorMessage: null;
|
||||
selectionStage: 'work-detail';
|
||||
historyPath: string | null;
|
||||
};
|
||||
|
||||
export type PlatformPublicWorkDetailOpenDecisionDeps = {
|
||||
canExposeEntry?: (entry: PlatformPublicGalleryCard) => boolean;
|
||||
hiddenMessage?: string;
|
||||
buildWorkDetailPath?: (publicWorkCode: string) => string;
|
||||
};
|
||||
|
||||
export type ActivePlatformPublicWorkAuthorEntryInput = {
|
||||
selectionStage: string;
|
||||
selectedPublicWorkDetail: PlatformPublicGalleryCard | null;
|
||||
selectedRpgDetailEntry: CustomWorldGalleryCard | null;
|
||||
};
|
||||
|
||||
export function isRpgPublicWorkDetailEntry(
|
||||
entry: PlatformPublicGalleryCard,
|
||||
): entry is CustomWorldGalleryCard {
|
||||
@@ -188,3 +221,57 @@ export function resolvePlatformPublicWorkActionMode(
|
||||
? 'edit'
|
||||
: 'remix';
|
||||
}
|
||||
|
||||
export function resolvePlatformPublicWorkDetailOpenDecision(
|
||||
entry: PlatformPublicGalleryCard,
|
||||
deps: PlatformPublicWorkDetailOpenDecisionDeps = {},
|
||||
): PlatformPublicWorkDetailOpenDecision {
|
||||
const canExposeEntry = deps.canExposeEntry ?? canExposePublicWork;
|
||||
const hiddenMessage = deps.hiddenMessage ?? EDUTAINMENT_HIDDEN_MESSAGE;
|
||||
const buildWorkDetailPath =
|
||||
deps.buildWorkDetailPath ??
|
||||
((publicWorkCode: string) =>
|
||||
buildPublicWorkStagePath('work-detail', publicWorkCode));
|
||||
|
||||
if (!canExposeEntry(entry)) {
|
||||
return {
|
||||
type: 'blocked',
|
||||
selectedDetail: null,
|
||||
errorMessage: hiddenMessage,
|
||||
selectionStage: 'platform',
|
||||
historyPath: null,
|
||||
};
|
||||
}
|
||||
|
||||
const publicWorkCode = entry.publicWorkCode?.trim()
|
||||
? entry.publicWorkCode
|
||||
: null;
|
||||
|
||||
return {
|
||||
type: 'open',
|
||||
selectedDetail: entry,
|
||||
errorMessage: null,
|
||||
selectionStage: 'work-detail',
|
||||
historyPath: publicWorkCode ? buildWorkDetailPath(publicWorkCode) : null,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveActivePlatformPublicWorkAuthorEntry({
|
||||
selectionStage,
|
||||
selectedPublicWorkDetail,
|
||||
selectedRpgDetailEntry,
|
||||
}: ActivePlatformPublicWorkAuthorEntryInput): PlatformPublicGalleryCard | null {
|
||||
if (selectionStage === 'work-detail') {
|
||||
return selectedPublicWorkDetail;
|
||||
}
|
||||
|
||||
if (
|
||||
selectionStage === 'detail' &&
|
||||
selectedRpgDetailEntry &&
|
||||
selectedRpgDetailEntry.visibility !== 'draft'
|
||||
) {
|
||||
return selectedRpgDetailEntry;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user