spacedrive/interface/hooks/useIsLocationIndexing.ts
Lynx 0688406adc
[ENG-293] Tag assign mode (#2462)
* Rename top bar icon *style* to *classlist*

* Update pnpm-lock.yaml

* Add user-facing name for tag assign mode: "Assign tags"

* Refactor path bar to allow tag bar display above

* Oops, use original PATH_BAR_HEIGHT

* rename ExplorerPath to more consistent ExplorerPathBar

* remove debug tag assign mode toggle

* fix straggling old reference to ExplorerPathBar

* rename useShortcuts to useExplorerShortcuts

* add `DEV` to turbo.json env deps

* tag assign mode list display + keyboard toggle

* Update pnpm-lock.yaml after merge

* Use new query style in ExplorerTagBar

* WIP debugging list bug

* Fix to the `<slot />` bug

* Remove awaiting tag assign keypress state variable

* Add tag assign mode localization lines

* Add actual tag assign mode functionality

* Use localization for bulk tag assignment

* i18n: Add proper "file" plurals and nest within tag assignment msgs

* implement tag hotkey assignment

* Use i18n for unknown error in tag assignment

* use type for tag bulk assign keycodes

* remove custom ordering todo

* add awaiting-assign visual state to tag bar tags

* Make Escape cancel tag bar hotkey assignment + add a11y + remove focus state on keypress

* Remove tag assign mutation success from tag bar

* Remove tab index `-1` from tag bar tag

* Update tag bar awaiting hotkey assignment colors

* Fix tag bar styling + sort properly

* Fix some missed `TOP_BAR_ICON_CLASSLIST` references

* improve tag ui & fix location redir

* fix pathbar caret and layout adjustment experiment

* Add better tag bar layout for users with lots of tags

* set padding if tags overflow

---------

Co-authored-by: Arnab Chakraborty <11457760+Rocky43007@users.noreply.github.com>
Co-authored-by: ameer2468 <33054370+ameer2468@users.noreply.github.com>
2024-06-18 10:52:19 +00:00

37 lines
997 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;
}
return false;
})
) || false;
return isLocationIndexing;
};