拆分 UI 编辑器路径复制按钮
Project CI / AI game creator shell Rust shard 1/4 (pull_request) Failing after 2m27s
Project CI / AI game creator shell Rust shard 2/4 (pull_request) Failing after 2m23s
Project CI / AI game creator shell Rust shard 3/4 (pull_request) Failing after 2m5s
Project CI / AI game creator shell Rust shard 4/4 (pull_request) Failing after 2m8s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 1m57s
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 2m15s
Project CI / Frontend tests (pull_request) Failing after 3m22s
Project CI / Repository checks (pull_request) Successful in 3m38s
Project CI / Native shell tests (pull_request) Successful in 6m42s
Project CI / AI game creator shell web tests (pull_request) Failing after 3m12s
Project CI / Backend tests (pull_request) Successful in 8m24s

将剪贴板状态与写入逻辑提取为独立小组件

保持保存结果弹窗只负责结果布局与动作编排
This commit is contained in:
2026-09-14 18:58:57 +08:00
parent 184d88dbb8
commit 8a0d5600b3
2 changed files with 45 additions and 33 deletions
@@ -0,0 +1,43 @@
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
import { Copy } from 'lucide-react';
import { useEffect, useState } from 'react';
export function UiEditorCopyPathButton({
relativePath,
}: {
relativePath: string;
}) {
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 (
<>
{copyState === 'failed' ? (
<p className="mt-2 text-xs text-red-600" role="alert">
</p>
) : null}
<button
type="button"
className="inline-flex items-center gap-1.5 rounded-lg border border-(--platform-subpanel-border) px-3 py-2 text-xs"
onClick={() => void copyPath()}
>
<Copy size={14} aria-hidden="true" />
{copyState === 'copied' ? '已复制' : '复制路径'}
</button>
</>
);
}
@@ -1,8 +1,5 @@
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
import { Copy } from 'lucide-react';
import { useEffect, useState } from 'react';
import { ThemedModal } from '../../../components/modal/ThemedModal';
import { UiEditorCopyPathButton } from './UiEditorCopyPathButton';
export type UiEditorSaveResultNotice =
| {
@@ -51,22 +48,6 @@ function GeneratedNotice({
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 (
<>
<h2 className="m-0 text-base font-semibold"></h2>
@@ -74,20 +55,8 @@ function GeneratedNotice({
<code className="mt-2 block select-text break-all rounded-lg bg-black/5 px-3 py-2 text-xs leading-5">
{relativePath}
</code>
{copyState === 'failed' ? (
<p className="mt-2 text-xs text-red-600" role="alert">
</p>
) : null}
<div className="mt-5 flex flex-wrap justify-end gap-2">
<button
type="button"
className="inline-flex items-center gap-1.5 rounded-lg border border-(--platform-subpanel-border) px-3 py-2 text-xs"
onClick={() => void copyPath()}
>
<Copy size={14} aria-hidden="true" />
{copyState === 'copied' ? '已复制' : '复制路径'}
</button>
<UiEditorCopyPathButton relativePath={relativePath} />
<button
type="button"
className="rounded-lg bg-orange-600 px-3 py-2 text-xs font-semibold text-white"