Updated list servers action so that it tries to fetch servers from the servers.json file when no local servers are found

This commit is contained in:
Alejandro Celaya
2019-04-28 12:07:09 +02:00
parent 502c8a7e02
commit 20820c47d4
9 changed files with 74 additions and 48 deletions

View File

@@ -1,9 +1,3 @@
import PropTypes from 'prop-types';
export const serversImporterType = PropTypes.shape({
importServersFromFile: PropTypes.func,
});
export default class ServersImporter {
constructor(csvjson) {
this.csvjson = csvjson;

View File

@@ -1,10 +1,11 @@
import { assoc, dissoc, reduce } from 'ramda';
import { assoc, curry, dissoc, reduce } from 'ramda';
const SERVERS_STORAGE_KEY = 'servers';
export default class ServersService {
constructor(storage) {
this.storage = storage;
this.setServers = curry(this.storage.set)(SERVERS_STORAGE_KEY);
}
listServers = () => this.storage.get(SERVERS_STORAGE_KEY) || {};
@@ -20,12 +21,9 @@ export default class ServersService {
servers
);
this.storage.set(SERVERS_STORAGE_KEY, allServers);
this.setServers(allServers);
};
deleteServer = (server) =>
this.storage.set(
SERVERS_STORAGE_KEY,
dissoc(server.id, this.listServers())
);
deleteServer = ({ id }) =>
this.setServers(dissoc(id, this.listServers()));
}

View File

@@ -38,7 +38,7 @@ const provideServices = (bottle, connect, withRouter) => {
bottle.serviceFactory('createServer', createServer, 'ServersService', 'listServers');
bottle.serviceFactory('createServers', createServers, 'ServersService', 'listServers');
bottle.serviceFactory('deleteServer', deleteServer, 'ServersService', 'listServers');
bottle.serviceFactory('listServers', listServers, 'ServersService');
bottle.serviceFactory('listServers', listServers, 'ServersService', 'axios');
bottle.serviceFactory('resetSelectedServer', () => resetSelectedServer);
};