spacedrive/interface/hooks/useIsLocationIndexing.ts
Ericson "Fogo" Soares bdc242a852
[ENG-1775] Scan location using new jobs (#2476)
* First draft on task system usage, still missing job system

* Scan location roughly working, a ton of stuff to fix yet

* Updating some deps due to crashes and bugs

* Exposing non critical errors to frontend

* Getting active job reports from job system

* Using boxed opaque type to avoid a downcast issue with generics

* Task system issues discovered on race conditions

* Enable debug

* Fix job report in the job manager

* Fix race condition on steal tasks

* Fixed race condition on task suspend

* Some fixes on job progress reporting and save

* Fixed many race conditions and a hard deadlock
Also some progress report polishing

* Ignore .ts and .mts video files for now

* Some better logs

* bruh

* Internal deadlocks and excess of communication in the task system
- Also better logs

* Bunch of fixes and optimizations

* WIP at fixing file identifier

* Fixed file identifier job
- still need to work on its progress report frontend

* A bunch of polishing

* Fixed some bugs and did more polishing

* Cleanup

* Bridging old and new job systems

* A ton of fixes

* A bunch of bugs related to shutdown and resume

* Indexer and watcher bugs

* Log normalizing

* Fixing CI

* Change error! to warn! on non critical errors log

* Fix redirect to new location

* Type annotation

* Bogus merge resolution on cargo lock
2024-06-17 21:30:57 +00:00

36 lines
979 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) => {
let jobLocationId: number | undefined;
for (const metadata of job.metadata) {
if (metadata.type === 'input' && metadata.metadata.type === 'location') {
jobLocationId = metadata.metadata.data.id;
break;
}
}
if (
job.name === 'Indexer' &&
jobLocationId === locationId &&
(job.status === 'Running' || job.status === 'Queued')
) {
return job.completed_task_count === 0;
}
})
) || false;
return isLocationIndexing;
};