Files
spacedrive/interface/hooks/useIsLocationIndexing.ts
Oscar Beaumont 95f48ea575 [ENG-1367] TypeError: null is not an object (#1698)
strickter types pog
2023-10-30 00:43:18 +00:00

29 lines
751 B
TypeScript

import { useLibraryQuery } from '@sd/client';
/*
This is a hook to check if a location is indexing and completed_task_count is 0.
We use this to display a loading indicator in the location page.
*/
export const useIsLocationIndexing = (locationId: number): boolean => {
const { data: jobGroups } = useLibraryQuery(['jobs.reports'], {
enabled: locationId != null,
refetchOnWindowFocus: false
});
const isLocationIndexing =
jobGroups?.some((group) =>
group.jobs.some((job) => {
if (
job.name === 'indexer' &&
job.metadata?.location.id === locationId &&
(job.status === 'Running' || job.status === 'Queued')
) {
return job.completed_task_count === 0;
}
})
) || false;
return isLocationIndexing;
};