temp commit

This commit is contained in:
41666 2019-04-20 04:46:46 -05:00
parent e86f7ff68e
commit 6fb39d6c4d
No known key found for this signature in database
GPG key ID: BC51D07640DC10AF
22 changed files with 282 additions and 39 deletions

View file

@ -1,16 +1,29 @@
// @flow
import { namespaceConfig } from 'fast-redux'
import RPC from '../config/rpc'
// import { Map } from 'immutable'
import type { PresentableServer as Server } from '@roleypoly/types'
const DEFAULT_STATE = {}
export type ServersState = {
[id: string]: Server
}
export type ServersState = typeof DEFAULT_STATE
const DEFAULT_STATE: ServersState = {}
export const { action, getState: getServerState } = namespaceConfig('servers', DEFAULT_STATE)
export const updateServers = action('updateServers', (state: ServersState, serverData) => ({
export const updateServers = action('updateServers', (state: ServersState, serverData: Server[]) => ({
...state,
servers: serverData
...serverData.reduce((acc, s) => ({ ...acc, [s.id]: s }), {})
}))
export const updateSingleServer = action('updateSingleServer', (state, data, server) => ({ ...state, [server]: data }))
export const fetchServerList = (rpc?: typeof RPC) => async (dispatch: *) => {
if (rpc == null) {
rpc = RPC
}
const servers: Server[] = await rpc.listOwnServers()
dispatch(updateServers(servers))
}