Skip to content

Commit

Permalink
Fix: Fix connecting wifi manually bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jane-rose committed Jan 7, 2021
1 parent 57844e4 commit f9c900a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/app/flux/machine/action-connect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import includes from 'lodash/includes';
import isInteger from 'lodash/isInteger';

import { Server } from './Server';
import { CONNECTION_TYPE_SERIAL, CONNECTION_TYPE_WIFI } from '../../constants';
import { machineStore } from '../../store/local-storage';

Expand Down Expand Up @@ -41,6 +41,22 @@ const setSelectedServer = (server) => (dispatch) => {
dispatch(baseActions.updateState({ server }));
};

const addSelectedServerToList = (server) => (dispatch, getState) => {
const { servers } = getState().machine;

const newServers = [];
const find = servers.find(v => v.equals(server));
if (find) {
// use old Server instance
newServers.push(find);
} else {
const newServer = new Server(server.name, server.address, server.model);
newServers.push(newServer);
}

dispatch(baseActions.updateState({ servers: newServers }));
};

const setServerAddress = (serverAddress) => (dispatch) => {
dispatch(baseActions.updateState({ serverAddress: serverAddress }));

Expand Down Expand Up @@ -73,6 +89,7 @@ export default {
setConnectionTimeout,

setSelectedServer,
addSelectedServerToList,

setMachineSerialPort,

Expand Down
3 changes: 3 additions & 0 deletions src/app/widgets/Connection/WifiConnection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class WifiConnection extends PureComponent {
manualIp: PropTypes.string,
serverAddress: PropTypes.string,

addSelectedServerToList: PropTypes.func.isRequired,
setSelectedServer: PropTypes.func.isRequired,
setManualIP: PropTypes.func.isRequired,

Expand Down Expand Up @@ -192,6 +193,7 @@ class WifiConnection extends PureComponent {

this.props.setManualIP(text);
const server = new Server('Manual', text);
this.props.addSelectedServerToList(server);
this.props.setSelectedServer(server);
this.props.openServer();
}
Expand Down Expand Up @@ -487,6 +489,7 @@ const mapDispatchToProps = (dispatch) => ({
openServer: (callback) => dispatch(machineActions.openServer(callback)),
closeServer: (state) => dispatch(machineActions.closeServer(state)),
setSelectedServer: (server) => dispatch(machineActions.connect.setSelectedServer(server)),
addSelectedServerToList: (server) => dispatch(machineActions.connect.addSelectedServerToList(server)),
setManualIP: (server) => dispatch(machineActions.connect.setManualIP(server))
});

Expand Down

0 comments on commit f9c900a

Please sign in to comment.