This commit is contained in:
@@ -20,6 +20,19 @@ export function InventoryPage() {
|
||||
const [loadingContext, setLoadingContext] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const loadContext = async (id: string) => {
|
||||
setSelectedId(id);
|
||||
setLoadingContext(true);
|
||||
try {
|
||||
const item = await fetchNodeContext(id);
|
||||
setContext(item);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Errore sconosciuto');
|
||||
} finally {
|
||||
setLoadingContext(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
setLoadingTree(true);
|
||||
@@ -28,7 +41,7 @@ export function InventoryPage() {
|
||||
if (!active) return;
|
||||
setNodes(items);
|
||||
const first = findFirstNode(items);
|
||||
setSelectedId(first);
|
||||
if (first) loadContext(first);
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
if (!active) return;
|
||||
@@ -42,25 +55,6 @@ export function InventoryPage() {
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedId) return;
|
||||
let active = true;
|
||||
setLoadingContext(true);
|
||||
fetchNodeContext(selectedId)
|
||||
.then((item) => {
|
||||
if (active) setContext(item);
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
if (active) setError(err.message);
|
||||
})
|
||||
.finally(() => {
|
||||
if (active) setLoadingContext(false);
|
||||
});
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [selectedId]);
|
||||
|
||||
if (loadingTree) {
|
||||
return <div className="inventory-empty">Caricamento inventory...</div>;
|
||||
}
|
||||
@@ -71,8 +65,8 @@ export function InventoryPage() {
|
||||
|
||||
return (
|
||||
<div className="inventory-layout">
|
||||
<InventoryTree nodes={nodes} selectedId={selectedId} onSelect={setSelectedId} />
|
||||
<NodeContextPanel context={context} loading={loadingContext} />
|
||||
<InventoryTree nodes={nodes} selectedId={selectedId} onSelect={loadContext} />
|
||||
<NodeContextPanel context={context} loading={loadingContext} onNavigateNode={loadContext} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user