2023-10-23 12:22:07 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
2023-10-24 07:51:58 +00:00
|
|
|
const isLocationIndexing =
|
|
|
|
jobGroups?.some((group) =>
|
|
|
|
group.jobs.some((job) => {
|
2023-10-30 00:43:18 +00:00
|
|
|
if (
|
|
|
|
job.name === 'indexer' &&
|
2023-12-05 13:16:03 +00:00
|
|
|
(job.metadata as any)?.location.id === locationId &&
|
2023-10-30 00:43:18 +00:00
|
|
|
(job.status === 'Running' || job.status === 'Queued')
|
|
|
|
) {
|
2023-10-24 07:51:58 +00:00
|
|
|
return job.completed_task_count === 0;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
) || false;
|
2023-10-23 12:22:07 +00:00
|
|
|
|
|
|
|
return isLocationIndexing;
|
2023-10-24 07:51:58 +00:00
|
|
|
};
|