Skip to content

Commit

Permalink
[Goals] Don't let back button get stuck on loading screen (#2971)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Mar 28, 2024
1 parent e9b7d72 commit 65f3ba5
Showing 1 changed file with 16 additions and 5 deletions.
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

0 comments on commit 65f3ba5

Please sign in to comment.