mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-19 22:19:49 -04:00
* Replace `useExplorerStore` with `useSelector` * Remove `getExplorerStore() * Devtools names for all major anonymous components * referential equality * Undo mobile changes * remove debug log * Properly memoise `RenameTextBox` args * goodbye log * Fix a couple of bugs Thanks @ameer2468 for pointing out!
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { useNavigate } from 'react-router';
|
|
import { useLibraryQuery, useSelector } from '@sd/client';
|
|
import { explorerStore } from '~/app/$libraryId/Explorer/store';
|
|
|
|
import { LibraryIdParamsSchema } from '../app/route-schemas';
|
|
import { useZodRouteParams } from './useZodRouteParams';
|
|
|
|
/**
|
|
* When a user adds a location and checks the should redirect box,
|
|
* this hook will redirect them to the location
|
|
* once the indexer has been invoked
|
|
*/
|
|
|
|
export const useRedirectToNewLocation = () => {
|
|
const navigate = useNavigate();
|
|
const { libraryId } = useZodRouteParams(LibraryIdParamsSchema);
|
|
const newLocation = useSelector(explorerStore, (s) => s.newLocationToRedirect);
|
|
const { data: jobGroups } = useLibraryQuery(['jobs.reports'], {
|
|
enabled: newLocation != null,
|
|
refetchOnWindowFocus: false
|
|
});
|
|
|
|
const hasIndexerJob = jobGroups
|
|
?.flatMap((j) => j.jobs)
|
|
.some(
|
|
(j) =>
|
|
j.name === 'indexer' &&
|
|
(j.metadata as any)?.location.id === newLocation &&
|
|
(j.completed_task_count > 0 || j.completed_at != null)
|
|
);
|
|
|
|
if (hasIndexerJob) {
|
|
navigate(`/${libraryId}/location/${newLocation}`);
|
|
explorerStore.newLocationToRedirect = null;
|
|
}
|
|
};
|