mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-20 22:50:11 -04:00
* New test: Add location - Add script to download some test files to allows tests to have a stable path for creating locations - Improve onboarding test - Add custom Cypress commands for fastOnboarding and deleteLibrary - Add some documentation related to tests to CONTRIBUTING.md - Update some deps * Download small test-data for Cypress CI * Replace globstar with find to make it compatible with bash 3.x * Fix react too many re-renders - add-location test should now pass successfully * Make job model task text match less flaky * Check if we were redirected to onboarding after Library was deleted - Check if sidebar entry was created after adding a location - Put route regex's into a separate file - Make onboarding test ensure that no Library exists before running * Enable test retries - Log cypress default config during test run * Run tests under webkit - Pass CI envvar to tests to ensure correct cypress config * Attempt fix CI config again * Remove single use checkUrlIsLibrary function
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { useEffect } from 'react';
|
|
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)
|
|
);
|
|
|
|
useEffect(() => {
|
|
if (hasIndexerJob) {
|
|
navigate(`/${libraryId}/location/${newLocation}`);
|
|
explorerStore.newLocationToRedirect = null;
|
|
}
|
|
}, [hasIndexerJob, libraryId, newLocation, navigate]);
|
|
};
|