@@ -24,15 +24,39 @@ class WiFiSettingsForm extends React.Component<WiFiStatusFormProps> {
24
24
static contextType = WiFiConnectionContext ;
25
25
context ! : React . ContextType < typeof WiFiConnectionContext > ;
26
26
27
+ constructor ( props : WiFiStatusFormProps , context : WiFiConnectionContext ) {
28
+ super ( props ) ;
29
+
30
+ const { selectedNetwork } = context ;
31
+ if ( selectedNetwork ) {
32
+ const wifiSettings : WiFiSettings = {
33
+ ssid : selectedNetwork . ssid ,
34
+ password : "" ,
35
+ hostname : props . data . hostname ,
36
+ static_ip_config : false ,
37
+ }
38
+ props . setData ( wifiSettings ) ;
39
+ }
40
+ }
41
+
27
42
componentWillMount ( ) {
28
43
ValidatorForm . addValidationRule ( 'isIP' , isIP ) ;
29
44
ValidatorForm . addValidationRule ( 'isHostname' , isHostname ) ;
30
45
ValidatorForm . addValidationRule ( 'isOptionalIP' , optional ( isIP ) ) ;
31
46
}
32
47
48
+ deselectNetworkAndLoadData = ( ) => {
49
+ this . context . deselectNetwork ( ) ;
50
+ this . props . loadData ( ) ;
51
+ }
52
+
53
+ componentWillUnmount ( ) {
54
+ this . context . deselectNetwork ( ) ;
55
+ }
56
+
33
57
render ( ) {
34
58
const { selectedNetwork, deselectNetwork } = this . context ;
35
- const { data, handleValueChange, saveData, loadData } = this . props ;
59
+ const { data, handleValueChange, saveData } = this . props ;
36
60
return (
37
61
< ValidatorForm onSubmit = { saveData } ref = "WiFiSettingsForm" >
38
62
{
@@ -167,7 +191,7 @@ class WiFiSettingsForm extends React.Component<WiFiStatusFormProps> {
167
191
< FormButton startIcon = { < SaveIcon /> } variant = "contained" color = "primary" type = "submit" >
168
192
Save
169
193
</ FormButton >
170
- < FormButton variant = "contained" color = "secondary" onClick = { loadData } >
194
+ < FormButton variant = "contained" color = "secondary" onClick = { this . deselectNetworkAndLoadData } >
171
195
Reset
172
196
</ FormButton >
173
197
</ FormActions >
0 commit comments