spacedrive/interface/hooks/useIsLocationIndexing.ts
Oscar Beaumont 89a7f735e5
[ENG-1400] Normalised caching (#1734)
* prototype

* `.normalise` helper + only `String` keys

* implement it for 'search.paths'

* redux devtools

* fix

* refactor backend

* wip: upgrade to rspc fork

* mega cursed

* Upgrade Specta-related stuff

* Upgrade Typescript

* Cache debug page

* bruh

* Fix optimistic library setting

* Cache clearing

* better timeout

* Fix tags page

* bit of cleanup

---------

Co-authored-by: Brendan Allan <brendonovich@outlook.com>
2023-12-05 13:16:03 +00:00

29 lines
760 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 as any)?.location.id === locationId &&
(job.status === 'Running' || job.status === 'Queued')
) {
return job.completed_task_count === 0;
}
})
) || false;
return isLocationIndexing;
};