From 106827b6da2553acf7db27dfe0fe1b292837b654 Mon Sep 17 00:00:00 2001 From: Yury Date: Fri, 24 May 2024 15:29:00 +0300 Subject: [PATCH] feat(Store): configured relays state --- src/store/actionTypes.ts | 6 ++++++ src/store/relays/action.ts | 35 +++++++++++++++++++++++++++++++++-- src/store/relays/reducer.ts | 28 ++++++++++++++++++++++++++-- src/store/relays/types.ts | 37 ++++++++++++++++++++++++++++++++++--- 4 files changed, 99 insertions(+), 7 deletions(-) diff --git a/src/store/actionTypes.ts b/src/store/actionTypes.ts index 990c495..18b4063 100644 --- a/src/store/actionTypes.ts +++ b/src/store/actionTypes.ts @@ -1,5 +1,7 @@ export const RESTORE_STATE = 'RESTORE_STATE' +export const USER_LOGOUT = 'USER_LOGOUT' + export const SET_AUTH_STATE = 'SET_AUTH_STATE' export const UPDATE_LOGIN_METHOD = 'UPDATE_LOGIN_METHOD' 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_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' diff --git a/src/store/relays/action.ts b/src/store/relays/action.ts index ff18724..6f95840 100644 --- a/src/store/relays/action.ts +++ b/src/store/relays/action.ts @@ -1,8 +1,39 @@ import * as ActionTypes from '../actionTypes' -import { SetRelayMapAction } from './types' -import { RelayMap } from '../../types' +import { + SetRelayMapAction, + SetMostPopularRelaysAction, + SetRelayInfoAction, + SetRelayConnectionStatusAction, + SetRelayMapUpdatedAction +} from './types' +import { RelayMap, RelayInfoObject, RelayConnectionStatus } from '../../types' export const setRelayMapAction = (payload: RelayMap): SetRelayMapAction => ({ type: ActionTypes.SET_RELAY_MAP, 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 +}) diff --git a/src/store/relays/reducer.ts b/src/store/relays/reducer.ts index 5febd1b..b4b9854 100644 --- a/src/store/relays/reducer.ts +++ b/src/store/relays/reducer.ts @@ -1,7 +1,13 @@ import * as ActionTypes from '../actionTypes' 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 = ( state = initialState, @@ -9,7 +15,25 @@ const reducer = ( ): RelaysState | null => { switch (action.type) { 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: return action.payload.relays diff --git a/src/store/relays/types.ts b/src/store/relays/types.ts index 3a86aac..e1c4da8 100644 --- a/src/store/relays/types.ts +++ b/src/store/relays/types.ts @@ -1,12 +1,43 @@ import * as ActionTypes from '../actionTypes' 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 { type: typeof ActionTypes.SET_RELAY_MAP 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