llmfit/llmfit-web/src/hooks/useSystem.js
LeeFJ0606 3cc2b67dee
Add zh-CN localization plus web planning and hardware simulation (#486)
* feat(ui): add built-in zh-CN localization for web and desktop

* feat(web): add hardware simulation and planning UI

---------

Co-authored-by: 李小白 <lixiaobai@lixiaobaideMacBook-Pro.local>
2026-04-22 10:17:59 +01:00

47 lines
1.1 KiB
JavaScript

import { useEffect } from 'react';
import { fetchSystemInfo } from '../api';
import { useModelContext } from '../contexts/ModelContext';
export function useSystem() {
const {
setSystemInfo,
setSystemLoading,
setSystemError,
refreshTick,
appliedSimulation
} = useModelContext();
useEffect(() => {
const controller = new AbortController();
async function loadSystem() {
setSystemLoading(true);
setSystemError('');
try {
const payload = await fetchSystemInfo(appliedSimulation, controller.signal);
setSystemInfo(payload);
setSystemLoading(false);
} catch (error) {
if (controller.signal.aborted) {
return;
}
setSystemLoading(false);
setSystemError(
error instanceof Error
? error.message
: 'Unable to load system details.'
);
setSystemInfo(null);
}
}
loadSystem();
return () => controller.abort();
}, [
refreshTick,
appliedSimulation,
setSystemInfo,
setSystemLoading,
setSystemError
]);
}