-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptRunner.tsx
More file actions
43 lines (39 loc) · 1.46 KB
/
Copy pathScriptRunner.tsx
File metadata and controls
43 lines (39 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { useState } from 'react';
import { useScriptStore, Script } from '../../store/scriptStore';
import './ScriptRunner.css';
export function ScriptRunner() {
const { scripts, addScript, removeScript, executeScript } = useScriptStore();
const [results, setResults] = useState<Map<string, string>>(new Map());
const handleRun = async (name: string) => {
try {
const result = await executeScript(name);
setResults((prev) => new Map(prev).set(name, result));
} catch (e) {
setResults((prev) => new Map(prev).set(name, `Error: ${e}`));
}
};
return (
<div className="script-runner">
<div className="script-list">
{scripts.map((script: Script) => (
<div key={script.name} className="script-item">
<div className="script-info">
<span className="script-name">{script.name}</span>
<span className="script-path">{script.path}</span>
</div>
<div className="script-actions">
<button onClick={() => handleRun(script.name)}>运行</button>
<button onClick={() => removeScript(script.name)}>删除</button>
</div>
{results.get(script.name) && (
<div className="script-result">{results.get(script.name)}</div>
)}
</div>
))}
</div>
<button onClick={() => addScript({ name: 'New Script', path: '', args: [] })}>
添加脚本
</button>
</div>
);
}