chore: migrate activeUsers reducer and action to TS

This commit is contained in:
GleidsonDaniel 2021-12-21 09:51:04 -03:00
parent b75e192e20
commit 3b97c34959
4 changed files with 41 additions and 23 deletions

View File

@ -1,8 +0,0 @@
import { SET_ACTIVE_USERS } from './actionsTypes';
export function setActiveUsers(activeUsers) {
return {
type: SET_ACTIVE_USERS,
activeUsers
};
}

View File

@ -0,0 +1,14 @@
import { Action } from 'redux';
import { ActiveUsers } from '../reducers/activeUsers';
import { SET_ACTIVE_USERS } from './actionsTypes';
export interface SetActiveUsers extends Action {
type: typeof SET_ACTIVE_USERS;
activeUsers: ActiveUsers;
}
export const setActiveUsers = (activeUsers: ActiveUsers): SetActiveUsers => ({
type: SET_ACTIVE_USERS,
activeUsers
});

View File

@ -1,15 +0,0 @@
import { SET_ACTIVE_USERS } from '../actions/actionsTypes';
const initialState = {};
export default function activeUsers(state = initialState, action) {
switch (action.type) {
case SET_ACTIVE_USERS:
return {
...state,
...action.activeUsers
};
default:
return state;
}
}

View File

@ -0,0 +1,27 @@
import { SetActiveUsers } from '../actions/activeUsers';
import { SET_ACTIVE_USERS } from '../actions/actionsTypes';
type UserStatus = 'online' | 'offline';
interface ActiveUser {
readonly status: UserStatus;
readonly statusText?: string;
}
export interface ActiveUsers {
[key: string]: ActiveUser;
}
const initialState: ActiveUsers = {};
export default function activeUsers(state = initialState, action: SetActiveUsers): ActiveUsers {
switch (action.type) {
case SET_ACTIVE_USERS:
return {
...state,
...action.activeUsers
};
default:
return state;
}
}