Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

import { Fragment, useReducer, type FormEvent } from 'react';
import { Link } from 'react-router-dom';
import { Link, useNavigate } from 'react-router-dom';

import { useAppDispatch } from 'src/store';
import { useAppDispatch, useAppSelector } from 'src/store';

import * as urlFor from 'src/shared/helpers/urlHelper';

Expand Down Expand Up @@ -140,6 +140,8 @@ const SelectedGenomesTable = (props: {
const { allSelectedGenomes, filteredGenomes } = props;
const [tableState, tableDispatch] = useReducer(reducer, initialState);
const reduxDispatch = useAppDispatch();
const navigate = useNavigate();
const previousApp = useAppSelector((state) => state.global.previousApp);

const isInDeletionMode = Boolean(tableState.deletionModeSettings);
const genomeIdsForDeletion = new Set<string>(
Expand Down Expand Up @@ -224,6 +226,13 @@ const SelectedGenomesTable = (props: {
reduxDispatch(deleteSpeciesAndSave(genomeId));
}
exitDeletionMode();
if (filteredGenomes.length === genomeIdsForDeletion.length) {
if (previousApp) {
navigate(`/${previousApp}`);
} else {
navigate(urlFor.speciesSelector());
}
}
};

const toggleGenomeUse = (genome: CommittedItem) => {
Expand Down
3 changes: 3 additions & 0 deletions src/global/globalSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ export const getScrollPosition = (state: RootState): ScrollPosition =>

export const getCurrentApp = (state: RootState): string =>
state.global.currentApp;

export const getPreviousApp = (state: RootState): string =>
state.global.previousApp;
8 changes: 7 additions & 1 deletion src/global/globalSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ export type GlobalState = Readonly<{
breakpointWidth: BreakpointWidth;
scrollPosition: ScrollPosition;
currentApp: string;
previousApp: string;
}>;

export const defaultState: GlobalState = {
browserTabId: null,
breakpointWidth: BreakpointWidth.DESKTOP,
scrollPosition: {},
currentApp: ''
currentApp: '',
previousApp: ''
};

export const updateBreakpointWidth: ActionCreator<
Expand Down Expand Up @@ -83,6 +85,10 @@ const globalSlice = createSlice({
state.scrollPosition = { ...state.scrollPosition, ...action.payload };
},
changeCurrentApp(state, action: PayloadAction<string>) {
if (!action.payload || action.payload === state.currentApp) {
return;
}
state.previousApp = state.currentApp;
state.currentApp = action.payload;
}
},
Expand Down