feat: add workbench shared utils, hooks, and display components
Phase 1-5: Created utils/workbench.js (STAGE_STATS_CONFIG eliminates 40+ repeated StatCards), useTaskStream hook (WebSocket event handling), useTaskRunner hook (task start logic), StageStatsPanel, TaskControlPanel, TaskProgressBar, TaskInfoPanel, TaskFileList, and TaskLogStream. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// frontend/src/hooks/useTaskRunner.js
|
||||
import { useState, useCallback } from 'react';
|
||||
import { runTask } from '../api/tasks';
|
||||
|
||||
export default function useTaskRunner({ hydrateTask }) {
|
||||
const [isStarting, setIsStarting] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState('');
|
||||
|
||||
const handleStart = useCallback(async (canStart) => {
|
||||
if (!canStart) {
|
||||
window.alert('请先在设置中配置目录!');
|
||||
return;
|
||||
}
|
||||
setIsStarting(true);
|
||||
setErrorMessage('');
|
||||
try {
|
||||
const response = await runTask();
|
||||
await hydrateTask(response.task_id, true);
|
||||
} catch (error) {
|
||||
if (error.status === 409 && error.taskId) {
|
||||
await hydrateTask(error.taskId, true);
|
||||
} else {
|
||||
setErrorMessage(error.message || '启动失败');
|
||||
}
|
||||
} finally {
|
||||
setIsStarting(false);
|
||||
}
|
||||
}, [hydrateTask]);
|
||||
|
||||
return { isStarting, errorMessage, setErrorMessage, handleStart };
|
||||
}
|
||||
Reference in New Issue
Block a user