Skip to content

Commit

Permalink
Fix for app crush and console warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasmadei authored and blcham committed May 18, 2024
1 parent 155a79d commit 09517db
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/contexts/AppBarContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const AppBarProvider = ({ children }: AppBarTitleProviderProps) => {
.catch((reason) => showSnackbar(reason, errorMessage));
};

if (loggedUser) fetchSystems();
if (loggedUser.authenticated) fetchSystems();

return () => axiosSource.cancel("SystemsProvider - unmounting");
}, []);
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useFailureModesTables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as failureModesTableService from "@services/failureModesTableService";
import { SnackbarType, useSnackbar } from "./useSnackbar";
import { filter, findIndex } from "lodash";
import { FailureModesTable, UpdateFailureModesTable } from "@models/failureModesTableModel";
import { useLoggedUser } from "./useLoggedUser";

type failureModesTableContextType = [
FailureModesTable[],
Expand All @@ -25,6 +26,7 @@ export const useFailureModesTables = () => {
export const FailureModesTablesProvider = ({ children }: ChildrenProps) => {
const [_tables, _setTables] = useState<FailureModesTable[]>([]);
const [showSnackbar] = useSnackbar();
const [loggedUser] = useLoggedUser();

useEffect(() => {
const fetchTables = async () => {
Expand All @@ -34,7 +36,7 @@ export const FailureModesTablesProvider = ({ children }: ChildrenProps) => {
.catch((reason) => showSnackbar(reason, SnackbarType.ERROR));
};

fetchTables();
if (loggedUser.authenticated) fetchTables();
return () => axiosSource.cancel("FailureModesTablesProvider - unmounting");
}, []);

Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useFaultTrees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { axiosSource } from "@services/utils/axiosUtils";
import { ChildrenProps } from "@utils/hookUtils";
import { SnackbarType, useSnackbar } from "@hooks/useSnackbar";
import { filter, findIndex } from "lodash";
import { useLoggedUser } from "./useLoggedUser";

type faultTreeContextType = [
FaultTree[],
Expand All @@ -25,6 +26,7 @@ export const useFaultTrees = () => {
export const FaultTreesProvider = ({ children }: ChildrenProps) => {
const [_faultTrees, _setFaultTrees] = useState<FaultTree[]>([]);
const [showSnackbar] = useSnackbar();
const [loggedUser] = useLoggedUser();

useEffect(() => {
const fetchFaultTrees = async () => {
Expand All @@ -34,7 +36,7 @@ export const FaultTreesProvider = ({ children }: ChildrenProps) => {
.catch((reason) => showSnackbar(reason, SnackbarType.ERROR));
};

fetchFaultTrees();
if (loggedUser.authenticated) fetchFaultTrees();

return () => axiosSource.cancel("FaultTreesProvider - unmounting");
}, []);
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useSystems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { axiosSource } from "@services/utils/axiosUtils";
import { ChildrenProps } from "@utils/hookUtils";
import { SnackbarType, useSnackbar } from "@hooks/useSnackbar";
import { filter, findIndex } from "lodash";
import { useLoggedUser } from "./useLoggedUser";

type systemContextType = [
System[],
Expand All @@ -25,6 +26,7 @@ export const useSystems = () => {
export const SystemsProvider = ({ children }: ChildrenProps) => {
const [_systems, _setSystems] = useState<System[]>([]);
const [showSnackbar] = useSnackbar();
const [loggedUser] = useLoggedUser();

useEffect(() => {
const fetchSystems = async () => {
Expand All @@ -34,7 +36,7 @@ export const SystemsProvider = ({ children }: ChildrenProps) => {
.catch((reason) => showSnackbar(reason, SnackbarType.ERROR));
};

fetchSystems();
if (loggedUser.authenticated) fetchSystems();

return () => axiosSource.cancel("SystemsProvider - unmounting");
}, []);
Expand Down

0 comments on commit 09517db

Please sign in to comment.