mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 10:19:10 +00:00
temp commit
This commit is contained in:
parent
e86f7ff68e
commit
6fb39d6c4d
22 changed files with 282 additions and 39 deletions
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue