Adding and updating Servers, fixes #524

This commit is contained in:
James Barnsley
2020-04-28 21:24:17 +12:00
parent 92292b18d7
commit 0caa780e38
17 changed files with 454 additions and 258 deletions

View File

@ -284,10 +284,20 @@ const MopidyMiddleware = (function () {
});
break;
case 'MOPIDY_SET_CONNECTION':
store.dispatch(mopidyActions.set(action.data));
case 'MOPIDY_UPDATE_SERVER':
let servers = store.getState().mopidy.servers;
servers[action.server.id] = { ...servers[action.server.id], ...action.server };
store.dispatch(mopidyActions.updateServers(servers));
break;
// Wait 250 ms and then retry connection
case 'MOPIDY_SET_CURRENT_SERVER':
store.dispatch(mopidyActions.set({
current_server: action.server.id,
host: action.server.host,
port: action.server.port
}));
// Wait a moment for store to update, then attempt connection
setTimeout(
() => {
store.dispatch(mopidyActions.connect());
@ -297,6 +307,12 @@ const MopidyMiddleware = (function () {
);
break;
case 'MOPIDY_REMOVE_SERVER':
let remaining_servers = store.getState().mopidy.servers;
delete remaining_servers[action.id];
store.dispatch(mopidyActions.updateServers(remaining_servers));
break;
case 'SET_WINDOW_FOCUS':
// Focus has just been regained