feat: switch agent fetching to the server side

this brings the benefit of fitting in the revalidator lifecycle we have
created via the useLiveData hook.
This commit is contained in:
Aarnav Tale
2025-03-24 11:39:02 -04:00
parent 9a1051b9af
commit 73ea35980d
7 changed files with 30 additions and 75 deletions
-24
View File
@@ -1,24 +0,0 @@
import { useEffect, useMemo, useRef } from 'react';
import { useFetcher } from 'react-router';
import { HostInfo } from '~/types';
export default function useAgent(nodeIds: string[]) {
const fetcher = useFetcher<Record<string, HostInfo>>();
const qp = useMemo(
() => new URLSearchParams({ node_ids: nodeIds.join(',') }),
[nodeIds],
);
const idRef = useRef<string[]>([]);
useEffect(() => {
if (idRef.current.join(',') !== nodeIds.join(',')) {
fetcher.load(`/api/agent?${qp.toString()}`);
idRef.current = nodeIds;
}
}, [qp.toString()]);
return {
data: fetcher.data,
isLoading: fetcher.state === 'loading',
};
}