From 09517db879935b953e1c9a02aa607ea868e8cbee Mon Sep 17 00:00:00 2001 From: Kiryl Koniukh <49252228+Kasmadei@users.noreply.github.com> Date: Sat, 18 May 2024 17:22:28 +0200 Subject: [PATCH] Fix for app crush and console warnings --- src/contexts/AppBarContext.tsx | 2 +- src/hooks/useFailureModesTables.tsx | 4 +++- src/hooks/useFaultTrees.tsx | 4 +++- src/hooks/useSystems.tsx | 4 +++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/contexts/AppBarContext.tsx b/src/contexts/AppBarContext.tsx index 8ceeda6a..b75e3d63 100644 --- a/src/contexts/AppBarContext.tsx +++ b/src/contexts/AppBarContext.tsx @@ -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"); }, []); diff --git a/src/hooks/useFailureModesTables.tsx b/src/hooks/useFailureModesTables.tsx index 24bbce17..eebe2265 100644 --- a/src/hooks/useFailureModesTables.tsx +++ b/src/hooks/useFailureModesTables.tsx @@ -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[], @@ -25,6 +26,7 @@ export const useFailureModesTables = () => { export const FailureModesTablesProvider = ({ children }: ChildrenProps) => { const [_tables, _setTables] = useState([]); const [showSnackbar] = useSnackbar(); + const [loggedUser] = useLoggedUser(); useEffect(() => { const fetchTables = async () => { @@ -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"); }, []); diff --git a/src/hooks/useFaultTrees.tsx b/src/hooks/useFaultTrees.tsx index ab5ce6b9..30684cb9 100644 --- a/src/hooks/useFaultTrees.tsx +++ b/src/hooks/useFaultTrees.tsx @@ -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[], @@ -25,6 +26,7 @@ export const useFaultTrees = () => { export const FaultTreesProvider = ({ children }: ChildrenProps) => { const [_faultTrees, _setFaultTrees] = useState([]); const [showSnackbar] = useSnackbar(); + const [loggedUser] = useLoggedUser(); useEffect(() => { const fetchFaultTrees = async () => { @@ -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"); }, []); diff --git a/src/hooks/useSystems.tsx b/src/hooks/useSystems.tsx index 7dfc70b4..b3ebe26d 100644 --- a/src/hooks/useSystems.tsx +++ b/src/hooks/useSystems.tsx @@ -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[], @@ -25,6 +26,7 @@ export const useSystems = () => { export const SystemsProvider = ({ children }: ChildrenProps) => { const [_systems, _setSystems] = useState([]); const [showSnackbar] = useSnackbar(); + const [loggedUser] = useLoggedUser(); useEffect(() => { const fetchSystems = async () => { @@ -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"); }, []);