Merge pull request 'codex/frontend-error-dialogs' (#40) from codex/frontend-error-dialogs into master
Reviewed-on: #40
This commit was merged in pull request #40.
This commit is contained in:
@@ -13,7 +13,7 @@ interface CustomWorldGenerationViewProps {
|
||||
anchorEntries?: CustomWorldStructuredAnchorEntry[];
|
||||
progress: CustomWorldGenerationProgress | null;
|
||||
isGenerating: boolean;
|
||||
error: string | null;
|
||||
error?: string | null;
|
||||
onBack: () => void;
|
||||
onEditSetting: () => void;
|
||||
onRetry: () => void;
|
||||
@@ -110,7 +110,6 @@ export function CustomWorldGenerationView({
|
||||
anchorEntries = [],
|
||||
progress,
|
||||
isGenerating,
|
||||
error,
|
||||
onBack,
|
||||
onEditSetting,
|
||||
onRetry,
|
||||
@@ -123,7 +122,6 @@ export function CustomWorldGenerationView({
|
||||
settingDescription = '这段文本会直接驱动本轮世界框架、角色与场景生成。',
|
||||
progressTitle = '生成进度',
|
||||
activeBadgeLabel = '世界建设中',
|
||||
pausedBadgeLabel = '生成已暂停',
|
||||
idleBadgeLabel = '等待操作',
|
||||
structuredEmptyText = '正在整理当前设定结构,请稍后。',
|
||||
hideBatchModule = false,
|
||||
@@ -169,11 +167,7 @@ export function CustomWorldGenerationView({
|
||||
<span className="break-keep">{backLabel}</span>
|
||||
</button>
|
||||
<div className="rounded-full border border-[#f05816] bg-white/72 px-3 py-1.5 text-[11px] font-black tracking-[0.08em] text-[#df6118] shadow-[0_12px_30px_rgba(214,77,31,0.08)] backdrop-blur-md sm:px-4 sm:text-xs">
|
||||
{isGenerating
|
||||
? activeBadgeLabel
|
||||
: error
|
||||
? pausedBadgeLabel
|
||||
: idleBadgeLabel}
|
||||
{isGenerating ? activeBadgeLabel : idleBadgeLabel}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -195,12 +189,6 @@ export function CustomWorldGenerationView({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<div className="mt-4 rounded-[1.4rem] border border-[#d88969]/35 bg-white/76 px-4 py-3 text-sm leading-6 text-[#a6402f] backdrop-blur-md">
|
||||
{error}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="mt-4 flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:justify-end">
|
||||
{!isGenerating ? (
|
||||
<>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import type { BigFishWorkSummary } from '../../../packages/shared/src/contracts/bigFishWorkSummary';
|
||||
import type { BarkBattleWorkSummary } from '../../../packages/shared/src/contracts/barkBattle';
|
||||
import type { BigFishWorkSummary } from '../../../packages/shared/src/contracts/bigFishWorkSummary';
|
||||
import type { CustomWorldWorkSummary } from '../../../packages/shared/src/contracts/customWorldAgent';
|
||||
import type { BabyObjectMatchDraft } from '../../../packages/shared/src/contracts/edutainmentBabyObject';
|
||||
import type { JumpHopWorkSummaryResponse } from '../../../packages/shared/src/contracts/jumpHop';
|
||||
import type { Match3DWorkSummary } from '../../../packages/shared/src/contracts/match3dWorks';
|
||||
import type { PuzzleWorkSummary } from '../../../packages/shared/src/contracts/puzzleWorkSummary';
|
||||
import type { JumpHopWorkSummaryResponse } from '../../../packages/shared/src/contracts/jumpHop';
|
||||
import type { CustomWorldLibraryEntry } from '../../../packages/shared/src/contracts/runtime';
|
||||
import type { SquareHoleWorkSummary } from '../../../packages/shared/src/contracts/squareHoleWorks';
|
||||
import type { VisualNovelWorkSummary } from '../../../packages/shared/src/contracts/visualNovel';
|
||||
@@ -43,7 +43,6 @@ type CustomWorldCreationHubProps = {
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
onRetry: () => void;
|
||||
createError?: string | null;
|
||||
createBusy?: boolean;
|
||||
entryConfig: CreationEntryConfig;
|
||||
creationTypes: readonly PlatformCreationTypeCard[];
|
||||
@@ -154,7 +153,6 @@ export function CustomWorldCreationHub({
|
||||
loading,
|
||||
error,
|
||||
onRetry,
|
||||
createError = null,
|
||||
createBusy = false,
|
||||
entryConfig,
|
||||
creationTypes,
|
||||
@@ -360,7 +358,6 @@ export function CustomWorldCreationHub({
|
||||
{showStartCard ? (
|
||||
<CustomWorldCreationStartCard
|
||||
busy={createBusy}
|
||||
error={createError}
|
||||
entryConfig={entryConfig}
|
||||
creationTypes={creationTypes}
|
||||
onCreateType={onCreateType}
|
||||
@@ -377,12 +374,11 @@ export function CustomWorldCreationHub({
|
||||
) : null}
|
||||
|
||||
{showWorkShelf && error ? (
|
||||
<div className="platform-banner platform-banner--danger rounded-[1.4rem] px-4 py-4 text-sm leading-7">
|
||||
<div>{error}</div>
|
||||
<div className="flex justify-end">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onRetry}
|
||||
className="platform-button platform-button--ghost mt-3 min-h-0 rounded-full px-4 py-2 text-sm"
|
||||
className="platform-button platform-button--ghost min-h-0 rounded-full px-4 py-2 text-sm"
|
||||
>
|
||||
重试
|
||||
</button>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Coins, Trophy } from 'lucide-react';
|
||||
import { useMemo, useState, type UIEvent } from 'react';
|
||||
import { type UIEvent,useMemo, useState } from 'react';
|
||||
|
||||
import type { CreationEntryConfig } from '../../services/creationEntryConfigService';
|
||||
import {
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
|
||||
type CustomWorldCreationStartCardProps = {
|
||||
busy?: boolean;
|
||||
error?: string | null;
|
||||
entryConfig: CreationEntryConfig;
|
||||
creationTypes: readonly PlatformCreationTypeCard[];
|
||||
onCreateType: (type: PlatformCreationTypeId) => void;
|
||||
@@ -25,7 +24,6 @@ function shouldShowCreationBadge(badge: string) {
|
||||
|
||||
export function CustomWorldCreationStartCard({
|
||||
busy = false,
|
||||
error = null,
|
||||
entryConfig,
|
||||
creationTypes,
|
||||
onCreateType,
|
||||
@@ -233,11 +231,6 @@ export function CustomWorldCreationStartCard({
|
||||
})}
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<div className="platform-banner platform-banner--danger mt-4 rounded-[1rem] px-3 py-2 text-sm leading-5 sm:rounded-[1.25rem] sm:leading-6">
|
||||
{error}
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -51,7 +51,6 @@ test('dispatches wooden fish creation type selection', () => {
|
||||
<PlatformEntryCreationTypeModal
|
||||
isOpen
|
||||
isBusy={false}
|
||||
error={null}
|
||||
entryConfig={entryConfig}
|
||||
creationTypes={derivePlatformCreationTypes(entryConfig.creationTypes)}
|
||||
onClose={() => {}}
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
export interface PlatformEntryCreationTypeModalProps {
|
||||
isOpen: boolean;
|
||||
isBusy: boolean;
|
||||
error: string | null;
|
||||
entryConfig: CreationEntryConfig;
|
||||
creationTypes: readonly PlatformCreationTypeCard[];
|
||||
onClose: () => void;
|
||||
@@ -94,7 +93,6 @@ function CreationTypeCard(props: {
|
||||
export function PlatformEntryCreationTypeModal({
|
||||
isOpen,
|
||||
isBusy,
|
||||
error,
|
||||
entryConfig,
|
||||
creationTypes,
|
||||
onClose,
|
||||
@@ -172,11 +170,6 @@ export function PlatformEntryCreationTypeModal({
|
||||
))}
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<div className="platform-banner platform-banner--danger mt-4 rounded-[1.25rem] text-sm leading-6">
|
||||
{error}
|
||||
</div>
|
||||
) : null}
|
||||
</UnifiedModal>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import type {
|
||||
BabyObjectMatchDraft,
|
||||
CreateBabyObjectMatchDraftRequest,
|
||||
} from '../../../packages/shared/src/contracts/edutainmentBabyObject';
|
||||
import type { JumpHopWorkSummaryResponse } from '../../../packages/shared/src/contracts/jumpHop';
|
||||
import type {
|
||||
CreateMatch3DSessionRequest,
|
||||
ExecuteMatch3DActionRequest,
|
||||
@@ -160,13 +161,6 @@ import {
|
||||
type CreationEntryConfig,
|
||||
fetchCreationEntryConfig,
|
||||
} from '../../services/creationEntryConfigService';
|
||||
import {
|
||||
cancelCreativeAgentSession,
|
||||
confirmCreativePuzzleTemplate,
|
||||
createCreativeAgentSession,
|
||||
streamCreativeAgentMessage,
|
||||
streamCreativeDraftEdit,
|
||||
} from '../../services/creative-agent';
|
||||
import {
|
||||
clearCreationUrlState,
|
||||
type CreationUrlState,
|
||||
@@ -175,11 +169,12 @@ import {
|
||||
writeCreationUrlState,
|
||||
} from '../../services/creationUrlState';
|
||||
import {
|
||||
clearPuzzleRuntimeUrlState,
|
||||
readPuzzleRuntimeUrlState,
|
||||
writePuzzleRuntimeUrlState,
|
||||
type PuzzleRuntimeUrlState,
|
||||
} from '../../services/puzzleRuntimeUrlState';
|
||||
cancelCreativeAgentSession,
|
||||
confirmCreativePuzzleTemplate,
|
||||
createCreativeAgentSession,
|
||||
streamCreativeAgentMessage,
|
||||
streamCreativeDraftEdit,
|
||||
} from '../../services/creative-agent';
|
||||
import {
|
||||
readCustomWorldAgentUiState,
|
||||
shouldRestoreCustomWorldAgentUiState,
|
||||
@@ -202,7 +197,6 @@ import {
|
||||
JumpHopWorkProfileResponse,
|
||||
JumpHopWorkspaceCreateRequest,
|
||||
} from '../../services/jump-hop/jumpHopClient';
|
||||
import type { JumpHopWorkSummaryResponse } from '../../../packages/shared/src/contracts/jumpHop';
|
||||
import { match3dCreationClient } from '../../services/match3d-creation';
|
||||
import {
|
||||
createLocalMatch3DRuntimeAdapter,
|
||||
@@ -296,6 +290,12 @@ import {
|
||||
listPuzzleWorks,
|
||||
updatePuzzleWork,
|
||||
} from '../../services/puzzle-works';
|
||||
import {
|
||||
clearPuzzleRuntimeUrlState,
|
||||
type PuzzleRuntimeUrlState,
|
||||
readPuzzleRuntimeUrlState,
|
||||
writePuzzleRuntimeUrlState,
|
||||
} from '../../services/puzzleRuntimeUrlState';
|
||||
import { deleteRpgCreationAgentSession } from '../../services/rpg-creation';
|
||||
import { rpgCreationPreviewAdapter } from '../../services/rpg-creation/rpgCreationPreviewAdapter';
|
||||
import {
|
||||
@@ -384,6 +384,7 @@ import {
|
||||
mapVisualNovelWorkToPlatformGalleryCard,
|
||||
mapWoodenFishWorkToPlatformGalleryCard,
|
||||
type PlatformPublicGalleryCard,
|
||||
resolvePlatformPublicWorkCode,
|
||||
} from '../rpg-entry/rpgEntryWorldPresentation';
|
||||
import { useRpgCreationAgentOperationPolling } from '../rpg-entry/useRpgCreationAgentOperationPolling';
|
||||
import { useRpgCreationEnterWorld } from '../rpg-entry/useRpgCreationEnterWorld';
|
||||
@@ -423,6 +424,7 @@ import {
|
||||
PlatformEntryHomeView,
|
||||
type PlatformHomeTab,
|
||||
} from './PlatformEntryHomeView';
|
||||
import { usePlatformDesktopLayout } from './platformEntryResponsive';
|
||||
import {
|
||||
buildCreationHubFallbackItems,
|
||||
resolveRpgCreationErrorMessage,
|
||||
@@ -432,11 +434,18 @@ import type {
|
||||
SelectionStage,
|
||||
} from './platformEntryTypes';
|
||||
import { PlatformEntryWorldDetailView } from './PlatformEntryWorldDetailView';
|
||||
import {
|
||||
PlatformErrorDialog,
|
||||
type PlatformErrorDialogPayload,
|
||||
} from './PlatformErrorDialog';
|
||||
import {
|
||||
PlatformTaskCompletionDialog,
|
||||
type PlatformTaskCompletionDialogPayload,
|
||||
} from './PlatformTaskCompletionDialog';
|
||||
import { PlatformFeedbackView } from './PlatformFeedbackView';
|
||||
import { PlatformWorkDetailView } from './PlatformWorkDetailView';
|
||||
import { usePlatformCreationAgentFlowController } from './usePlatformCreationAgentFlowController';
|
||||
import { usePlatformEntryBootstrap } from './usePlatformEntryBootstrap';
|
||||
import { usePlatformDesktopLayout } from './platformEntryResponsive';
|
||||
import { usePlatformEntryLibraryDetail } from './usePlatformEntryLibraryDetail';
|
||||
import { usePlatformEntryNavigation } from './usePlatformEntryNavigation';
|
||||
|
||||
@@ -448,6 +457,7 @@ type DraftGenerationNoticeStatus = 'generating' | 'ready';
|
||||
type DraftGenerationNotice = {
|
||||
status: DraftGenerationNoticeStatus;
|
||||
seen: boolean;
|
||||
completedAtMs?: number;
|
||||
};
|
||||
type DraftGenerationNoticeMap = Record<string, DraftGenerationNotice>;
|
||||
type CreationWorkShelfKind = CreationWorkShelfItem['kind'];
|
||||
@@ -2025,6 +2035,84 @@ function createPendingDraftShelfState(
|
||||
};
|
||||
}
|
||||
|
||||
function normalizePlatformErrorMessage(message: string | null | undefined) {
|
||||
const normalized = message?.trim();
|
||||
return normalized ? normalized : null;
|
||||
}
|
||||
|
||||
function formatPlatformErrorSource(label: string, id?: string | null) {
|
||||
const normalizedId = id?.trim();
|
||||
return normalizedId ? `${label} ${normalizedId}` : label;
|
||||
}
|
||||
|
||||
function formatPlatformTaskCompletionSource(label: string, id?: string | null) {
|
||||
const normalizedId = id?.trim();
|
||||
return normalizedId ? `${label} ${normalizedId}` : label;
|
||||
}
|
||||
|
||||
function buildPlatformErrorDialogDismissKey(
|
||||
error: (PlatformErrorDialogPayload & { key: string }) | null,
|
||||
) {
|
||||
return error ? `${error.key}:${error.source}:${error.message}` : null;
|
||||
}
|
||||
|
||||
function buildPlatformTaskCompletionDialogDismissKey(
|
||||
completion:
|
||||
| (PlatformTaskCompletionDialogPayload & {
|
||||
key: string;
|
||||
completedAtMs: number | null;
|
||||
})
|
||||
| null,
|
||||
) {
|
||||
return completion
|
||||
? `${completion.key}:${completion.source}:${completion.message}:${completion.completedAtMs ?? 0}`
|
||||
: null;
|
||||
}
|
||||
|
||||
function pickDraftCompletionDialogSourceId(
|
||||
ids: Array<string | null | undefined>,
|
||||
) {
|
||||
const normalizedIds = ids
|
||||
.map((id) => id?.trim() ?? '')
|
||||
.filter((id) => Boolean(id));
|
||||
return (
|
||||
normalizedIds.find((id) => /session/i.test(id)) ??
|
||||
normalizedIds.find((id) => /work/i.test(id)) ??
|
||||
normalizedIds.find((id) => /draft/i.test(id)) ??
|
||||
normalizedIds.find((id) => /run/i.test(id)) ??
|
||||
normalizedIds.find((id) => /profile/i.test(id)) ??
|
||||
normalizedIds[0] ??
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
function buildDraftCompletionDialogSource(
|
||||
kind: CreationWorkShelfKind,
|
||||
ids: Array<string | null | undefined>,
|
||||
) {
|
||||
const sourceId = pickDraftCompletionDialogSourceId(ids);
|
||||
switch (kind) {
|
||||
case 'rpg':
|
||||
return formatPlatformTaskCompletionSource('RPG 草稿', sourceId);
|
||||
case 'big-fish':
|
||||
return formatPlatformTaskCompletionSource('大鱼吃小鱼草稿', sourceId);
|
||||
case 'match3d':
|
||||
return formatPlatformTaskCompletionSource('抓大鹅草稿', sourceId);
|
||||
case 'square-hole':
|
||||
return formatPlatformTaskCompletionSource('方洞挑战草稿', sourceId);
|
||||
case 'jump-hop':
|
||||
return formatPlatformTaskCompletionSource('跳一跳草稿', sourceId);
|
||||
case 'puzzle':
|
||||
return formatPlatformTaskCompletionSource('拼图草稿', sourceId);
|
||||
case 'visual-novel':
|
||||
return formatPlatformTaskCompletionSource('视觉小说草稿', sourceId);
|
||||
case 'bark-battle':
|
||||
return formatPlatformTaskCompletionSource('汪汪声浪草稿', sourceId);
|
||||
case 'baby-object-match':
|
||||
return formatPlatformTaskCompletionSource('宝贝识物草稿', sourceId);
|
||||
}
|
||||
}
|
||||
|
||||
function createMiniGameDraftGenerationStateForRestoredDraft(
|
||||
kind: MiniGameDraftGenerationKind,
|
||||
metadata?: MiniGameDraftGenerationState['metadata'],
|
||||
@@ -3322,6 +3410,17 @@ export function PlatformEntryFlowShellImpl({
|
||||
useState<DraftGenerationNoticeMap>({});
|
||||
const [pendingDraftShelfItems, setPendingDraftShelfItems] =
|
||||
useState<PendingDraftShelfMap>({});
|
||||
const [
|
||||
pendingPlatformTaskCompletionDialog,
|
||||
setPendingPlatformTaskCompletionDialog,
|
||||
] = useState<
|
||||
| (PlatformTaskCompletionDialogPayload & {
|
||||
key: string;
|
||||
completedAtMs: number | null;
|
||||
})
|
||||
| null
|
||||
>(null);
|
||||
const [profileTaskRefreshKey, setProfileTaskRefreshKey] = useState(0);
|
||||
const [initialCreationUrlState] = useState(() => readCreationUrlState());
|
||||
const handledInitialCreationUrlStateRef = useRef(false);
|
||||
const [initialPuzzleRuntimeUrlState] = useState(() =>
|
||||
@@ -3399,10 +3498,14 @@ export function PlatformEntryFlowShellImpl({
|
||||
return;
|
||||
}
|
||||
|
||||
const completedAtMs = status === 'ready' ? Date.now() : undefined;
|
||||
setDraftGenerationNotices((current) => {
|
||||
const next = { ...current };
|
||||
for (const key of uniqueKeys) {
|
||||
next[key] = { status, seen };
|
||||
next[key] =
|
||||
completedAtMs === undefined
|
||||
? { status, seen }
|
||||
: { status, seen, completedAtMs };
|
||||
}
|
||||
return next;
|
||||
});
|
||||
@@ -3444,12 +3547,13 @@ export function PlatformEntryFlowShellImpl({
|
||||
);
|
||||
const markDraftGenerating = useCallback(
|
||||
(kind: CreationWorkShelfKind, ids: Array<string | null | undefined>) => {
|
||||
setPendingPlatformTaskCompletionDialog(null);
|
||||
updateDraftGenerationNotices(
|
||||
collectDraftNoticeKeys(kind, ids),
|
||||
'generating',
|
||||
);
|
||||
},
|
||||
[updateDraftGenerationNotices],
|
||||
[setPendingPlatformTaskCompletionDialog, updateDraftGenerationNotices],
|
||||
);
|
||||
const markDraftReady = useCallback(
|
||||
(
|
||||
@@ -3462,17 +3566,26 @@ export function PlatformEntryFlowShellImpl({
|
||||
'ready',
|
||||
viewedImmediately,
|
||||
);
|
||||
setProfileTaskRefreshKey((current) => current + 1);
|
||||
const completedAtMs = Date.now();
|
||||
setPendingPlatformTaskCompletionDialog({
|
||||
key: `${kind}:${collectDraftNoticeKeys(kind, ids).join('|')}:${completedAtMs}`,
|
||||
source: buildDraftCompletionDialogSource(kind, ids),
|
||||
message: '生成任务已完成,可以继续查看草稿。',
|
||||
completedAtMs,
|
||||
});
|
||||
},
|
||||
[updateDraftGenerationNotices],
|
||||
[setPendingPlatformTaskCompletionDialog, updateDraftGenerationNotices],
|
||||
);
|
||||
const markPendingDraftGenerating = useCallback(
|
||||
(
|
||||
kind: Exclude<CreationWorkShelfKind, 'rpg'>,
|
||||
id: string | null | undefined,
|
||||
) => {
|
||||
setPendingPlatformTaskCompletionDialog(null);
|
||||
updatePendingDraftShelfItem(kind, id, 'generating');
|
||||
},
|
||||
[updatePendingDraftShelfItem],
|
||||
[setPendingPlatformTaskCompletionDialog, updatePendingDraftShelfItem],
|
||||
);
|
||||
const markPendingDraftReady = useCallback(
|
||||
(
|
||||
@@ -5842,6 +5955,372 @@ export function PlatformEntryFlowShellImpl({
|
||||
isMiniGameDraftGenerating(
|
||||
activePuzzleBackgroundCompileTask?.generationState ?? null,
|
||||
);
|
||||
const [dismissedPlatformErrorDialogKey, setDismissedPlatformErrorDialogKey] =
|
||||
useState<string | null>(null);
|
||||
const [
|
||||
dismissedPlatformTaskCompletionDialogKey,
|
||||
setDismissedPlatformTaskCompletionDialogKey,
|
||||
] = useState<string | null>(null);
|
||||
const currentPlatformErrorDialog = useMemo<
|
||||
(PlatformErrorDialogPayload & { key: string }) | null
|
||||
>(() => {
|
||||
const candidates: Array<{
|
||||
key: string;
|
||||
source: string;
|
||||
message: string | null | undefined;
|
||||
}> = [
|
||||
{
|
||||
key: 'creation-entry-config',
|
||||
source: '创作入口配置',
|
||||
message: creationEntryConfigError,
|
||||
},
|
||||
{
|
||||
key: 'platform-bootstrap',
|
||||
source: '平台首页',
|
||||
message: platformBootstrap.platformError,
|
||||
},
|
||||
{
|
||||
key: 'rpg-creation-type',
|
||||
source: '创作入口',
|
||||
message: sessionController.creationTypeError,
|
||||
},
|
||||
{
|
||||
key: 'rpg-restore',
|
||||
source: '创作作品架',
|
||||
message: sessionController.agentWorkspaceRestoreError,
|
||||
},
|
||||
{
|
||||
key: 'rpg-result',
|
||||
source: formatPlatformErrorSource(
|
||||
'RPG 草稿',
|
||||
sessionController.agentSession?.sessionId ??
|
||||
sessionController.generatedCustomWorldProfile?.id,
|
||||
),
|
||||
message: resultViewError,
|
||||
},
|
||||
{
|
||||
key: 'public-work-detail',
|
||||
source: formatPlatformErrorSource(
|
||||
'作品详情',
|
||||
selectedPublicWorkDetail
|
||||
? resolvePlatformPublicWorkCode(selectedPublicWorkDetail)
|
||||
: selectedDetailEntry?.profileId,
|
||||
),
|
||||
message: publicWorkDetailError ?? detailNavigation.detailError,
|
||||
},
|
||||
{
|
||||
key: 'big-fish',
|
||||
source: formatPlatformErrorSource(
|
||||
selectionStage === 'big-fish-runtime' ? '大鱼吃小鱼游玩' : '大鱼草稿',
|
||||
bigFishRun?.runId ?? bigFishSession?.sessionId,
|
||||
),
|
||||
message: bigFishError,
|
||||
},
|
||||
{
|
||||
key: 'match3d',
|
||||
source: formatPlatformErrorSource(
|
||||
selectionStage === 'match3d-runtime' ? '抓大鹅游玩' : '抓大鹅草稿',
|
||||
match3dRun?.runId ??
|
||||
match3dGenerationViewSession?.sessionId ??
|
||||
match3dSession?.sessionId,
|
||||
),
|
||||
message: match3dGenerationViewError ?? match3dError,
|
||||
},
|
||||
{
|
||||
key: 'square-hole',
|
||||
source: formatPlatformErrorSource(
|
||||
selectionStage === 'square-hole-runtime'
|
||||
? '方洞挑战游玩'
|
||||
: '方洞挑战草稿',
|
||||
squareHoleRun?.runId ?? squareHoleSession?.sessionId,
|
||||
),
|
||||
message: squareHoleError,
|
||||
},
|
||||
{
|
||||
key: 'jump-hop',
|
||||
source: formatPlatformErrorSource(
|
||||
selectionStage === 'jump-hop-runtime' ? '跳一跳游玩' : '跳一跳草稿',
|
||||
jumpHopRun?.runId ?? jumpHopSession?.sessionId,
|
||||
),
|
||||
message: jumpHopError,
|
||||
},
|
||||
{
|
||||
key: 'wooden-fish',
|
||||
source: formatPlatformErrorSource(
|
||||
selectionStage === 'wooden-fish-runtime'
|
||||
? '敲木鱼游玩'
|
||||
: '敲木鱼草稿',
|
||||
woodenFishRun?.runId ?? woodenFishSession?.sessionId,
|
||||
),
|
||||
message: woodenFishError,
|
||||
},
|
||||
{
|
||||
key: 'puzzle',
|
||||
source: formatPlatformErrorSource(
|
||||
selectionStage === 'puzzle-runtime' ? '拼图游玩' : '拼图草稿',
|
||||
puzzleRun?.runId ??
|
||||
puzzleGenerationViewSession?.sessionId ??
|
||||
puzzleSession?.sessionId,
|
||||
),
|
||||
message: puzzleGenerationViewError ?? puzzleCreationError ?? puzzleError,
|
||||
},
|
||||
{
|
||||
key: 'puzzle-onboarding',
|
||||
source: '拼图首次创作',
|
||||
message: puzzleOnboardingError,
|
||||
},
|
||||
{
|
||||
key: 'puzzle-shelf',
|
||||
source: '拼图作品架',
|
||||
message: puzzleShelfError,
|
||||
},
|
||||
{
|
||||
key: 'visual-novel',
|
||||
source: formatPlatformErrorSource(
|
||||
selectionStage === 'visual-novel-runtime'
|
||||
? '视觉小说游玩'
|
||||
: '视觉小说草稿',
|
||||
visualNovelRun?.runId ?? visualNovelSession?.sessionId,
|
||||
),
|
||||
message: visualNovelError,
|
||||
},
|
||||
{
|
||||
key: 'baby-object-match',
|
||||
source: formatPlatformErrorSource(
|
||||
selectionStage === 'baby-object-match-runtime'
|
||||
? '宝贝识物游玩'
|
||||
: '宝贝识物草稿',
|
||||
babyObjectMatchDraft?.profileId,
|
||||
),
|
||||
message: babyObjectMatchError,
|
||||
},
|
||||
{
|
||||
key: 'bark-battle',
|
||||
source: formatPlatformErrorSource(
|
||||
selectionStage === 'bark-battle-runtime'
|
||||
? '汪汪声浪游玩'
|
||||
: '汪汪声浪草稿',
|
||||
barkBattlePublishedConfig?.workId ?? barkBattleDraftConfig?.workId,
|
||||
),
|
||||
message: barkBattleError,
|
||||
},
|
||||
{
|
||||
key: 'creative-agent',
|
||||
source: formatPlatformErrorSource(
|
||||
'智能创作 Agent',
|
||||
creativeAgentSession?.sessionId,
|
||||
),
|
||||
message: creativeAgentError,
|
||||
},
|
||||
{
|
||||
key: 'rpg-generation',
|
||||
source: formatPlatformErrorSource(
|
||||
'RPG 草稿生成',
|
||||
sessionController.agentSession?.sessionId,
|
||||
),
|
||||
message: sessionController.activeGenerationError,
|
||||
},
|
||||
];
|
||||
|
||||
for (const candidate of candidates) {
|
||||
const message = normalizePlatformErrorMessage(candidate.message);
|
||||
if (message) {
|
||||
return {
|
||||
key: candidate.key,
|
||||
source: candidate.source,
|
||||
message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}, [
|
||||
babyObjectMatchDraft?.profileId,
|
||||
babyObjectMatchError,
|
||||
barkBattleDraftConfig?.workId,
|
||||
barkBattleError,
|
||||
barkBattlePublishedConfig?.workId,
|
||||
bigFishError,
|
||||
bigFishRun?.runId,
|
||||
bigFishSession?.sessionId,
|
||||
creationEntryConfigError,
|
||||
creativeAgentError,
|
||||
creativeAgentSession?.sessionId,
|
||||
detailNavigation.detailError,
|
||||
jumpHopError,
|
||||
jumpHopRun?.runId,
|
||||
jumpHopSession?.sessionId,
|
||||
match3dError,
|
||||
match3dGenerationViewError,
|
||||
match3dGenerationViewSession?.sessionId,
|
||||
match3dRun?.runId,
|
||||
match3dSession?.sessionId,
|
||||
platformBootstrap.platformError,
|
||||
publicWorkDetailError,
|
||||
puzzleCreationError,
|
||||
puzzleError,
|
||||
puzzleGenerationViewError,
|
||||
puzzleGenerationViewSession?.sessionId,
|
||||
puzzleOnboardingError,
|
||||
puzzleRun?.runId,
|
||||
puzzleSession?.sessionId,
|
||||
puzzleShelfError,
|
||||
resultViewError,
|
||||
selectedDetailEntry?.profileId,
|
||||
selectedPublicWorkDetail,
|
||||
selectionStage,
|
||||
sessionController.activeGenerationError,
|
||||
sessionController.agentSession?.sessionId,
|
||||
sessionController.agentWorkspaceRestoreError,
|
||||
sessionController.creationTypeError,
|
||||
sessionController.generatedCustomWorldProfile?.id,
|
||||
squareHoleError,
|
||||
squareHoleRun?.runId,
|
||||
squareHoleSession?.sessionId,
|
||||
visualNovelError,
|
||||
visualNovelRun?.runId,
|
||||
visualNovelSession?.sessionId,
|
||||
woodenFishError,
|
||||
woodenFishRun?.runId,
|
||||
woodenFishSession?.sessionId,
|
||||
]);
|
||||
const currentPlatformTaskCompletionDialog = useMemo<
|
||||
| (PlatformTaskCompletionDialogPayload & {
|
||||
key: string;
|
||||
completedAtMs: number | null;
|
||||
})
|
||||
| null
|
||||
>(() => pendingPlatformTaskCompletionDialog, [
|
||||
pendingPlatformTaskCompletionDialog,
|
||||
]);
|
||||
const activePlatformTaskCompletionDialogDismissKey =
|
||||
buildPlatformTaskCompletionDialogDismissKey(
|
||||
currentPlatformTaskCompletionDialog,
|
||||
);
|
||||
const activePlatformTaskCompletionDialog =
|
||||
activePlatformTaskCompletionDialogDismissKey &&
|
||||
activePlatformTaskCompletionDialogDismissKey ===
|
||||
dismissedPlatformTaskCompletionDialogKey
|
||||
? null
|
||||
: currentPlatformTaskCompletionDialog;
|
||||
const activePlatformErrorDialogDismissKey =
|
||||
buildPlatformErrorDialogDismissKey(currentPlatformErrorDialog);
|
||||
const activePlatformErrorDialog =
|
||||
activePlatformErrorDialogDismissKey &&
|
||||
activePlatformErrorDialogDismissKey === dismissedPlatformErrorDialogKey
|
||||
? null
|
||||
: currentPlatformErrorDialog;
|
||||
const closePlatformErrorDialog = useCallback(() => {
|
||||
if (!currentPlatformErrorDialog) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dismissKey = buildPlatformErrorDialogDismissKey(
|
||||
currentPlatformErrorDialog,
|
||||
);
|
||||
if (dismissKey) {
|
||||
setDismissedPlatformErrorDialogKey(dismissKey);
|
||||
}
|
||||
|
||||
if (currentPlatformErrorDialog.key === 'creation-entry-config') {
|
||||
setCreationEntryConfigError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'platform-bootstrap') {
|
||||
platformBootstrap.setPlatformError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'rpg-creation-type') {
|
||||
sessionController.setCreationTypeError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'rpg-restore') {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
currentPlatformErrorDialog.key === 'rpg-result' ||
|
||||
currentPlatformErrorDialog.key === 'rpg-generation'
|
||||
) {
|
||||
autosaveCoordinator.setCustomWorldAutoSaveError(null);
|
||||
sessionController.setCustomWorldError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'public-work-detail') {
|
||||
setPublicWorkDetailError(null);
|
||||
detailNavigation.setDetailError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'big-fish') {
|
||||
setBigFishError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'match3d') {
|
||||
setMatch3DError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'square-hole') {
|
||||
setSquareHoleError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'jump-hop') {
|
||||
setJumpHopError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'wooden-fish') {
|
||||
setWoodenFishError(null);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
currentPlatformErrorDialog.key === 'puzzle' ||
|
||||
currentPlatformErrorDialog.key === 'puzzle-onboarding' ||
|
||||
currentPlatformErrorDialog.key === 'puzzle-shelf'
|
||||
) {
|
||||
setPuzzleCreationError(null);
|
||||
setPuzzleOnboardingError(null);
|
||||
setPuzzleShelfError(null);
|
||||
setPuzzleError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'visual-novel') {
|
||||
setVisualNovelError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'baby-object-match') {
|
||||
setBabyObjectMatchError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'bark-battle') {
|
||||
setBarkBattleError(null);
|
||||
return;
|
||||
}
|
||||
if (currentPlatformErrorDialog.key === 'creative-agent') {
|
||||
setCreativeAgentError(null);
|
||||
}
|
||||
}, [
|
||||
autosaveCoordinator,
|
||||
currentPlatformErrorDialog,
|
||||
detailNavigation,
|
||||
platformBootstrap,
|
||||
sessionController,
|
||||
setBigFishError,
|
||||
setMatch3DError,
|
||||
setPuzzleError,
|
||||
setSquareHoleError,
|
||||
setVisualNovelError,
|
||||
]);
|
||||
const closePlatformTaskCompletionDialog = useCallback(() => {
|
||||
if (!currentPlatformTaskCompletionDialog) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dismissKey = buildPlatformTaskCompletionDialogDismissKey(
|
||||
currentPlatformTaskCompletionDialog,
|
||||
);
|
||||
if (dismissKey) {
|
||||
setDismissedPlatformTaskCompletionDialogKey(dismissKey);
|
||||
}
|
||||
setPendingPlatformTaskCompletionDialog(null);
|
||||
}, [currentPlatformTaskCompletionDialog]);
|
||||
const shouldPollPuzzleGenerationSession =
|
||||
selectionStage === 'puzzle-generating' &&
|
||||
activePuzzleGenerationSessionId != null &&
|
||||
@@ -6862,6 +7341,7 @@ export function PlatformEntryFlowShellImpl({
|
||||
setIsProfilePlayStatsOpen(false);
|
||||
setDraftGenerationNotices({});
|
||||
setPendingDraftShelfItems({});
|
||||
setPendingPlatformTaskCompletionDialog(null);
|
||||
resetRpgSessionViewState();
|
||||
setRpgGeneratedCustomWorldProfile(null);
|
||||
setRpgCustomWorldError(null);
|
||||
@@ -14254,19 +14734,6 @@ export function PlatformEntryFlowShellImpl({
|
||||
void refreshBabyObjectMatchShelf();
|
||||
void refreshBarkBattleShelf();
|
||||
}}
|
||||
createError={
|
||||
creationEntryConfigError ??
|
||||
sessionController.creationTypeError ??
|
||||
bigFishError ??
|
||||
match3dError ??
|
||||
(isSquareHoleCreationVisible ? squareHoleError : null) ??
|
||||
woodenFishError ??
|
||||
puzzleCreationError ??
|
||||
puzzleError ??
|
||||
(isVisualNovelCreationOpen ? visualNovelError : null) ??
|
||||
babyObjectMatchError ??
|
||||
barkBattleError
|
||||
}
|
||||
createBusy={
|
||||
!creationEntryConfig ||
|
||||
sessionController.isCreatingAgentSession ||
|
||||
@@ -14454,6 +14921,7 @@ export function PlatformEntryFlowShellImpl({
|
||||
isLoadingPlatform={platformBootstrap.isLoadingPlatform}
|
||||
isLoadingDashboard={platformBootstrap.isLoadingDashboard}
|
||||
hasUnreadDraftUpdate={hasUnreadDraftUpdates}
|
||||
profileTaskRefreshKey={profileTaskRefreshKey}
|
||||
isDesktopLayout={isDesktopLayout}
|
||||
isResumingSaveWorldKey={platformBootstrap.isResumingSaveWorldKey}
|
||||
platformError={
|
||||
@@ -15953,7 +16421,6 @@ export function PlatformEntryFlowShellImpl({
|
||||
settingDescription={null}
|
||||
progressTitle="拼图草稿生成进度"
|
||||
activeBadgeLabel="草稿生成中"
|
||||
pausedBadgeLabel="草稿生成已暂停"
|
||||
idleBadgeLabel="等待返回工作区"
|
||||
hideBatchModule
|
||||
/>
|
||||
@@ -16619,7 +17086,7 @@ export function PlatformEntryFlowShellImpl({
|
||||
</AnimatePresence>
|
||||
|
||||
{creationEntryConfig ? (
|
||||
<PlatformEntryCreationTypeModal
|
||||
<PlatformEntryCreationTypeModal
|
||||
isOpen={showCreationTypeModal}
|
||||
isBusy={
|
||||
sessionController.isCreatingAgentSession ||
|
||||
@@ -16635,20 +17102,6 @@ export function PlatformEntryFlowShellImpl({
|
||||
(isVisualNovelCreationOpen && isVisualNovelStreamingReply) ||
|
||||
isBabyObjectMatchBusy
|
||||
}
|
||||
error={
|
||||
creationEntryConfigError ??
|
||||
bigFishError ??
|
||||
creativeAgentError ??
|
||||
match3dError ??
|
||||
squareHoleError ??
|
||||
jumpHopError ??
|
||||
woodenFishError ??
|
||||
puzzleCreationError ??
|
||||
(isVisualNovelCreationOpen ? visualNovelError : null) ??
|
||||
babyObjectMatchError ??
|
||||
puzzleError ??
|
||||
sessionController.creationTypeError
|
||||
}
|
||||
entryConfig={creationEntryConfig}
|
||||
creationTypes={creationEntryTypes}
|
||||
onClose={() => {
|
||||
@@ -16741,6 +17194,18 @@ export function PlatformEntryFlowShellImpl({
|
||||
payload={publishSharePayload}
|
||||
onClose={() => setPublishSharePayload(null)}
|
||||
/>
|
||||
<PlatformErrorDialog
|
||||
error={activePlatformErrorDialog}
|
||||
onClose={closePlatformErrorDialog}
|
||||
overlayClassName={`platform-theme ${platformThemeClass} !items-center`}
|
||||
panelClassName="platform-remap-surface rounded-[1.5rem]"
|
||||
/>
|
||||
<PlatformTaskCompletionDialog
|
||||
completion={activePlatformTaskCompletionDialog}
|
||||
onClose={closePlatformTaskCompletionDialog}
|
||||
overlayClassName={`platform-theme ${platformThemeClass} !items-center`}
|
||||
panelClassName="platform-remap-surface rounded-[1.5rem]"
|
||||
/>
|
||||
<UnifiedModal
|
||||
open={Boolean(pendingDeleteCreationWork)}
|
||||
title="删除作品"
|
||||
|
||||
107
src/components/platform-entry/PlatformErrorDialog.test.tsx
Normal file
107
src/components/platform-entry/PlatformErrorDialog.test.tsx
Normal file
@@ -0,0 +1,107 @@
|
||||
/* @vitest-environment jsdom */
|
||||
|
||||
import {
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react';
|
||||
import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import * as clipboardService from '../../services/clipboard';
|
||||
import { PlatformErrorDialog } from './PlatformErrorDialog';
|
||||
import { PlatformTaskCompletionDialog } from './PlatformTaskCompletionDialog';
|
||||
|
||||
vi.mock('../../services/clipboard', () => ({
|
||||
copyTextToClipboard: vi.fn(),
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('PlatformErrorDialog', () => {
|
||||
test('shows source, message, and copies the full error report', async () => {
|
||||
vi.mocked(clipboardService.copyTextToClipboard).mockResolvedValue(true);
|
||||
|
||||
render(
|
||||
<PlatformErrorDialog
|
||||
error={{
|
||||
source: '拼图草稿 puzzle-session-123',
|
||||
message: '图片生成失败,请稍后再试。',
|
||||
}}
|
||||
onClose={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
const dialog = screen.getByRole('dialog', { name: '发生错误' });
|
||||
expect(within(dialog).getByText('拼图草稿 puzzle-session-123')).toBeTruthy();
|
||||
expect(within(dialog).getByText('图片生成失败,请稍后再试。')).toBeTruthy();
|
||||
|
||||
fireEvent.click(within(dialog).getByRole('button', { name: '复制报错' }));
|
||||
|
||||
expect(clipboardService.copyTextToClipboard).toHaveBeenCalledWith(
|
||||
['来源:拼图草稿 puzzle-session-123', '错误:图片生成失败,请稍后再试。'].join(
|
||||
'\n',
|
||||
),
|
||||
);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
within(dialog).getByRole('button', { name: '已复制' }),
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
test('does not render when there is no active error', () => {
|
||||
render(<PlatformErrorDialog error={null} onClose={() => {}} />);
|
||||
|
||||
expect(screen.queryByRole('dialog', { name: '发生错误' })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('PlatformTaskCompletionDialog', () => {
|
||||
test('shows source, message, and copies the full completion report', async () => {
|
||||
vi.mocked(clipboardService.copyTextToClipboard).mockResolvedValue(true);
|
||||
|
||||
render(
|
||||
<PlatformTaskCompletionDialog
|
||||
completion={{
|
||||
source: '抓大鹅草稿 match3d-notice-session-1',
|
||||
message: '生成任务已完成,可以继续查看草稿。',
|
||||
}}
|
||||
onClose={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
const dialog = screen.getByRole('dialog', { name: '生成完成' });
|
||||
expect(
|
||||
within(dialog).getByText('抓大鹅草稿 match3d-notice-session-1'),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
within(dialog).getByText('生成任务已完成,可以继续查看草稿。'),
|
||||
).toBeTruthy();
|
||||
|
||||
fireEvent.click(within(dialog).getByRole('button', { name: '复制内容' }));
|
||||
|
||||
expect(clipboardService.copyTextToClipboard).toHaveBeenCalledWith(
|
||||
[
|
||||
'来源:抓大鹅草稿 match3d-notice-session-1',
|
||||
'状态:生成任务已完成,可以继续查看草稿。',
|
||||
].join('\n'),
|
||||
);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
within(dialog).getByRole('button', { name: '已复制' }),
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
test('does not render when there is no active completion', () => {
|
||||
render(
|
||||
<PlatformTaskCompletionDialog completion={null} onClose={() => {}} />,
|
||||
);
|
||||
|
||||
expect(screen.queryByRole('dialog', { name: '生成完成' })).toBeNull();
|
||||
});
|
||||
});
|
||||
120
src/components/platform-entry/PlatformErrorDialog.tsx
Normal file
120
src/components/platform-entry/PlatformErrorDialog.tsx
Normal file
@@ -0,0 +1,120 @@
|
||||
import { Check, Copy } from 'lucide-react';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
import { copyTextToClipboard } from '../../services/clipboard';
|
||||
import { UnifiedModal } from '../common/UnifiedModal';
|
||||
|
||||
export type PlatformErrorDialogPayload = {
|
||||
source: string;
|
||||
message: string;
|
||||
};
|
||||
|
||||
type PlatformErrorDialogProps = {
|
||||
error: PlatformErrorDialogPayload | null;
|
||||
onClose: () => void;
|
||||
overlayClassName?: string;
|
||||
panelClassName?: string;
|
||||
};
|
||||
|
||||
function buildPlatformErrorReport(error: PlatformErrorDialogPayload) {
|
||||
return [`来源:${error.source}`, `错误:${error.message}`].join('\n');
|
||||
}
|
||||
|
||||
export function PlatformErrorDialog({
|
||||
error,
|
||||
onClose,
|
||||
overlayClassName = 'platform-theme platform-theme--light !items-center',
|
||||
panelClassName = 'platform-remap-surface rounded-[1.5rem]',
|
||||
}: PlatformErrorDialogProps) {
|
||||
const [copyState, setCopyState] = useState<'idle' | 'copied' | 'failed'>(
|
||||
'idle',
|
||||
);
|
||||
const resetTimerRef = useRef<number | null>(null);
|
||||
const reportText = useMemo(
|
||||
() => (error ? buildPlatformErrorReport(error) : ''),
|
||||
[error],
|
||||
);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (resetTimerRef.current !== null) {
|
||||
window.clearTimeout(resetTimerRef.current);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setCopyState('idle');
|
||||
}, [error?.source, error?.message]);
|
||||
|
||||
const copyError = () => {
|
||||
if (!reportText) {
|
||||
return;
|
||||
}
|
||||
|
||||
void copyTextToClipboard(reportText).then((copied) => {
|
||||
setCopyState(copied ? 'copied' : 'failed');
|
||||
if (resetTimerRef.current !== null) {
|
||||
window.clearTimeout(resetTimerRef.current);
|
||||
}
|
||||
resetTimerRef.current = window.setTimeout(() => {
|
||||
resetTimerRef.current = null;
|
||||
setCopyState('idle');
|
||||
}, 1400);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<UnifiedModal
|
||||
open={Boolean(error)}
|
||||
title="发生错误"
|
||||
onClose={onClose}
|
||||
size="sm"
|
||||
overlayClassName={overlayClassName}
|
||||
panelClassName={panelClassName}
|
||||
bodyClassName="space-y-3 px-4 py-4 sm:px-5 sm:py-5"
|
||||
footerClassName="justify-end px-4 py-4 sm:px-5"
|
||||
footer={
|
||||
<button
|
||||
type="button"
|
||||
onClick={copyError}
|
||||
disabled={!reportText}
|
||||
className="platform-button platform-button--primary w-full justify-center gap-2 sm:w-auto"
|
||||
>
|
||||
{copyState === 'copied' ? (
|
||||
<Check className="h-4 w-4" />
|
||||
) : (
|
||||
<Copy className="h-4 w-4" />
|
||||
)}
|
||||
{copyState === 'copied'
|
||||
? '已复制'
|
||||
: copyState === 'failed'
|
||||
? '复制失败'
|
||||
: '复制报错'}
|
||||
</button>
|
||||
}
|
||||
>
|
||||
{error ? (
|
||||
<>
|
||||
<div className="rounded-[1rem] border border-[var(--platform-subpanel-border)] bg-white/72 px-3 py-2">
|
||||
<div className="text-xs font-bold text-[var(--platform-text-soft)]">
|
||||
来源
|
||||
</div>
|
||||
<div className="mt-1 break-words text-sm font-semibold leading-5 text-[var(--platform-text-strong)]">
|
||||
{error.source}
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-[1rem] border border-[var(--platform-subpanel-border)] bg-white/72 px-3 py-2">
|
||||
<div className="text-xs font-bold text-[var(--platform-text-soft)]">
|
||||
错误
|
||||
</div>
|
||||
<div className="mt-1 whitespace-pre-wrap break-words text-sm leading-6 text-[var(--platform-text-strong)]">
|
||||
{error.message}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
</UnifiedModal>
|
||||
);
|
||||
}
|
||||
124
src/components/platform-entry/PlatformTaskCompletionDialog.tsx
Normal file
124
src/components/platform-entry/PlatformTaskCompletionDialog.tsx
Normal file
@@ -0,0 +1,124 @@
|
||||
import { CheckCircle2, Copy } from 'lucide-react';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
import { copyTextToClipboard } from '../../services/clipboard';
|
||||
import { UnifiedModal } from '../common/UnifiedModal';
|
||||
|
||||
export type PlatformTaskCompletionDialogPayload = {
|
||||
source: string;
|
||||
message: string;
|
||||
};
|
||||
|
||||
type PlatformTaskCompletionDialogProps = {
|
||||
completion: PlatformTaskCompletionDialogPayload | null;
|
||||
onClose: () => void;
|
||||
overlayClassName?: string;
|
||||
panelClassName?: string;
|
||||
};
|
||||
|
||||
function buildPlatformTaskCompletionReport(
|
||||
completion: PlatformTaskCompletionDialogPayload,
|
||||
) {
|
||||
return [`来源:${completion.source}`, `状态:${completion.message}`].join(
|
||||
'\n',
|
||||
);
|
||||
}
|
||||
|
||||
export function PlatformTaskCompletionDialog({
|
||||
completion,
|
||||
onClose,
|
||||
overlayClassName = 'platform-theme platform-theme--light !items-center',
|
||||
panelClassName = 'platform-remap-surface rounded-[1.5rem]',
|
||||
}: PlatformTaskCompletionDialogProps) {
|
||||
const [copyState, setCopyState] = useState<'idle' | 'copied' | 'failed'>(
|
||||
'idle',
|
||||
);
|
||||
const resetTimerRef = useRef<number | null>(null);
|
||||
const reportText = useMemo(
|
||||
() => (completion ? buildPlatformTaskCompletionReport(completion) : ''),
|
||||
[completion],
|
||||
);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (resetTimerRef.current !== null) {
|
||||
window.clearTimeout(resetTimerRef.current);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setCopyState('idle');
|
||||
}, [completion?.source, completion?.message]);
|
||||
|
||||
const copyCompletion = () => {
|
||||
if (!reportText) {
|
||||
return;
|
||||
}
|
||||
|
||||
void copyTextToClipboard(reportText).then((copied) => {
|
||||
setCopyState(copied ? 'copied' : 'failed');
|
||||
if (resetTimerRef.current !== null) {
|
||||
window.clearTimeout(resetTimerRef.current);
|
||||
}
|
||||
resetTimerRef.current = window.setTimeout(() => {
|
||||
resetTimerRef.current = null;
|
||||
setCopyState('idle');
|
||||
}, 1400);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<UnifiedModal
|
||||
open={Boolean(completion)}
|
||||
title="生成完成"
|
||||
onClose={onClose}
|
||||
size="sm"
|
||||
overlayClassName={overlayClassName}
|
||||
panelClassName={panelClassName}
|
||||
bodyClassName="space-y-3 px-4 py-4 sm:px-5 sm:py-5"
|
||||
footerClassName="justify-end px-4 py-4 sm:px-5"
|
||||
footer={
|
||||
<button
|
||||
type="button"
|
||||
onClick={copyCompletion}
|
||||
disabled={!reportText}
|
||||
className="platform-button platform-button--primary w-full justify-center gap-2 sm:w-auto"
|
||||
>
|
||||
{copyState === 'copied' ? (
|
||||
<CheckCircle2 className="h-4 w-4" />
|
||||
) : (
|
||||
<Copy className="h-4 w-4" />
|
||||
)}
|
||||
{copyState === 'copied'
|
||||
? '已复制'
|
||||
: copyState === 'failed'
|
||||
? '复制失败'
|
||||
: '复制内容'}
|
||||
</button>
|
||||
}
|
||||
>
|
||||
{completion ? (
|
||||
<>
|
||||
<div className="rounded-[1rem] border border-[var(--platform-subpanel-border)] bg-white/72 px-3 py-2">
|
||||
<div className="text-xs font-bold text-[var(--platform-text-soft)]">
|
||||
来源
|
||||
</div>
|
||||
<div className="mt-1 break-words text-sm font-semibold leading-5 text-[var(--platform-text-strong)]">
|
||||
{completion.source}
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-[1rem] border border-[var(--platform-subpanel-border)] bg-white/72 px-3 py-2">
|
||||
<div className="text-xs font-bold text-[var(--platform-text-soft)]">
|
||||
状态
|
||||
</div>
|
||||
<div className="mt-1 whitespace-pre-wrap break-words text-sm leading-6 text-[var(--platform-text-strong)]">
|
||||
{completion.message}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
</UnifiedModal>
|
||||
);
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import {
|
||||
formatPlatformWorldTime,
|
||||
isBarkBattleGalleryEntry,
|
||||
isEdutainmentGalleryEntry,
|
||||
isJumpHopGalleryEntry,
|
||||
type PlatformPublicGalleryCard,
|
||||
resolvePlatformPublicWorkCode,
|
||||
resolvePlatformWorldCoverSlides,
|
||||
@@ -36,7 +35,7 @@ export interface PlatformWorkDetailViewProps {
|
||||
authorAvatarUrl?: string | null;
|
||||
authorDisplayName?: string | null;
|
||||
isBusy: boolean;
|
||||
error: string | null;
|
||||
error?: string | null;
|
||||
visibleCoverCount?: number;
|
||||
onBack: () => void;
|
||||
onLike: () => void;
|
||||
@@ -89,7 +88,6 @@ export function PlatformWorkDetailView({
|
||||
authorAvatarUrl,
|
||||
authorDisplayName,
|
||||
isBusy,
|
||||
error,
|
||||
visibleCoverCount = 1,
|
||||
onBack,
|
||||
onLike,
|
||||
@@ -432,9 +430,6 @@ export function PlatformWorkDetailView({
|
||||
{shareState === 'copied' ? '分享内容已复制' : '分享失败'}
|
||||
</div>
|
||||
) : null}
|
||||
{error ? (
|
||||
<div className="platform-work-detail__error">{error}</div>
|
||||
) : null}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1819,12 +1819,7 @@ export function PuzzleResultView({
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<div className="platform-banner platform-banner--danger mt-3 rounded-2xl text-sm leading-6">
|
||||
{error}
|
||||
</div>
|
||||
) : null}
|
||||
{!error && autoSaveError ? (
|
||||
{autoSaveError ? (
|
||||
<div className="platform-banner platform-banner--danger mt-3 rounded-2xl text-sm leading-6">
|
||||
{autoSaveError}
|
||||
</div>
|
||||
|
||||
@@ -5080,6 +5080,22 @@ test('completed match3d draft notice first opens trial then reopens result', asy
|
||||
resolveCompile({ session: generatedSession });
|
||||
});
|
||||
|
||||
const completionDialog = await screen.findByRole('dialog', {
|
||||
name: '生成完成',
|
||||
});
|
||||
expect(
|
||||
within(completionDialog).getByText(
|
||||
/抓大鹅草稿 match3d-notice-session-1/u,
|
||||
),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
within(completionDialog).getByText(/生成任务已完成/u),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
within(completionDialog).getByRole('button', { name: '复制内容' }),
|
||||
).toBeTruthy();
|
||||
await user.click(within(completionDialog).getByLabelText('关闭'));
|
||||
|
||||
expect(await screen.findByLabelText('新生成完成')).toBeTruthy();
|
||||
await user.click(
|
||||
await screen.findByRole('button', {
|
||||
@@ -7503,6 +7519,48 @@ test('persisted generating puzzle draft keeps session polling on the same sessio
|
||||
expect(getPuzzleAgentSession).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
test('puzzle compile timeout shows failure dialog when reread session is still generating', async () => {
|
||||
const user = userEvent.setup();
|
||||
const runningSession = buildMockPuzzleAgentSession({
|
||||
sessionId: 'puzzle-session-timeout',
|
||||
draft: null,
|
||||
stage: 'collecting_anchors',
|
||||
progressPercent: 88,
|
||||
lastAssistantReply: '正在生成拼图草稿。',
|
||||
});
|
||||
vi.mocked(createPuzzleAgentSession).mockResolvedValueOnce({
|
||||
session: runningSession,
|
||||
});
|
||||
vi.mocked(executePuzzleAgentAction).mockRejectedValueOnce(
|
||||
Object.assign(new Error('请求超时:1800000ms'), {
|
||||
name: 'TimeoutError',
|
||||
}),
|
||||
);
|
||||
vi.mocked(getPuzzleAgentSession).mockResolvedValue({
|
||||
session: runningSession,
|
||||
});
|
||||
|
||||
render(<TestWrapper withAuth />);
|
||||
|
||||
await openCreateTemplateHub(user);
|
||||
await user.click(await findCreationTypeButton('拼图'));
|
||||
await user.click(await screen.findByRole('button', { name: '生成草稿' }));
|
||||
|
||||
const dialog = await screen.findByRole('dialog', { name: '发生错误' });
|
||||
expect(within(dialog).getByText('拼图草稿 puzzle-session-timeout')).toBeTruthy();
|
||||
expect(
|
||||
within(dialog).getByText(
|
||||
'拼图共创操作超时,请确认运行时后端已启动后重试。',
|
||||
),
|
||||
).toBeTruthy();
|
||||
expect(within(dialog).getByRole('button', { name: '复制报错' })).toBeTruthy();
|
||||
expect(
|
||||
await screen.findByRole('progressbar', {
|
||||
name: '拼图草稿生成进度',
|
||||
}),
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
test('published puzzle work card restores its source session for editing', async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
|
||||
@@ -702,14 +702,22 @@ function mockNarrowMobileLayout() {
|
||||
});
|
||||
}
|
||||
|
||||
function renderProfileView(
|
||||
function ProfileHomeViewHarness({
|
||||
onRechargeSuccess = vi.fn(),
|
||||
profileDashboardOverrides: Partial<
|
||||
profileDashboardOverrides = {},
|
||||
userOverrides = {},
|
||||
activeTab = 'profile',
|
||||
profileTaskRefreshKey = 0,
|
||||
}: {
|
||||
onRechargeSuccess?: () => void | Promise<void>;
|
||||
profileDashboardOverrides?: Partial<
|
||||
NonNullable<RpgEntryHomeViewProps['profileDashboard']>
|
||||
> = {},
|
||||
userOverrides: Partial<AuthUser> = {},
|
||||
) {
|
||||
return render(
|
||||
>;
|
||||
userOverrides?: Partial<AuthUser>;
|
||||
activeTab?: RpgEntryHomeViewProps['activeTab'];
|
||||
profileTaskRefreshKey?: number;
|
||||
}) {
|
||||
return (
|
||||
<AuthUiContext.Provider
|
||||
value={{
|
||||
user: {
|
||||
@@ -742,7 +750,7 @@ function renderProfileView(
|
||||
}}
|
||||
>
|
||||
<RpgEntryHomeView
|
||||
activeTab="profile"
|
||||
activeTab={activeTab}
|
||||
onTabChange={vi.fn()}
|
||||
hasSavedGame={false}
|
||||
savedSnapshot={null}
|
||||
@@ -772,8 +780,27 @@ function renderProfileView(
|
||||
onOpenLibraryDetail={vi.fn()}
|
||||
onSearchPublicCode={vi.fn()}
|
||||
onRechargeSuccess={onRechargeSuccess}
|
||||
profileTaskRefreshKey={profileTaskRefreshKey}
|
||||
/>
|
||||
</AuthUiContext.Provider>,
|
||||
</AuthUiContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
function renderProfileView(
|
||||
onRechargeSuccess = vi.fn(),
|
||||
profileDashboardOverrides: Partial<
|
||||
NonNullable<RpgEntryHomeViewProps['profileDashboard']>
|
||||
> = {},
|
||||
userOverrides: Partial<AuthUser> = {},
|
||||
profileTaskRefreshKey = 0,
|
||||
) {
|
||||
return render(
|
||||
<ProfileHomeViewHarness
|
||||
onRechargeSuccess={onRechargeSuccess}
|
||||
profileDashboardOverrides={profileDashboardOverrides}
|
||||
userOverrides={userOverrides}
|
||||
profileTaskRefreshKey={profileTaskRefreshKey}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1826,11 +1853,18 @@ test('non-wechat profile opens reward code from recharge-shaped entry', async ()
|
||||
expect(mockGetRpgProfileRechargeCenter).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('profile daily task shortcut opens task center and claims reward', async () => {
|
||||
test('profile daily task shortcut reflects task progress and claim updates', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onRechargeSuccess = vi.fn();
|
||||
|
||||
renderProfileView(onRechargeSuccess);
|
||||
|
||||
const dailyTask = screen.getByRole('button', { name: /每日任务/u });
|
||||
await waitFor(() => {
|
||||
expect(within(dailyTask).getByText('1 / 1')).toBeTruthy();
|
||||
});
|
||||
expect(within(dailyTask).getByText('领取')).toBeTruthy();
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /每日任务/u }));
|
||||
|
||||
expect(await screen.findByText('每日登录')).toBeTruthy();
|
||||
@@ -1847,6 +1881,7 @@ test('profile daily task shortcut opens task center and claims reward', async ()
|
||||
expect(await screen.findByText('已领取 10 泥点')).toBeTruthy();
|
||||
expect(screen.queryByRole('button', { name: '已领取' })).toBeNull();
|
||||
expect(screen.getByText('暂无任务')).toBeTruthy();
|
||||
expect(within(dailyTask).getByText('已完成')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('profile task center keeps only the highest priority actionable task', async () => {
|
||||
@@ -1909,7 +1944,7 @@ test('profile task center keeps only the highest priority actionable task', asyn
|
||||
expect(screen.queryByText('低优先级已完成')).toBeNull();
|
||||
});
|
||||
|
||||
test('profile total play time card always uses hours', () => {
|
||||
test('profile total play time card always uses hours', async () => {
|
||||
renderProfileView(vi.fn(), {
|
||||
totalPlayTimeMs: 90 * 60 * 1000,
|
||||
});
|
||||
@@ -1920,9 +1955,10 @@ test('profile total play time card always uses hours', () => {
|
||||
|
||||
expect(within(playTimeCard).getByText('1.5小时')).toBeTruthy();
|
||||
expect(within(playTimeCard).queryByText('90分')).toBeNull();
|
||||
await screen.findByText('1 / 1');
|
||||
});
|
||||
|
||||
test('profile played works card shows count unit', () => {
|
||||
test('profile played works card shows count unit', async () => {
|
||||
renderProfileView(vi.fn(), {
|
||||
playedWorldCount: 1,
|
||||
});
|
||||
@@ -1932,9 +1968,10 @@ test('profile played works card shows count unit', () => {
|
||||
});
|
||||
|
||||
expect(within(playedCard).getByText('1个')).toBeTruthy();
|
||||
await screen.findByText('1 / 1');
|
||||
});
|
||||
|
||||
test('profile stats cards are centered without update timestamp', () => {
|
||||
test('profile stats cards are centered without update timestamp', async () => {
|
||||
renderProfileView(vi.fn(), {
|
||||
updatedAt: '2026-05-03T08:01:00Z',
|
||||
});
|
||||
@@ -1950,6 +1987,7 @@ test('profile stats cards are centered without update timestamp', () => {
|
||||
expect(card.className).toContain('text-center');
|
||||
}
|
||||
expect(screen.queryByText(/更新于/u)).toBeNull();
|
||||
await screen.findByText('1 / 1');
|
||||
});
|
||||
|
||||
test('mobile profile page matches the reference layout sections', async () => {
|
||||
@@ -2007,7 +2045,7 @@ test('mobile profile page matches the reference layout sections', async () => {
|
||||
expect(dailyTask.querySelector('.platform-profile-daily-task-card__desc')).toBeTruthy();
|
||||
expect(dailyTask.querySelector('.platform-profile-daily-task-card__progress')).toBeTruthy();
|
||||
expect(dailyTask.textContent).toContain('完成任务可领取 10 泥点');
|
||||
expect(within(dailyTask).getByText('0 / 1')).toBeTruthy();
|
||||
expect(await within(dailyTask).findByText('1 / 1')).toBeTruthy();
|
||||
|
||||
const shortcutRegion = screen.getByRole('region', { name: '常用功能' });
|
||||
expect(
|
||||
@@ -2015,7 +2053,7 @@ test('mobile profile page matches the reference layout sections', async () => {
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
shortcutRegion.querySelectorAll('.platform-profile-shortcut-button'),
|
||||
).toHaveLength(5);
|
||||
).toHaveLength(4);
|
||||
expect(
|
||||
shortcutRegion
|
||||
.querySelector('.platform-profile-shortcut-grid')
|
||||
@@ -2023,7 +2061,6 @@ test('mobile profile page matches the reference layout sections', async () => {
|
||||
).toBe(true);
|
||||
for (const label of [
|
||||
'泥点充值',
|
||||
'邀请好友',
|
||||
'兑换码',
|
||||
'玩家社区',
|
||||
'反馈与建议',
|
||||
@@ -2101,7 +2138,7 @@ test('profile scan action opens camera scanner instead of recharge panel', async
|
||||
expect(mockGetRpgProfileRechargeCenter).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('desktop account entry uses saved avatar image when available', () => {
|
||||
test('desktop account entry uses saved avatar image when available', async () => {
|
||||
mockDesktopLayout();
|
||||
const avatarUrl = 'data:image/png;base64,AAAA';
|
||||
|
||||
@@ -2111,6 +2148,7 @@ test('desktop account entry uses saved avatar image when available', () => {
|
||||
const avatarImage = accountEntry.querySelector('img');
|
||||
expect(avatarImage?.getAttribute('src')).toBe(avatarUrl);
|
||||
expect(within(accountEntry).queryByText('测')).toBeNull();
|
||||
await screen.findByText('1 / 1');
|
||||
});
|
||||
|
||||
test('profile avatar upload uses the shared square crop tool', async () => {
|
||||
@@ -2160,83 +2198,83 @@ test('wallet ledger modal shows empty and error states', async () => {
|
||||
expect(screen.getByText('重新加载')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('profile invite shortcut shows reward subtitle and invited users', async () => {
|
||||
test('profile community shortcut shows reward subtitle and invited users', async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
renderProfileView(vi.fn(), {}, { createdAt: buildFreshProfileCreatedAt() });
|
||||
|
||||
const inviteButton = screen.getByRole('button', { name: /邀请好友/u });
|
||||
expect(within(inviteButton).getByText('双方得 30 泥点')).toBeTruthy();
|
||||
expect(screen.queryByRole('button', { name: /邀请好友/u })).toBeNull();
|
||||
|
||||
const communityButton = screen.getByRole('button', { name: /玩家社区/u });
|
||||
expect(within(communityButton).getByText('交流心得 领取福利')).toBeTruthy();
|
||||
|
||||
await user.click(inviteButton);
|
||||
await user.click(communityButton);
|
||||
|
||||
expect(mockGetRpgProfileReferralInviteCenter).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
await screen.findByText('邀请一个用户注册,双方都可以获得30泥点。'),
|
||||
).toBeTruthy();
|
||||
expect(screen.getByText('每日最多获得十次邀请奖励。')).toBeTruthy();
|
||||
expect(screen.getByText('成功邀请')).toBeTruthy();
|
||||
expect(screen.getByText('被邀请玩家')).toBeTruthy();
|
||||
expect(screen.queryByText('已奖')).toBeNull();
|
||||
expect(screen.queryByText('今日')).toBeNull();
|
||||
expect(screen.getByAltText('玩家社区微信群二维码')).toBeTruthy();
|
||||
expect(screen.getByAltText('玩家社区 QQ 群二维码')).toBeTruthy();
|
||||
expect(screen.getByText('微信群')).toBeTruthy();
|
||||
expect(screen.getByText('QQ群')).toBeTruthy();
|
||||
expect(screen.queryByText('成功邀请')).toBeNull();
|
||||
expect(screen.queryByText('被邀请玩家')).toBeNull();
|
||||
});
|
||||
|
||||
test('profile redeem invite shortcut sits between invite and community for fresh accounts', async () => {
|
||||
test('profile page hides legacy redeem invite secondary shortcut for fresh accounts', async () => {
|
||||
renderProfileView(
|
||||
vi.fn(),
|
||||
{},
|
||||
{ createdAt: buildFreshProfileCreatedAt() },
|
||||
);
|
||||
|
||||
const inviteButton = screen.getByRole('button', { name: /邀请好友/u });
|
||||
const redeemButton = await screen.findByRole('button', {
|
||||
name: /填邀请码/u,
|
||||
});
|
||||
const communityButton = screen.getByRole('button', { name: /玩家社区/u });
|
||||
const secondaryShortcuts = screen.getByRole('region', {
|
||||
name: '次级入口',
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockGetRpgProfileReferralInviteCenter).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
expect(inviteButton).toBeTruthy();
|
||||
expect(screen.queryByRole('button', { name: /邀请好友/u })).toBeNull();
|
||||
expect(communityButton).toBeTruthy();
|
||||
expect(
|
||||
within(secondaryShortcuts).getByRole('button', { name: /填邀请码/u }),
|
||||
).toBeTruthy();
|
||||
expect(within(redeemButton).getByText('新用户奖励')).toBeTruthy();
|
||||
expect(screen.queryByRole('region', { name: '次级入口' })).toBeNull();
|
||||
expect(screen.queryByRole('button', { name: /填邀请码/u })).toBeNull();
|
||||
});
|
||||
|
||||
test('profile redeem invite shortcut hides after redeemed or one day old', async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
mockGetRpgProfileReferralInviteCenter.mockResolvedValueOnce(
|
||||
mockBuildReferralCenter({
|
||||
invitedUsers: [],
|
||||
hasRedeemedCode: true,
|
||||
boundInviterUserId: 'user-2',
|
||||
boundAt: '2026-05-01T08:00:00Z',
|
||||
}),
|
||||
);
|
||||
const { unmount } = renderProfileView();
|
||||
await user.click(screen.getByRole('button', { name: /邀请好友/u }));
|
||||
await screen.findByText('成功邀请');
|
||||
const firstShortcutRegion = screen.getByRole('region', { name: '常用功能' });
|
||||
expect(
|
||||
within(firstShortcutRegion).queryByRole('button', { name: /邀请好友/u }),
|
||||
).toBeNull();
|
||||
expect(
|
||||
within(firstShortcutRegion).queryByRole('button', { name: /填邀请码/u }),
|
||||
).toBeNull();
|
||||
await waitFor(() => {
|
||||
expect(mockGetRpgProfileTasks).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
await act(async () => {
|
||||
await Promise.resolve();
|
||||
});
|
||||
unmount();
|
||||
|
||||
renderProfileView(vi.fn(), {}, { createdAt: '2026-04-01T00:00:00.000Z' });
|
||||
const expiredShortcutRegion = screen.getByRole('region', {
|
||||
name: '常用功能',
|
||||
});
|
||||
expect(
|
||||
within(expiredShortcutRegion).queryByRole('button', {
|
||||
name: /邀请好友/u,
|
||||
}),
|
||||
).toBeNull();
|
||||
expect(
|
||||
within(expiredShortcutRegion).queryByRole('button', {
|
||||
name: /填邀请码/u,
|
||||
}),
|
||||
).toBeNull();
|
||||
await waitFor(() => {
|
||||
expect(mockGetRpgProfileTasks).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
await act(async () => {
|
||||
await Promise.resolve();
|
||||
});
|
||||
});
|
||||
|
||||
test('invite query opens login modal for logged out users', async () => {
|
||||
@@ -2269,9 +2307,10 @@ test('profile redeem invite modal reads query invite code after login', async ()
|
||||
expect((input as HTMLInputElement).value).toBe('SPRING2026');
|
||||
});
|
||||
|
||||
test('profile redeem invite modal submits code and hides shortcut after success', async () => {
|
||||
test('profile redeem invite query modal submits code after login', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onRechargeSuccess = vi.fn();
|
||||
window.history.replaceState(null, '', '/?inviteCode=spring-2026');
|
||||
|
||||
renderProfileView(
|
||||
onRechargeSuccess,
|
||||
@@ -2279,9 +2318,7 @@ test('profile redeem invite modal submits code and hides shortcut after success'
|
||||
{ createdAt: buildFreshProfileCreatedAt() },
|
||||
);
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: /填邀请码/u }));
|
||||
const input = await screen.findByLabelText('邀请码');
|
||||
await user.type(input, 'spring-2026');
|
||||
expect(await screen.findByLabelText('邀请码')).toBeTruthy();
|
||||
await user.click(screen.getByRole('button', { name: '提交' }));
|
||||
|
||||
await waitFor(() => {
|
||||
@@ -2291,12 +2328,23 @@ test('profile redeem invite modal submits code and hides shortcut after success'
|
||||
});
|
||||
expect(onRechargeSuccess).toHaveBeenCalledTimes(1);
|
||||
expect(await screen.findByText('已填写')).toBeTruthy();
|
||||
const shortcutRegion = screen.getByRole('region', { name: '常用功能' });
|
||||
expect(
|
||||
within(shortcutRegion).queryByRole('button', {
|
||||
name: /填邀请码/u,
|
||||
}),
|
||||
).toBeNull();
|
||||
expect(screen.queryByRole('region', { name: '次级入口' })).toBeNull();
|
||||
});
|
||||
|
||||
test('profile task center reloads when refresh key changes', async () => {
|
||||
const { rerender } = renderProfileView();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockGetRpgProfileTasks).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
rerender(
|
||||
<ProfileHomeViewHarness profileTaskRefreshKey={1} />,
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockGetRpgProfileTasks).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
test('opens reward code modal from profile action on mobile', async () => {
|
||||
@@ -2326,8 +2374,8 @@ test('profile page shows legal entries and hides archive shortcuts', async () =>
|
||||
?.classList.contains('platform-profile-shortcut-grid'),
|
||||
).toBe(true);
|
||||
expect(
|
||||
within(shortcutRegion).getByRole('button', { name: /邀请好友/u }),
|
||||
).toBeTruthy();
|
||||
within(shortcutRegion).queryByRole('button', { name: /邀请好友/u }),
|
||||
).toBeNull();
|
||||
expect(
|
||||
within(shortcutRegion).getByRole('button', { name: /玩家社区/u }),
|
||||
).toBeTruthy();
|
||||
|
||||
@@ -29,7 +29,6 @@ import {
|
||||
Star,
|
||||
ThumbsUp,
|
||||
Ticket,
|
||||
UserPlus,
|
||||
UserRound,
|
||||
XCircle,
|
||||
} from 'lucide-react';
|
||||
@@ -50,7 +49,6 @@ import profileClockImage from '../../../media/profile/_Image (1).png';
|
||||
import profileGamepadImage from '../../../media/profile/_Image (2).png';
|
||||
import profileStillLifeImage from '../../../media/profile/_Image (3).png';
|
||||
import profileCoinsImage from '../../../media/profile/_Image (4).png';
|
||||
import profileInviteImage from '../../../media/profile/_Image (5).png';
|
||||
import profileGiftImage from '../../../media/profile/_Image (6).png';
|
||||
import profileCommunityImage from '../../../media/profile/_Image (7).png';
|
||||
import profileFeedbackImage from '../../../media/profile/_Image (8).png';
|
||||
@@ -217,6 +215,7 @@ export interface RpgEntryHomeViewProps {
|
||||
onOpenPlayedWork?: (work: ProfilePlayedWorkSummary) => void;
|
||||
onOpenFeedback?: () => void;
|
||||
onRechargeSuccess?: () => void | Promise<void>;
|
||||
profileTaskRefreshKey?: number;
|
||||
createTabContent?: ReactNode;
|
||||
draftTabContent?: ReactNode;
|
||||
hasUnreadDraftUpdate?: boolean;
|
||||
@@ -256,18 +255,25 @@ const RECOMMEND_ENTRY_DRAG_LIMIT_PX = 160;
|
||||
const WECHAT_JS_SDK_URL = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js';
|
||||
const WECHAT_PAY_CONFIRM_RETRY_DELAYS_MS = [800, 1600, 3000] as const;
|
||||
const WECHAT_NATIVE_PAY_QR_IMAGE_SIZE = 180;
|
||||
const PROFILE_TASK_STATUS_PRIORITY_RANK: Record<ProfileTaskItem['status'], number> = {
|
||||
const PROFILE_TASK_STATUS_PRIORITY_RANK: Record<
|
||||
ProfileTaskItem['status'],
|
||||
number
|
||||
> = {
|
||||
claimable: 2,
|
||||
incomplete: 1,
|
||||
disabled: 0,
|
||||
claimed: -1,
|
||||
};
|
||||
const PROFILE_TASK_CARD_FALLBACK_REWARD_POINTS = 10;
|
||||
const PROFILE_QR_SCAN_INTERVAL_MS = 360;
|
||||
|
||||
function selectProfileTaskCenterTasks(tasks: ProfileTaskItem[]) {
|
||||
return tasks
|
||||
.map((task, index) => ({ task, index }))
|
||||
.filter(({ task }) => task.status === 'claimable' || task.status === 'incomplete')
|
||||
.filter(
|
||||
({ task }) =>
|
||||
task.status === 'claimable' || task.status === 'incomplete',
|
||||
)
|
||||
.sort(
|
||||
(left, right) =>
|
||||
PROFILE_TASK_STATUS_PRIORITY_RANK[right.task.status] -
|
||||
@@ -278,6 +284,37 @@ function selectProfileTaskCenterTasks(tasks: ProfileTaskItem[]) {
|
||||
.map(({ task }) => task);
|
||||
}
|
||||
|
||||
function selectProfileTaskCardTask(tasks: ProfileTaskItem[]) {
|
||||
return (
|
||||
selectProfileTaskCenterTasks(tasks)[0] ??
|
||||
tasks.find((task) => task.status === 'claimed') ??
|
||||
tasks.find((task) => task.status !== 'disabled') ??
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
function buildProfileTaskCardSummary(center: ProfileTaskCenterResponse | null) {
|
||||
const task = selectProfileTaskCardTask(center?.tasks ?? []);
|
||||
const threshold = Math.max(1, task?.threshold ?? 1);
|
||||
const progressCount = Math.min(task?.progressCount ?? 0, threshold);
|
||||
const rewardPoints =
|
||||
task?.rewardPoints ?? PROFILE_TASK_CARD_FALLBACK_REWARD_POINTS;
|
||||
const actionLabel =
|
||||
task?.status === 'claimable'
|
||||
? '领取'
|
||||
: task?.status === 'claimed'
|
||||
? '已完成'
|
||||
: '去完成';
|
||||
|
||||
return {
|
||||
actionLabel,
|
||||
progressCount,
|
||||
progressPercent: Math.round((progressCount / threshold) * 100),
|
||||
rewardPoints,
|
||||
threshold,
|
||||
};
|
||||
}
|
||||
|
||||
type ProfileReferralPanel = 'invite' | 'redeem' | 'community';
|
||||
type ProfilePopupPanel = ProfileReferralPanel | 'saveArchives';
|
||||
type BarcodeDetectorLike = {
|
||||
@@ -2450,42 +2487,6 @@ function ProfileSettingsRow({
|
||||
);
|
||||
}
|
||||
|
||||
function ProfileSecondaryShortcutButton({
|
||||
label,
|
||||
subLabel,
|
||||
icon,
|
||||
onClick,
|
||||
}: {
|
||||
label: string;
|
||||
subLabel?: string;
|
||||
icon: ComponentType<{ className?: string }>;
|
||||
onClick: () => void;
|
||||
}) {
|
||||
const Icon = icon;
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
className="platform-profile-secondary-shortcut inline-flex items-center gap-2 rounded-full px-3 py-2 text-left"
|
||||
>
|
||||
<span className="platform-profile-secondary-shortcut__icon">
|
||||
<Icon className="h-4 w-4" />
|
||||
</span>
|
||||
<span className="min-w-0">
|
||||
<span className="block truncate text-[13px] font-semibold text-[var(--platform-text-strong)]">
|
||||
{label}
|
||||
</span>
|
||||
{subLabel ? (
|
||||
<span className="mt-0.5 block truncate text-[11px] font-medium text-[var(--platform-text-soft)]">
|
||||
{subLabel}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function ProfileLegalSection({
|
||||
onOpenDocument,
|
||||
}: {
|
||||
@@ -3982,6 +3983,7 @@ export function RpgEntryHomeView({
|
||||
onOpenPlayedWork,
|
||||
onOpenFeedback,
|
||||
onRechargeSuccess,
|
||||
profileTaskRefreshKey = 0,
|
||||
createTabContent,
|
||||
draftTabContent,
|
||||
hasUnreadDraftUpdate = false,
|
||||
@@ -4023,6 +4025,7 @@ export function RpgEntryHomeView({
|
||||
useState<ProfileTaskCenterResponse | null>(null);
|
||||
const [taskCenterError, setTaskCenterError] = useState<string | null>(null);
|
||||
const [isLoadingTaskCenter, setIsLoadingTaskCenter] = useState(false);
|
||||
const taskCenterRequestIdRef = useRef(0);
|
||||
const [claimingTaskId, setClaimingTaskId] = useState<string | null>(null);
|
||||
const [taskClaimSuccess, setTaskClaimSuccess] = useState<string | null>(null);
|
||||
const [isQrScannerOpen, setIsQrScannerOpen] = useState(false);
|
||||
@@ -4042,6 +4045,7 @@ export function RpgEntryHomeView({
|
||||
: readProfileInviteCodeFromLocationSearch(window.location.search),
|
||||
[],
|
||||
);
|
||||
const promptedLoginForInviteQueryRef = useRef(false);
|
||||
const autoOpenedInviteQueryRef = useRef(false);
|
||||
const [referralRedeemCode, setReferralRedeemCode] = useState(
|
||||
pendingProfileInviteCode,
|
||||
@@ -4220,12 +4224,10 @@ export function RpgEntryHomeView({
|
||||
profileDashboard?.totalPlayTimeMs ?? 0,
|
||||
);
|
||||
const playedWorkCount = profileDashboard?.playedWorldCount ?? 0;
|
||||
const canShowReferralRedeemShortcut =
|
||||
isAuthenticated &&
|
||||
isWithinProfileInviteRedeemWindow(authUi?.user?.createdAt) &&
|
||||
isReferralCenterInitialized &&
|
||||
Boolean(referralCenter) &&
|
||||
referralCenter?.hasRedeemedCode !== true;
|
||||
const profileTaskCardSummary = useMemo(
|
||||
() => buildProfileTaskCardSummary(taskCenter),
|
||||
[taskCenter],
|
||||
);
|
||||
const tabIcons: Record<
|
||||
PlatformHomeTab,
|
||||
ComponentType<{ className?: string }>
|
||||
@@ -4392,12 +4394,15 @@ export function RpgEntryHomeView({
|
||||
return;
|
||||
}
|
||||
|
||||
autoOpenedInviteQueryRef.current = true;
|
||||
if (!authUi?.user) {
|
||||
authUi?.openLoginModal();
|
||||
if (!promptedLoginForInviteQueryRef.current) {
|
||||
promptedLoginForInviteQueryRef.current = true;
|
||||
authUi?.openLoginModal();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
autoOpenedInviteQueryRef.current = true;
|
||||
setReferralRedeemCode(pendingProfileInviteCode);
|
||||
setReferralError(null);
|
||||
setReferralSuccess(null);
|
||||
@@ -4795,23 +4800,49 @@ export function RpgEntryHomeView({
|
||||
document.removeEventListener('visibilitychange', handleResume);
|
||||
};
|
||||
}, [handleWechatPayResult]);
|
||||
const loadTaskCenter = () => {
|
||||
const loadTaskCenter = useCallback(() => {
|
||||
const requestId = ++taskCenterRequestIdRef.current;
|
||||
setTaskCenterError(null);
|
||||
setIsLoadingTaskCenter(true);
|
||||
void getRpgProfileTasks()
|
||||
.then(setTaskCenter)
|
||||
.then((center) => {
|
||||
if (requestId === taskCenterRequestIdRef.current) {
|
||||
setTaskCenter(center);
|
||||
}
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
if (requestId !== taskCenterRequestIdRef.current) {
|
||||
return;
|
||||
}
|
||||
setTaskCenter(null);
|
||||
setTaskCenterError(
|
||||
error instanceof Error ? error.message : '读取每日任务失败',
|
||||
);
|
||||
})
|
||||
.finally(() => setIsLoadingTaskCenter(false));
|
||||
};
|
||||
.finally(() => {
|
||||
if (requestId === taskCenterRequestIdRef.current) {
|
||||
setIsLoadingTaskCenter(false);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (activeTab !== 'profile' || !isAuthenticated) {
|
||||
taskCenterRequestIdRef.current += 1;
|
||||
setTaskCenter(null);
|
||||
setTaskCenterError(null);
|
||||
return;
|
||||
}
|
||||
|
||||
loadTaskCenter();
|
||||
}, [activeTab, isAuthenticated, loadTaskCenter, profileTaskRefreshKey]);
|
||||
|
||||
const openTaskCenterPanel = () => {
|
||||
setIsTaskCenterOpen(true);
|
||||
setTaskClaimSuccess(null);
|
||||
loadTaskCenter();
|
||||
if (!taskCenter) {
|
||||
loadTaskCenter();
|
||||
}
|
||||
};
|
||||
const openQrScannerPanel = () => {
|
||||
if (!authUi?.user) {
|
||||
@@ -6215,14 +6246,24 @@ export function RpgEntryHomeView({
|
||||
每日任务
|
||||
</span>
|
||||
<span className="platform-profile-daily-task-card__desc mt-4 block text-[13px] font-medium text-[var(--platform-text-base)]">
|
||||
完成任务可领取 <span className="text-[#c45b2a]">10</span> 泥点
|
||||
完成任务可领取{' '}
|
||||
<span className="text-[#c45b2a]">
|
||||
{profileTaskCardSummary.rewardPoints}
|
||||
</span>{' '}
|
||||
泥点
|
||||
</span>
|
||||
<span className="platform-profile-daily-task-card__progress mt-4 flex items-center gap-3">
|
||||
<span className="platform-profile-daily-task-card__progress-value text-[14px] font-semibold text-[#dc3f0e]">
|
||||
0 / 1
|
||||
{profileTaskCardSummary.progressCount} /{' '}
|
||||
{profileTaskCardSummary.threshold}
|
||||
</span>
|
||||
<span className="platform-profile-daily-task-card__track">
|
||||
<span className="platform-profile-daily-task-card__bar" />
|
||||
<span
|
||||
className="platform-profile-daily-task-card__bar"
|
||||
style={{
|
||||
width: `${profileTaskCardSummary.progressPercent}%`,
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
@@ -6232,7 +6273,7 @@ export function RpgEntryHomeView({
|
||||
className="platform-profile-daily-task-card__mascot"
|
||||
/>
|
||||
<span className="platform-profile-daily-task-card__action">
|
||||
去完成
|
||||
{profileTaskCardSummary.actionLabel}
|
||||
</span>
|
||||
</button>
|
||||
|
||||
@@ -6248,13 +6289,6 @@ export function RpgEntryHomeView({
|
||||
imageSrc={profileCoinsImage}
|
||||
onClick={openRechargeOrRewardCodeModal}
|
||||
/>
|
||||
<ProfileShortcutButton
|
||||
label="邀请好友"
|
||||
subLabel="双方得 30 泥点"
|
||||
icon={UserPlus}
|
||||
imageSrc={profileInviteImage}
|
||||
onClick={() => openProfilePopupPanel('invite')}
|
||||
/>
|
||||
<ProfileShortcutButton
|
||||
label="兑换码"
|
||||
subLabel="领取福利"
|
||||
@@ -6297,20 +6331,6 @@ export function RpgEntryHomeView({
|
||||
/>
|
||||
</section>
|
||||
|
||||
{canShowReferralRedeemShortcut ? (
|
||||
<section
|
||||
className="platform-profile-secondary-shortcuts"
|
||||
aria-label="次级入口"
|
||||
>
|
||||
<ProfileSecondaryShortcutButton
|
||||
label="填邀请码"
|
||||
subLabel="新用户奖励"
|
||||
icon={Ticket}
|
||||
onClick={() => openProfilePopupPanel('redeem')}
|
||||
/>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
<ProfileLegalSection onOpenDocument={setActiveLegalDocumentId} />
|
||||
</>
|
||||
) : (
|
||||
|
||||
@@ -9,6 +9,9 @@ import type { CustomWorldProfile } from '../../types';
|
||||
|
||||
export function resolveRpgEntryErrorMessage(error: unknown, fallback: string) {
|
||||
if (isTimeoutError(error)) {
|
||||
if (/拼图/u.test(fallback) && /操作|执行|编译|生成草稿/u.test(fallback)) {
|
||||
return '拼图共创操作超时,请确认运行时后端已启动后重试。';
|
||||
}
|
||||
if (/智能创作/u.test(fallback)) {
|
||||
return '开启智能创作工作区超时,请确认运行时后端已启动后重试。';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user