refactor: 收口创作直达恢复判定

This commit is contained in:
2026-06-04 01:43:31 +08:00
parent 75593b8860
commit 0d2d391cb2
6 changed files with 98 additions and 19 deletions

View File

@@ -158,7 +158,6 @@ import {
} from '../../services/creationEntryConfigService';
import {
clearCreationUrlState,
isCreationRestorePath,
readCreationUrlState,
writeCreationUrlState,
} from '../../services/creationUrlState';
@@ -408,9 +407,9 @@ import {
buildSquareHoleCreationUrlState,
buildVisualNovelCreationUrlState,
buildWoodenFishCreationUrlState,
hasCreationUrlStateValue,
hasPuzzleRuntimeUrlStateValue,
normalizeCreationUrlValue,
resolveInitialCreationUrlRestoreDecision,
} from './platformCreationUrlStateModel';
import { resolvePlatformCreationWorkDeleteConfirmationModel } from './platformCreationWorkDeleteFlow';
import {
@@ -12136,23 +12135,22 @@ export function PlatformEntryFlowShellImpl({
);
useEffect(() => {
if (handledInitialCreationUrlStateRef.current) {
const restoreDecision = resolveInitialCreationUrlRestoreDecision({
handled: handledInitialCreationUrlStateRef.current,
pathname: window.location.pathname,
state: initialCreationUrlState,
isLoadingPlatform: platformBootstrap.isLoadingPlatform,
canReadProtectedData: platformBootstrap.canReadProtectedData,
});
if (restoreDecision.type === 'skip' || restoreDecision.type === 'wait') {
return;
}
if (!isCreationRestorePath(window.location.pathname)) {
if (restoreDecision.type === 'mark-handled') {
handledInitialCreationUrlStateRef.current = true;
return;
}
if (!hasCreationUrlStateValue(initialCreationUrlState)) {
handledInitialCreationUrlStateRef.current = true;
return;
}
if (platformBootstrap.isLoadingPlatform) {
return;
}
if (!platformBootstrap.canReadProtectedData) {
return;
}
handledInitialCreationUrlStateRef.current = true;

View File

@@ -32,6 +32,7 @@ import {
hasCreationUrlStateValue,
hasPuzzleRuntimeUrlStateValue,
normalizeCreationUrlValue,
resolveInitialCreationUrlRestoreDecision,
} from './platformCreationUrlStateModel';
describe('platformCreationUrlStateModel', () => {
@@ -49,6 +50,50 @@ describe('platformCreationUrlStateModel', () => {
expect(hasCreationUrlStateValue({})).toBe(false);
});
test('resolves initial creation url restore readiness', () => {
const readyParams = {
handled: false,
pathname: '/creation/puzzle/result',
state: { sessionId: 'puzzle-session-1' },
isLoadingPlatform: false,
canReadProtectedData: true,
};
expect(
resolveInitialCreationUrlRestoreDecision({
...readyParams,
handled: true,
}),
).toEqual({ type: 'skip' });
expect(
resolveInitialCreationUrlRestoreDecision({
...readyParams,
pathname: '/works/detail',
}),
).toEqual({ type: 'mark-handled' });
expect(
resolveInitialCreationUrlRestoreDecision({
...readyParams,
state: {},
}),
).toEqual({ type: 'mark-handled' });
expect(
resolveInitialCreationUrlRestoreDecision({
...readyParams,
isLoadingPlatform: true,
}),
).toEqual({ type: 'wait' });
expect(
resolveInitialCreationUrlRestoreDecision({
...readyParams,
canReadProtectedData: false,
}),
).toEqual({ type: 'wait' });
expect(resolveInitialCreationUrlRestoreDecision(readyParams)).toEqual({
type: 'restore',
});
});
test('builds creation restore state for core session based plays', () => {
expect(
buildBigFishCreationUrlState({

View File

@@ -6,7 +6,10 @@ import type { PuzzleAgentSessionSnapshot } from '../../../packages/shared/src/co
import type { PuzzleWorkSummary } from '../../../packages/shared/src/contracts/puzzleWorkSummary';
import type { SquareHoleSessionSnapshot } from '../../../packages/shared/src/contracts/squareHoleAgent';
import type { VisualNovelAgentSessionSnapshot } from '../../../packages/shared/src/contracts/visualNovel';
import type { CreationUrlState } from '../../services/creationUrlState';
import {
type CreationUrlState,
isCreationRestorePath,
} from '../../services/creationUrlState';
import type {
JumpHopSessionSnapshotResponse,
JumpHopWorkProfileResponse,
@@ -57,6 +60,37 @@ export function buildPuzzleRuntimeUrlStateKey(state: PuzzleRuntimeUrlState) {
].join('|');
}
export type InitialCreationUrlRestoreDecision =
| { type: 'skip' }
| { type: 'mark-handled' }
| { type: 'wait' }
| { type: 'restore' };
export function resolveInitialCreationUrlRestoreDecision(params: {
handled: boolean;
pathname: string | undefined;
state: CreationUrlState;
isLoadingPlatform: boolean;
canReadProtectedData: boolean;
}): InitialCreationUrlRestoreDecision {
if (params.handled) {
return { type: 'skip' };
}
if (
!isCreationRestorePath(params.pathname) ||
!hasCreationUrlStateValue(params.state)
) {
return { type: 'mark-handled' };
}
if (params.isLoadingPlatform || !params.canReadProtectedData) {
return { type: 'wait' };
}
return { type: 'restore' };
}
export function buildBigFishCreationUrlState(
session: BigFishSessionSnapshotResponse | null,
): CreationUrlState {