feat(Relays): added logic to manage relays #63
@ -1,5 +1,7 @@
|
|||||||
export const RESTORE_STATE = 'RESTORE_STATE'
|
export const RESTORE_STATE = 'RESTORE_STATE'
|
||||||
|
|
||||||
|
export const USER_LOGOUT = 'USER_LOGOUT'
|
||||||
|
|
||||||
export const SET_AUTH_STATE = 'SET_AUTH_STATE'
|
export const SET_AUTH_STATE = 'SET_AUTH_STATE'
|
||||||
export const UPDATE_LOGIN_METHOD = 'UPDATE_LOGIN_METHOD'
|
export const UPDATE_LOGIN_METHOD = 'UPDATE_LOGIN_METHOD'
|
||||||
export const UPDATE_KEYPAIR = 'UPDATE_KEYPAIR'
|
export const UPDATE_KEYPAIR = 'UPDATE_KEYPAIR'
|
||||||
@ -11,3 +13,7 @@ export const SET_METADATA_EVENT = 'SET_METADATA_EVENT'
|
|||||||
export const SET_USER_ROBOT_IMAGE = 'SET_USER_ROBOT_IMAGE'
|
export const SET_USER_ROBOT_IMAGE = 'SET_USER_ROBOT_IMAGE'
|
||||||
|
|
||||||
export const SET_RELAY_MAP = 'SET_RELAY_MAP'
|
export const SET_RELAY_MAP = 'SET_RELAY_MAP'
|
||||||
|
export const SET_RELAY_INFO = 'SET_RELAY_INFO'
|
||||||
|
export const SET_RELAY_MAP_UPDATED = 'SET_RELAY_MAP_UPDATED'
|
||||||
|
export const SET_MOST_POPULAR_RELAYS = 'SET_MOST_POPULAR_RELAYS'
|
||||||
|
export const SET_RELAY_CONNECTION_STATUS = 'SET_RELAY_CONNECTION_STATUS'
|
||||||
|
@ -1,8 +1,39 @@
|
|||||||
import * as ActionTypes from '../actionTypes'
|
import * as ActionTypes from '../actionTypes'
|
||||||
import { SetRelayMapAction } from './types'
|
import {
|
||||||
import { RelayMap } from '../../types'
|
SetRelayMapAction,
|
||||||
|
SetMostPopularRelaysAction,
|
||||||
|
SetRelayInfoAction,
|
||||||
|
SetRelayConnectionStatusAction,
|
||||||
|
SetRelayMapUpdatedAction
|
||||||
|
} from './types'
|
||||||
|
import { RelayMap, RelayInfoObject, RelayConnectionStatus } from '../../types'
|
||||||
|
|
||||||
export const setRelayMapAction = (payload: RelayMap): SetRelayMapAction => ({
|
export const setRelayMapAction = (payload: RelayMap): SetRelayMapAction => ({
|
||||||
type: ActionTypes.SET_RELAY_MAP,
|
type: ActionTypes.SET_RELAY_MAP,
|
||||||
payload
|
payload
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const setRelayInfoAction = (
|
||||||
|
payload: RelayInfoObject
|
||||||
|
): SetRelayInfoAction => ({
|
||||||
|
type: ActionTypes.SET_RELAY_INFO,
|
||||||
|
payload
|
||||||
|
})
|
||||||
|
|
||||||
|
export const setMostPopularRelaysAction = (
|
||||||
|
payload: string[]
|
||||||
|
): SetMostPopularRelaysAction => ({
|
||||||
|
type: ActionTypes.SET_MOST_POPULAR_RELAYS,
|
||||||
|
payload
|
||||||
|
})
|
||||||
|
|
||||||
|
export const setRelayConnectionStatusAction = (
|
||||||
|
payload: RelayConnectionStatus
|
||||||
|
): SetRelayConnectionStatusAction => ({
|
||||||
|
type: ActionTypes.SET_RELAY_CONNECTION_STATUS,
|
||||||
|
payload
|
||||||
|
})
|
||||||
|
|
||||||
|
export const setRelayMapUpdatedAction = (): SetRelayMapUpdatedAction => ({
|
||||||
|
type: ActionTypes.SET_RELAY_MAP_UPDATED
|
||||||
|
})
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
import * as ActionTypes from '../actionTypes'
|
import * as ActionTypes from '../actionTypes'
|
||||||
import { RelaysDispatchTypes, RelaysState } from './types'
|
import { RelaysDispatchTypes, RelaysState } from './types'
|
||||||
|
|
||||||
const initialState: RelaysState | null = null
|
const initialState: RelaysState = {
|
||||||
|
map: undefined,
|
||||||
|
mapUpdated: undefined,
|
||||||
|
mostPopular: undefined,
|
||||||
|
info: undefined,
|
||||||
|
connectionStatus: undefined
|
||||||
|
}
|
||||||
|
|
||||||
const reducer = (
|
const reducer = (
|
||||||
state = initialState,
|
state = initialState,
|
||||||
@ -9,7 +15,25 @@ const reducer = (
|
|||||||
): RelaysState | null => {
|
): RelaysState | null => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionTypes.SET_RELAY_MAP:
|
case ActionTypes.SET_RELAY_MAP:
|
||||||
return { map: action.payload, mapUpdated: Date.now() }
|
return { ...state, map: action.payload, mapUpdated: Date.now() }
|
||||||
|
|
||||||
|
case ActionTypes.SET_RELAY_MAP_UPDATED:
|
||||||
|
return { ...state, mapUpdated: Date.now() }
|
||||||
|
|
||||||
|
case ActionTypes.SET_RELAY_INFO:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
info: { ...state.info, ...action.payload }
|
||||||
|
}
|
||||||
|
|
||||||
|
case ActionTypes.SET_RELAY_CONNECTION_STATUS:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
connectionStatus: action.payload
|
||||||
|
}
|
||||||
|
|
||||||
|
case ActionTypes.SET_MOST_POPULAR_RELAYS:
|
||||||
|
return { ...state, mostPopular: action.payload }
|
||||||
|
|
||||||
case ActionTypes.RESTORE_STATE:
|
case ActionTypes.RESTORE_STATE:
|
||||||
return action.payload.relays
|
return action.payload.relays
|
||||||
|
@ -1,12 +1,43 @@
|
|||||||
import * as ActionTypes from '../actionTypes'
|
import * as ActionTypes from '../actionTypes'
|
||||||
import { RestoreState } from '../actions'
|
import { RestoreState } from '../actions'
|
||||||
import { RelayMap } from '../../types'
|
import { RelayMap, RelayInfoObject, RelayConnectionStatus } from '../../types'
|
||||||
|
|
||||||
export type RelaysState = { map: RelayMap; mapUpdated: number }
|
export type RelaysState = {
|
||||||
|
map?: RelayMap
|
||||||
|
mapUpdated?: number
|
||||||
|
mostPopular?: string[]
|
||||||
|
info?: RelayInfoObject
|
||||||
|
connectionStatus?: RelayConnectionStatus
|
||||||
|
}
|
||||||
|
|
||||||
export interface SetRelayMapAction {
|
export interface SetRelayMapAction {
|
||||||
type: typeof ActionTypes.SET_RELAY_MAP
|
type: typeof ActionTypes.SET_RELAY_MAP
|
||||||
payload: RelayMap
|
payload: RelayMap
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RelaysDispatchTypes = SetRelayMapAction | RestoreState
|
export interface SetMostPopularRelaysAction {
|
||||||
|
type: typeof ActionTypes.SET_MOST_POPULAR_RELAYS
|
||||||
|
payload: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SetRelayInfoAction {
|
||||||
|
type: typeof ActionTypes.SET_RELAY_INFO
|
||||||
|
payload: RelayInfoObject
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SetRelayConnectionStatusAction {
|
||||||
|
type: typeof ActionTypes.SET_RELAY_CONNECTION_STATUS
|
||||||
|
payload: RelayConnectionStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SetRelayMapUpdatedAction {
|
||||||
|
type: typeof ActionTypes.SET_RELAY_MAP_UPDATED
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RelaysDispatchTypes =
|
||||||
|
| SetRelayMapAction
|
||||||
|
| SetRelayInfoAction
|
||||||
|
| SetRelayMapUpdatedAction
|
||||||
|
| SetMostPopularRelaysAction
|
||||||
|
| SetRelayConnectionStatusAction
|
||||||
|
| RestoreState
|
||||||
|
Loading…
Reference in New Issue
Block a user