1- import { Fragment , useEffect , useState } from 'react' ;
1+ import { useEffect , useState } from 'react' ;
22import Form from 'react-bootstrap/Form' ;
33import Button from 'react-bootstrap/Button' ;
44import ButtonGroup from 'react-bootstrap/ButtonGroup' ;
55import InputGroup from 'react-bootstrap/InputGroup' ;
66import { useDispatch , useSelector } from 'react-redux' ;
7- import { getConfigAsync , removeStationConfigAsync , saveAccessPointConfigAsync , saveConfigAsync , saveStationConfigAsync , selectWiFiAccessPointConfig , selectWiFiConfig , selectWiFiStationsConfig } from './wifiSlice' ;
7+ import {
8+ getConfigAsync ,
9+ removeStationConfigAsync ,
10+ saveAccessPointConfigAsync ,
11+ saveStationConfigAsync ,
12+ selectWiFiAccessPointConfig ,
13+ selectConfig ,
14+ selectWiFiStationsConfig
15+ } from './configSlice' ;
816import Spinner from 'react-bootstrap/Spinner' ;
917import { FaRegEye , FaRegEyeSlash } from "react-icons/fa" ;
1018import Container from 'react-bootstrap/Container' ;
1119import Row from 'react-bootstrap/Row' ;
1220import Col from 'react-bootstrap/Col' ;
1321import { ConfirmModal } from '../../ConfirmModal' ;
14- import { reconnectWiFiAsync , restartAsync } from './appSlice' ;
22+ import { reconnectWiFiAsync } from './appSlice' ;
1523import { RestartModalButton } from './RestartModalButton' ;
1624import { SaveConfigModalButton } from './SaveConfigModalButton' ;
1725
18- const WiFiPasswordControl = ( { label, ...props } ) => {
26+ const WiFiPasswordControl = ( { label, ...props } ) => {
1927 const [ show , setShow ] = useState ( false ) ;
2028 return < InputGroup >
21- { label && < InputGroup . Text > { label } </ InputGroup . Text > }
29+ { label && < InputGroup . Text > { label } </ InputGroup . Text > }
2230 < Form . Control type = { show ? 'text' : 'password' } { ...props } autoComplete = 'new-password' />
23- < Button variant = 'outline-secondary' onClick = { ( ) => setShow ( ! show ) } >
24- { show ? < FaRegEyeSlash /> : < FaRegEye /> }
31+ < Button variant = 'outline-secondary' onClick = { ( ) => setShow ( ! show ) } >
32+ { show ? < FaRegEyeSlash /> : < FaRegEye /> }
2533 </ Button >
2634 </ InputGroup >
2735}
@@ -40,7 +48,7 @@ const WiFiAccessPoint = () => {
4048 < Form . Group as = { Row } >
4149 < Form . Label column sm = { 4 } > Hostname/AccessPoint ESSID</ Form . Label >
4250 < Col sm = { 8 } >
43- < Form . Control type = 'text' value = { essid } onChange = { e => setEssid ( e . target . value ) } />
51+ < Form . Control type = 'text' value = { essid } onChange = { e => setEssid ( e . target . value ) } />
4452 < Form . Text muted > This will be used as he DHCP hostname sent to your server. It's also the access point ESSID that will be used if AstroPowerBox can't be connected to any WiFi station</ Form . Text >
4553 </ Col >
4654 </ Form . Group >
@@ -54,12 +62,12 @@ const WiFiAccessPoint = () => {
5462 </ Form . Group >
5563 < ButtonGroup className = 'float-end' >
5664 < Button disabled = { ! isChanged ( ) } variant = "secondary" onClick = { resetState } > Reset</ Button >
57- < Button disabled = { ! isChanged ( ) } variant = "danger" onClick = { ( ) => dispatch ( saveAccessPointConfigAsync ( { essid, psk} ) ) } > Update</ Button >
65+ < Button disabled = { ! isChanged ( ) } variant = "danger" onClick = { ( ) => dispatch ( saveAccessPointConfigAsync ( { essid, psk } ) ) } > Update</ Button >
5866 </ ButtonGroup >
5967 </ Form >
6068}
6169
62- const WifiStation = ( { station, index} ) => {
70+ const WifiStation = ( { station, index } ) => {
6371 const [ essid , setEssid ] = useState ( station . essid )
6472 const [ psk , setPsk ] = useState ( station . psk )
6573 const dispatch = useDispatch ( ) ;
@@ -69,49 +77,49 @@ const WifiStation = ({station, index}) => {
6977 setPsk ( station . psk )
7078 }
7179 useEffect ( resetState , [ station ] ) ;
72- return < Form . Group as = { Row } className = 'mt-2' >
73- < Form . Label column lg = { 1 } > Station { index } </ Form . Label >
74- < Col lg = { 4 } >
75- < InputGroup >
76- < InputGroup . Text > ESSID</ InputGroup . Text >
77- < Form . Control type = 'text' value = { essid } onChange = { e => setEssid ( e . target . value ) } />
78- </ InputGroup >
79- </ Col >
80- < Col lg = { 5 } >
81- < WiFiPasswordControl label = 'Password' value = { psk } onChange = { e => setPsk ( e . target . value ) } />
82- </ Col >
83- < Col lg = { 2 } className = 'd-grid' >
84- < ButtonGroup className = 'float-end' size = 'sm' >
85- < Button disabled = { ! isChanged ( ) } variant = "secondary" onClick = { resetState } > Reset</ Button >
86- < Button disabled = { ! isChanged ( ) } variant = "danger" onClick = { ( ) => dispatch ( saveStationConfigAsync ( { index, essid, psk} ) ) } > Update</ Button >
87- < Button disabled = { ! station . essid && ! station . psk } variant = "warning" onClick = { ( ) => dispatch ( removeStationConfigAsync ( { index} ) ) } > Remove</ Button >
88- </ ButtonGroup >
89- </ Col >
90- </ Form . Group >
80+ return < Form . Group as = { Row } className = 'mt-2' >
81+ < Form . Label column lg = { 1 } > Station { index } </ Form . Label >
82+ < Col lg = { 4 } >
83+ < InputGroup >
84+ < InputGroup . Text > ESSID</ InputGroup . Text >
85+ < Form . Control type = 'text' value = { essid } onChange = { e => setEssid ( e . target . value ) } />
86+ </ InputGroup >
87+ </ Col >
88+ < Col lg = { 5 } >
89+ < WiFiPasswordControl label = 'Password' value = { psk } onChange = { e => setPsk ( e . target . value ) } />
90+ </ Col >
91+ < Col lg = { 2 } className = 'd-grid' >
92+ < ButtonGroup className = 'float-end' size = 'sm' >
93+ < Button disabled = { ! isChanged ( ) } variant = "secondary" onClick = { resetState } > Reset</ Button >
94+ < Button disabled = { ! isChanged ( ) } variant = "danger" onClick = { ( ) => dispatch ( saveStationConfigAsync ( { index, essid, psk } ) ) } > Update</ Button >
95+ < Button disabled = { ! station . essid && ! station . psk } variant = "warning" onClick = { ( ) => dispatch ( removeStationConfigAsync ( { index } ) ) } > Remove</ Button >
96+ </ ButtonGroup >
97+ </ Col >
98+ </ Form . Group >
9199}
92100
93101const WiFiStations = ( ) => {
94102 const stations = useSelector ( selectWiFiStationsConfig ) ;
95103 return < Form >
96- { stations . map ( ( station , index ) => < WifiStation station = { station } index = { index } key = { index } /> ) }
104+ { stations . map ( ( station , index ) => < WifiStation station = { station } index = { index } key = { index } /> ) }
97105 </ Form >
98- }
106+ }
99107
100108export const WiFi = ( ) => {
101109 const dispatch = useDispatch ( ) ;
102110 useEffect ( ( ) => { dispatch ( getConfigAsync ( ) ) } , [ dispatch ] )
103- const wifiConfig = useSelector ( selectWiFiConfig )
111+ const wifiConfig = useSelector ( selectConfig )
104112
105- if ( ! wifiConfig . ready ) {
106- return < Spinner />
113+ if ( ! wifiConfig . ready ) {
114+ return < Spinner />
107115 }
108116 return < Container >
109117 < Row >
110- < Col md = { { span :10 , offset :1 } } >
118+ < Col md = { { span : 10 , offset : 1 } } >
111119 < WiFiAccessPoint />
112120 </ Col >
113121 </ Row >
114- < Row className = 'mt-5' >
122+ < Row className = 'mt-5' >
115123 < WiFiStations />
116124 </ Row >
117125 < Row className = 'mt-5' >
@@ -121,8 +129,8 @@ export const WiFi = () => {
121129 < Row className = 'mt-2' >
122130 < Col sm = { 10 } > Reconnecting wifi will allow to apply some changes without restarting.</ Col >
123131 < Col sm = { 2 } className = 'd-grid' >
124- < ConfirmModal
125- confirmButton = 'Reconnect'
132+ < ConfirmModal
133+ confirmButton = 'Reconnect'
126134 text = 'Reconnecting WiFi might cause connectivity loss. Do you want to continue?'
127135 onConfirm = { ( ) => dispatch ( reconnectWiFiAsync ( ) ) }
128136 RenderButton = { ( props ) => < Button { ...props } variant = 'warning' > Reconnect WiFi</ Button > }
@@ -134,6 +142,6 @@ export const WiFi = () => {
134142 < Col sm = { 2 } className = 'd-grid' > < RestartModalButton /> </ Col >
135143 </ Row >
136144 </ Container >
137-
138-
145+
146+
139147}
0 commit comments