diff --git a/src/app/flux/machine/action-connect.js b/src/app/flux/machine/action-connect.js index 391d689bcd..e66e33bcae 100644 --- a/src/app/flux/machine/action-connect.js +++ b/src/app/flux/machine/action-connect.js @@ -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'; @@ -36,8 +36,17 @@ const setConnectionTimeout = (connectionTimeout) => (dispatch) => { * Set selected server. * * Update state only, we will save the server when connection established. + * If 'server' is not found in 'servers' list, add it and update state */ -const setSelectedServer = (server) => (dispatch) => { +const setSelectedServer = (server) => (dispatch, getState) => { + const { servers } = getState().machine; + + const find = servers.find(v => v.equals(server)); + if (!find) { + const newServers = servers.slice(0); + newServers.push(server); + dispatch(baseActions.updateState({ servers: newServers })); + } dispatch(baseActions.updateState({ server })); }; diff --git a/src/app/widgets/Connection/WifiConnection.jsx b/src/app/widgets/Connection/WifiConnection.jsx index 979aeb9886..d70c1a2be3 100644 --- a/src/app/widgets/Connection/WifiConnection.jsx +++ b/src/app/widgets/Connection/WifiConnection.jsx @@ -247,7 +247,7 @@ class WifiConnection extends PureComponent { } else { find = servers.find(v => v.name === server.name && v.address === server.address); } - if (find) { + if (find && find !== server) { this.setState({ server: find });