diff --git a/apps/ai-game-creator-shell/src/view/ui-editor/components/UiEditorSaveResultModal.tsx b/apps/ai-game-creator-shell/src/view/ui-editor/components/UiEditorSaveResultModal.tsx new file mode 100644 index 000000000..8d5bc45c5 --- /dev/null +++ b/apps/ai-game-creator-shell/src/view/ui-editor/components/UiEditorSaveResultModal.tsx @@ -0,0 +1,169 @@ +import { writeText } from '@tauri-apps/plugin-clipboard-manager'; +import { Copy } from 'lucide-react'; +import { useEffect, useState } from 'react'; + +import { ThemedModal } from '../../../components/modal/ThemedModal'; + +export type UiEditorSaveResultNotice = + | { + kind: 'saved'; + } + | { + kind: 'generated'; + relativePath: string; + } + | { + kind: 'failure'; + message: string; + retryLabel?: string; + onRetry?: () => void; + }; + +export function UiEditorSaveResultModal({ + notice, + onClose, +}: { + notice: UiEditorSaveResultNotice | null; + onClose: () => void; +}) { + return ( + + {notice?.kind === 'generated' ? ( + + ) : notice?.kind === 'saved' ? ( + + ) : notice?.kind === 'failure' ? ( + + ) : null} + + ); +} + +function GeneratedNotice({ + relativePath, + onClose, +}: { + relativePath: string; + onClose: () => void; +}) { + const [copyState, setCopyState] = useState<'idle' | 'copied' | 'failed'>( + 'idle', + ); + + useEffect(() => setCopyState('idle'), [relativePath]); + + async function copyPath() { + setCopyState('idle'); + try { + await writeText(relativePath); + setCopyState('copied'); + } catch { + setCopyState('failed'); + } + } + + return ( + <> +

代码已生成

+

生成文件路径

+ + {relativePath} + + {copyState === 'failed' ? ( +

+ 复制失败,请手动复制路径。 +

+ ) : null} +
+ + +
+ + ); +} + +function SimpleNotice({ + title, + onClose, +}: { + title: string; + onClose: () => void; +}) { + return ( + <> +

{title}

+
+ +
+ + ); +} + +function FailureNotice({ + notice, + onClose, +}: { + notice: Extract; + onClose: () => void; +}) { + return ( + <> +

操作失败

+

+ {notice.message} +

+
+ + {notice.onRetry ? ( + + ) : null} +
+ + ); +} + +function ariaLabelForNotice(notice: UiEditorSaveResultNotice | null) { + if (notice?.kind === 'generated') return '代码已生成'; + if (notice?.kind === 'saved') return '保存成功'; + if (notice?.kind === 'failure') return '操作失败'; + return '保存结果'; +}