@@ -2,32 +2,30 @@ import { Button, HStack, Portal, Text } from "@chakra-ui/react";
22import { useMemo , useRef } from "react" ;
33import { MdBolt } from "react-icons/md" ;
44import { FormattedMessage } from "react-intl" ;
5- import {
6- ConnectionStatus ,
7- useConnectionStage ,
8- } from "../connection-stage-hooks" ;
5+ import { useConnectionStage } from "../connection-stage-hooks" ;
96import InfoToolTip from "./InfoToolTip" ;
107import LiveGraph from "./LiveGraph" ;
8+ import { ConnectionStatus , useConnectStatus } from "../connect-status-hooks" ;
119
1210const LiveGraphPanel = ( ) => {
1311 const { actions } = useConnectionStage ( ) ;
14- const { stage } = useConnectionStage ( ) ;
12+ const status = useConnectStatus ( ) ;
1513 const parentPortalRef = useRef ( null ) ;
1614
17- const connectBtnConfig = useMemo (
18- ( ) =>
19- stage . status === ConnectionStatus . None ||
20- stage . status === ConnectionStatus . Connecting
21- ? {
22- textId : "footer.connectButton" ,
23- onClick : actions . start ,
24- }
25- : {
26- textId : "actions.reconnect" ,
27- onClick : actions . reconnect ,
28- } ,
29- [ actions . reconnect , actions . start , stage ]
30- ) ;
15+ const connectBtnConfig = useMemo ( ( ) => {
16+ return status === ConnectionStatus . NotConnected ||
17+ status === ConnectionStatus . Connecting ||
18+ status === ConnectionStatus . FailedToConnect ||
19+ status === ConnectionStatus . FailedToReconnectTwice
20+ ? {
21+ textId : "footer.connectButton" ,
22+ onClick : actions . start ,
23+ }
24+ : {
25+ textId : " actions.reconnect" ,
26+ onClick : actions . reconnect ,
27+ } ;
28+ } , [ actions . reconnect , actions . start , status ] ) ;
3129
3230 return (
3331 < HStack
@@ -49,7 +47,7 @@ const LiveGraphPanel = () => {
4947 >
5048 < HStack gap = { 4 } >
5149 < LiveIndicator />
52- { stage . status === ConnectionStatus . Connected ? (
50+ { status === ConnectionStatus . Connected ? (
5351 < Button variant = "primary" size = "sm" onClick = { actions . disconnect } >
5452 < FormattedMessage id = "footer.disconnectButton" />
5553 </ Button >
@@ -58,15 +56,15 @@ const LiveGraphPanel = () => {
5856 variant = "primary"
5957 size = "sm"
6058 isDisabled = {
61- stage . status === ConnectionStatus . Reconnecting ||
62- stage . status === ConnectionStatus . Connecting
59+ status === ConnectionStatus . Reconnecting ||
60+ status === ConnectionStatus . Connecting
6361 }
6462 onClick = { connectBtnConfig . onClick }
6563 >
6664 < FormattedMessage id = { connectBtnConfig . textId } />
6765 </ Button >
6866 ) }
69- { stage . status === ConnectionStatus . Reconnecting && (
67+ { status === ConnectionStatus . Reconnecting && (
7068 < Text rounded = "4xl" bg = "white" py = "1px" fontWeight = "bold" >
7169 < FormattedMessage id = "connectMB.reconnecting" />
7270 </ Text >
0 commit comments