@@ -6,43 +6,45 @@ import {ChargePoint as OCPPChargePoint} from "../cp/ChargePoint.ts";
6
6
import { useAtom } from 'jotai'
7
7
import { configAtom } from "../store/store.ts" ;
8
8
import { BootNotification , DefaultBootNotification } from "../cp/OcppTypes.ts" ;
9
-
9
+ import { useNavigate } from "react-router-dom" ;
10
10
11
11
const TopPage : React . FC = ( ) => {
12
12
const [ cps , setCps ] = useState < OCPPChargePoint [ ] > ( [ ] ) ;
13
- const [ connectorNumber , setConnectorNumber ] = useState < number > ( 2 ) ;
14
13
const [ config ] = useAtom ( configAtom ) ;
15
14
const [ tagIDs , setTagIDs ] = useState < string [ ] > ( [ ] ) ;
15
+ const navigate = useNavigate ( ) ;
16
16
17
17
useEffect ( ( ) => {
18
- console . log ( `Connector Number: ${ config ?. connectorNumber } WSURL: ${ config ?. wsURL } CPID: ${ config ?. ChargePointID } TagID: ${ config ?. tagID } ` ) ;
19
- if ( config ?. Experimental === null ) {
20
- setConnectorNumber ( config ?. connectorNumber || 2 ) ;
21
- setCps ( [
22
- NewChargePoint ( connectorNumber , config . ChargePointID , config . BootNotification ?? DefaultBootNotification , config . wsURL , config . basicAuthSettings , config . autoMeterValueSetting )
23
- ] ) ;
24
- } else {
25
- const cps = config ?. Experimental ?. ChargePointIDs . map ( ( cp ) =>
26
- NewChargePoint ( cp . ConnectorNumber , cp . ChargePointID , config . BootNotification ?? DefaultBootNotification , config . wsURL , config . basicAuthSettings , config . autoMeterValueSetting )
18
+ if ( ! config ) {
19
+ navigate ( '/settings' ) ;
20
+ return ;
21
+ }
22
+ console . log ( `Connector Number: ${ config . connectorNumber } WSURL: ${ config . wsURL } CPID: ${ config . ChargePointID } TagID: ${ config . tagID } ` ) ;
23
+ if ( config . Experimental ) {
24
+ const cps = config . Experimental . ChargePointIDs . map ( ( cp ) =>
25
+ NewChargePoint ( cp . ConnectorNumber , cp . ChargePointID , config . BootNotification ?? DefaultBootNotification , config . wsURL , config . basicAuthSettings , config . autoMeterValueSetting )
27
26
)
28
27
setCps ( cps ?? [ ] ) ;
29
- const tagIDs = config ? .Experimental ? .TagIDs ;
28
+ const tagIDs = config . Experimental . TagIDs ;
30
29
setTagIDs ( tagIDs ?? [ ] ) ;
30
+ } else {
31
+ setCps ( [
32
+ NewChargePoint ( config . connectorNumber , config . ChargePointID , config . BootNotification ?? DefaultBootNotification , config . wsURL , config . basicAuthSettings , config . autoMeterValueSetting )
33
+ ] ) ;
31
34
}
32
- } , [ ] ) ;
33
-
35
+ } , [ config , navigate ] ) ;
34
36
35
37
return (
36
38
< div className = "bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4" >
37
39
{
38
- cps . length = == 1 ? (
39
- < >
40
- < ChargePoint cp = { cps [ 0 ] } TagID = { config ?. tagID ?? "" } />
41
- </ >
40
+ config ?. Experimental || cps . length ! == 1 ? (
41
+ < >
42
+ < ExperimentalView cps = { cps } tagIDs = { tagIDs } />
43
+ </ >
42
44
) : (
43
- < >
44
- < ExperimentalView cps = { cps } tagIDs = { tagIDs } />
45
- </ >
45
+ < >
46
+ < ChargePoint cp = { cps [ 0 ] } TagID = { config ?. tagID ?? "" } />
47
+ </ >
46
48
)
47
49
}
48
50
</ div >
0 commit comments