diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 5d6c10b61..170779258 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -14,6 +14,7 @@ import { RobotProvider } from 'components/Contexts/RobotContext' import { config } from 'config' import { MissionDefinitionsProvider } from 'components/Contexts/MissionDefinitionsContext' import { MediaStreamProvider } from 'components/Contexts/MediaStreamContext' +import { DockProvider } from 'components/Contexts/DockContext' const appInsights = new ApplicationInsights({ config: { @@ -35,22 +36,24 @@ const App = () => ( - - - -
- -
-
- - - - - - - -
-
+ + + + +
+ +
+
+ + + + + + + +
+
+
diff --git a/frontend/src/components/Contexts/DockContext.tsx b/frontend/src/components/Contexts/DockContext.tsx new file mode 100644 index 000000000..424054c67 --- /dev/null +++ b/frontend/src/components/Contexts/DockContext.tsx @@ -0,0 +1,76 @@ +import { createContext, FC, useEffect, useState } from 'react' +import { useRobotContext } from './RobotContext' +import { AlertType } from './AlertContext' +import { DockAlertContent, DockAlertListContent } from 'components/Alerts/DockAlert' +import { AlertCategory } from 'components/Alerts/AlertsBanner' +import { RobotFlotillaStatus } from 'models/Robot' +import { useAlertContext } from './AlertContext' + +interface IDockContext { + DockStatus: boolean +} + +interface Props { + children: React.ReactNode +} + +const defaultDockInterface = { + DockStatus: false, +} + +const DockContext = createContext(defaultDockInterface) + +export const DockProvider: FC = ({ children }) => { + const [DockStatus, setDockStatus] = useState(defaultDockInterface.DockStatus) + const { enabledRobots } = useRobotContext() + const { setAlert, clearAlert, setListAlert, clearListAlert } = useAlertContext() + + useEffect(() => { + const missionQueueFozenStatus = enabledRobots.filter( + (robot) => robot.flotillaStatus === RobotFlotillaStatus.Docked + ) + + if (missionQueueFozenStatus.length > 0 && DockStatus === false) { + setDockStatus((oldStatus) => !oldStatus) + clearListAlert(AlertType.DismissDock) + clearAlert(AlertType.DismissDock) + setListAlert( + AlertType.RequestDock, + , + AlertCategory.WARNING + ) + setAlert( + AlertType.RequestDock, + , + AlertCategory.WARNING + ) + } else if (missionQueueFozenStatus.length === 0 && DockStatus === true) { + setDockStatus((oldStatus) => !oldStatus) + clearListAlert(AlertType.RequestDock) + clearListAlert(AlertType.DockSuccess) + clearAlert(AlertType.RequestDock) + clearAlert(AlertType.DockSuccess) + setListAlert( + AlertType.DismissDock, + , + AlertCategory.INFO + ) + setAlert( + AlertType.DismissDock, + , + AlertCategory.INFO + ) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [enabledRobots]) + + return ( + + {children} + + ) +}