mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 10:19:10 +00:00
first bits of redux
This commit is contained in:
parent
9c7f7fda73
commit
def2b0d2a3
13 changed files with 170 additions and 16 deletions
53
ui/stores/currentServer.js
Normal file
53
ui/stores/currentServer.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
// @flow
|
||||
import { dynamicPropertyConfig } from 'fast-redux'
|
||||
// import { Map } from 'immutable'
|
||||
import type { PresentableServer } from '../../services/presentation'
|
||||
import RPC from '../config/rpc'
|
||||
import { action } from './servers'
|
||||
|
||||
const DEFAULT_STATE: $Shape<PresentableServer> | { id: ?string } = {
|
||||
id: null,
|
||||
server: {
|
||||
name: 'PLACEHOLDER',
|
||||
id: '386659935687147521',
|
||||
icon: '4fa0c1063649a739f3fe1a0589aa2c03',
|
||||
ownerID: '62601275618889728'
|
||||
},
|
||||
gm: {
|
||||
nickname: 'person',
|
||||
color: '#ff00ff'
|
||||
},
|
||||
categories: {},
|
||||
perms: {
|
||||
isAdmin: false,
|
||||
canManageRoles: false
|
||||
},
|
||||
roles: []
|
||||
}
|
||||
|
||||
export type ServerState = PresentableServer
|
||||
|
||||
// export const { action, getState: getCurrentServerState } = namespaceConfig('currentServer', DEFAULT_STATE)
|
||||
|
||||
export const { propertyAction: currentServerAction, getPropertyState: getCurrentServerState } = dynamicPropertyConfig(action, DEFAULT_STATE)
|
||||
|
||||
export const updateCurrentServer = currentServerAction('updateCurrentServer', (state, newState) => ({ ...state, ...newState }))
|
||||
|
||||
export const fetchServerIfNeed = (id: string, rpc?: typeof RPC) => async (dispatch: *, getState: *) => {
|
||||
if (rpc == null) {
|
||||
rpc = RPC
|
||||
}
|
||||
|
||||
if (id == null) {
|
||||
console.warn({ id })
|
||||
}
|
||||
|
||||
const state: ServerState = getCurrentServerState(getState(), id)
|
||||
if (state.id == null || state.id !== id) {
|
||||
const server = await rpc.getServer(id)
|
||||
dispatch(updateCurrentServer(id, server))
|
||||
console.log({ state, server, fullStore: getState() })
|
||||
} else {
|
||||
console.log('did not update')
|
||||
}
|
||||
}
|
10
ui/stores/roles.js
Normal file
10
ui/stores/roles.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { namespaceConfig } from 'fast-redux'
|
||||
import { getCurrentServerState } from './currentServer'
|
||||
|
||||
export const { action, getState: getCurrentRoles } = namespaceConfig('roles', {})
|
||||
|
||||
export const updateCurrentRoles = action('updateCurrentRoles', (state, data) => data)
|
||||
|
||||
export const renderRoles = (dispatch, getState) => {
|
||||
const server = getCurrentServerState(getState())
|
||||
}
|
16
ui/stores/servers.js
Normal file
16
ui/stores/servers.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
// @flow
|
||||
import { namespaceConfig } from 'fast-redux'
|
||||
// import { Map } from 'immutable'
|
||||
|
||||
const DEFAULT_STATE = {}
|
||||
|
||||
export type ServersState = typeof DEFAULT_STATE
|
||||
|
||||
export const { action, getState: getServerState } = namespaceConfig('servers', DEFAULT_STATE)
|
||||
|
||||
export const updateServers = action('updateServers', (state: ServersState, serverData) => ({
|
||||
...state,
|
||||
servers: serverData
|
||||
}))
|
||||
|
||||
export const updateSingleServer = action('updateSingleServer', (state, data, server) => ({ ...state, [server]: data }))
|
32
ui/stores/user.js
Normal file
32
ui/stores/user.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
// @flow
|
||||
import { namespaceConfig } from 'fast-redux'
|
||||
|
||||
export type User = {
|
||||
id: string,
|
||||
username: string,
|
||||
discriminator: string,
|
||||
avatar: string,
|
||||
nicknameCache: {
|
||||
[server: string]: string
|
||||
}
|
||||
}
|
||||
|
||||
export type UserState = {
|
||||
currentUser: User | null,
|
||||
userCache: {
|
||||
[id: string]: User
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_STATE: UserState = {
|
||||
currentUser: null,
|
||||
userCache: {}
|
||||
}
|
||||
|
||||
export const {
|
||||
action, getState: getUserStore
|
||||
} = namespaceConfig('userStore', DEFAULT_STATE)
|
||||
|
||||
export const getCurrentUser = () => async (dispatch: Function) => {
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue