Linked CreateServer component with redux

This commit is contained in:
Alejandro Celaya
2018-07-16 18:25:37 +02:00
parent 554248c376
commit ebb94a17ab
5 changed files with 74 additions and 31 deletions

View File

@@ -1,4 +1,8 @@
import Storage from '../../utils/Storage';
import { assoc } from 'ramda';
import { v4 as uuid } from 'uuid';
const SERVERS_STORAGE_KEY = 'servers';
export class ServersService {
constructor(storage) {
@@ -6,13 +10,20 @@ export class ServersService {
}
listServers = () => {
return this.storage.get('servers');
return this.storage.get(SERVERS_STORAGE_KEY);
};
findServerById = serverId => {
const servers = this.listServers();
return servers[serverId];
}
};
createServer = server => {
const servers = this.listServers();
server = assoc('id', uuid(), server);
servers[server.id] = server;
this.storage.set(SERVERS_STORAGE_KEY, servers);
};
}
export default new ServersService(Storage);