mirror of
https://github.com/AlexsJones/llmfit.git
synced 2026-09-03 16:35:24 +00:00
* 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>
47 lines
1.1 KiB
JavaScript
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
|
|
]);
|
|
}
|