Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't let back button get stuck on loading screen #2971

Merged
merged 5 commits into from
Mar 28, 2024
Merged
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
21 changes: 16 additions & 5 deletions src/goals/DefaultGoal/BaseGoalScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import loadable from "@loadable/component";
import { ReactElement, useEffect } from "react";
import { type ReactElement, useEffect } from "react";
import { useNavigate } from "react-router-dom";

import PageNotFound from "components/PageNotFound/component";
import DisplayProgress from "goals/DefaultGoal/DisplayProgress";
import Loading from "goals/DefaultGoal/Loading";
import { clearTree } from "goals/MergeDuplicates/Redux/MergeDupsActions";
import { setCurrentGoal } from "goals/Redux/GoalActions";
import { resetReviewEntries } from "goals/ReviewEntries/Redux/ReviewEntriesActions";
import { StoreState } from "types";
import { type StoreState } from "types";
import { Goal, GoalStatus, GoalType } from "types/goals";
import { useAppDispatch, useAppSelector } from "types/hooks";
import { Path } from "types/path";

const CharacterInventory = loadable(() => import("goals/CharacterInventory"));
const MergeDup = loadable(() => import("goals/MergeDuplicates"));
Expand All @@ -35,10 +37,19 @@ function displayComponent(goal: Goal): ReactElement {
}

export default function LoadingGoalScreen(): ReactElement {
const goalStatus = useAppSelector(
(state: StoreState) => state.goalsState.currentGoal.status
const { goalType, status } = useAppSelector(
(state: StoreState) => state.goalsState.currentGoal
);
return goalStatus === GoalStatus.Loading ? <Loading /> : <BaseGoalScreen />;
const navigate = useNavigate();

useEffect(() => {
// Prevent getting stuck on loading screen when user clicks the back button.
if (goalType === GoalType.Default) {
navigate(Path.Goals);
}
}, [goalType, navigate]);

return status === GoalStatus.Loading ? <Loading /> : <BaseGoalScreen />;
}

/**
Expand Down
Loading