From 59bd85170b48d1343620fda2bf81a7bed515d262 Mon Sep 17 00:00:00 2001 From: Sergey Nechaev Date: Tue, 14 Feb 2023 18:49:34 +0100 Subject: [PATCH] Use Connecting component for loading and connecting state --- legacy/src/app/Marine2/App.tsx | 4 +- legacy/src/app/Marine2/Marine2.tsx | 79 ++++++++++-------------------- 2 files changed, 28 insertions(+), 55 deletions(-) diff --git a/legacy/src/app/Marine2/App.tsx b/legacy/src/app/Marine2/App.tsx index ac9fe53f0..2531a953b 100644 --- a/legacy/src/app/Marine2/App.tsx +++ b/legacy/src/app/Marine2/App.tsx @@ -8,6 +8,7 @@ import { useVisibleWidgetsStore } from "./modules" // import { ErrorModal } from "./components/ErrorModal" import { Marine2 } from "./Marine2" +import Connecting from "./components/ui/Connecting" export type AppProps = { host: string @@ -65,8 +66,7 @@ const App = observer((props: AppProps) => { }, [themeStore.darkMode]) return ( - // todo: replace with Loader component - Loading}> + }> {/**/} diff --git a/legacy/src/app/Marine2/Marine2.tsx b/legacy/src/app/Marine2/Marine2.tsx index 4ca4c90a8..c65c2df48 100644 --- a/legacy/src/app/Marine2/Marine2.tsx +++ b/legacy/src/app/Marine2/Marine2.tsx @@ -1,5 +1,4 @@ import React, { useEffect, useState } from "react" -// import classnames from "classnames" // import { useState } from "react" // import Fade, { viewChangeDelay } from "../components/Fade" @@ -7,7 +6,6 @@ import React, { useEffect, useState } from "react" // import { Connecting, Error, MqttUnavailable, RemoteConsole } from "./components/Views" import { useLanguage, useMqtt, STATUS } from "@elninotech/mfd-modules" -// import { VIEWS } from "../utils/constants" import { AppProps } from "./App" import { mfdLanguageOptions } from "app/locales/constants" @@ -18,6 +16,7 @@ import { AppViews, useAppViewsStore } from "./modules/AppViews" import BoxView from "./components/views/BoxView" import RootView from "./components/views/RootView" import RemoteConsoleView from "./components/views/RemoteConsoleView" +import Connecting from "./components/ui/Connecting" // type MainProps = { // isConnected?: boolean @@ -46,8 +45,6 @@ export const Marine2 = observer((props: AppProps) => { // subscribe to language useLanguage(mfdLanguageOptions) // const [viewUnmounting, setViewUnmounting] = useState(false) - // const [currentPage, setCurrentPage] = useState(0) - // const [pages, setTotalPages] = useState(1) const mqtt = useMqtt() const isConnected = mqtt.isConnected const portalId = mqtt.portalId @@ -76,31 +73,6 @@ export const Marine2 = observer((props: AppProps) => { } } - // const setPage = (currentPage: number) => { - // setCurrentPage(currentPage) - // } - // - // const setPages = (pages: number) => { - // setTotalPages(pages) - // setCurrentPage(0) - // } - - // const setView = (view: string) => { - // if (currentView !== view) { - // setViewUnmounting(true) - // setTimeout(() => { - // setCurrentView(view) - // setViewUnmounting(false) - // }, viewChangeDelay) - // } - // } - - // const toggleRemoteConsole = () => { - // if (currentView !== VIEWS.REMOTE_CONSOLE) { - // setView(VIEWS.REMOTE_CONSOLE) - // } else setView(VIEWS.METRICS) - // } - if (error && isError(error) && status !== STATUS.CONNECTING) { return ( // @@ -110,32 +82,33 @@ export const Marine2 = observer((props: AppProps) => { ) } - if (error) { - return ( -
Error
- // <> - // - // {(() => { - // switch (currentView) { - // case VIEWS.REMOTE_CONSOLE: - // return ( - //
- // - // setView(VIEWS.METRICS)} /> - // - //
- // ) - // default: - // return - // } - // })()} - // - ) - } + // todo: this is a special state for mqqt connection error, but it also happens + // when the mqtt server is just connecting. We need to handle this better + // if (error) { + // return ( + //
Error
+ // <> + // + // {(() => { + // switch (currentView) { + // case VIEWS.REMOTE_CONSOLE: + // return ( + //
+ // + // setView(VIEWS.METRICS)} /> + // + //
+ // ) + // default: + // return + // } + // })()} + // + // ) + // } if (!isConnected || !portalId) { - return
Connecting
- // return + return } return renderView()