chore: type selectedUsers action and reducer and improvement in the code of other files
This commit is contained in:
parent
9d7450b300
commit
003f9fca68
|
@ -2,8 +2,8 @@ const REQUEST = 'REQUEST';
|
|||
const SUCCESS = 'SUCCESS';
|
||||
const FAILURE = 'FAILURE';
|
||||
const defaultTypes = [REQUEST, SUCCESS, FAILURE];
|
||||
function createRequestTypes(base, types = defaultTypes) {
|
||||
const res = {};
|
||||
function createRequestTypes(base = {}, types = defaultTypes): Record<any, any> {
|
||||
const res: Record<any, any> = {};
|
||||
types.forEach(type => (res[type] = `${base}_${type}`));
|
||||
return res;
|
||||
}
|
|
@ -1,14 +1,15 @@
|
|||
import { Action } from 'redux';
|
||||
|
||||
import { ActiveUsers } from '../reducers/activeUsers';
|
||||
import { IActiveUsers } from '../reducers/activeUsers';
|
||||
import { SET_ACTIVE_USERS } from './actionsTypes';
|
||||
|
||||
export interface SetActiveUsers extends Action {
|
||||
type: typeof SET_ACTIVE_USERS;
|
||||
activeUsers: ActiveUsers;
|
||||
activeUsers: IActiveUsers;
|
||||
}
|
||||
|
||||
export const setActiveUsers = (activeUsers: ActiveUsers): SetActiveUsers => ({
|
||||
export type IActionActiveUsers = SetActiveUsers;
|
||||
|
||||
export const setActiveUsers = (activeUsers: IActiveUsers): SetActiveUsers => ({
|
||||
type: SET_ACTIVE_USERS,
|
||||
activeUsers
|
||||
});
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
import * as types from './actionsTypes';
|
||||
|
||||
export function addUser(user) {
|
||||
return {
|
||||
type: types.SELECTED_USERS.ADD_USER,
|
||||
user
|
||||
};
|
||||
}
|
||||
|
||||
export function removeUser(user) {
|
||||
return {
|
||||
type: types.SELECTED_USERS.REMOVE_USER,
|
||||
user
|
||||
};
|
||||
}
|
||||
|
||||
export function reset() {
|
||||
return {
|
||||
type: types.SELECTED_USERS.RESET
|
||||
};
|
||||
}
|
||||
|
||||
export function setLoading(loading) {
|
||||
return {
|
||||
type: types.SELECTED_USERS.SET_LOADING,
|
||||
loading
|
||||
};
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
import { Action } from 'redux';
|
||||
|
||||
import { IUser } from '../types';
|
||||
import * as types from './actionsTypes';
|
||||
|
||||
type User = {
|
||||
user: IUser;
|
||||
};
|
||||
|
||||
type IAction = Action & User;
|
||||
|
||||
interface SetLoading extends Action {
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
export type IActionSelectedUsers = IAction & SetLoading;
|
||||
|
||||
export function addUser(user: IUser): IAction {
|
||||
return {
|
||||
type: types.SELECTED_USERS.ADD_USER,
|
||||
user
|
||||
};
|
||||
}
|
||||
|
||||
export function removeUser(user: IUser): IAction {
|
||||
return {
|
||||
type: types.DEEP_LINKING,
|
||||
user
|
||||
};
|
||||
}
|
||||
|
||||
export function reset(): Action {
|
||||
return {
|
||||
type: types.SELECTED_USERS.RESET
|
||||
};
|
||||
}
|
||||
|
||||
export function setLoading(loading: boolean): SetLoading {
|
||||
return {
|
||||
type: types.SELECTED_USERS.SET_LOADING,
|
||||
loading
|
||||
};
|
||||
}
|
|
@ -1,20 +1,13 @@
|
|||
import { SetActiveUsers } from '../actions/activeUsers';
|
||||
import { ActiveUser, ApplicationActions } from '../types';
|
||||
import { SET_ACTIVE_USERS } from '../actions/actionsTypes';
|
||||
|
||||
type UserStatus = 'online' | 'offline';
|
||||
|
||||
interface ActiveUser {
|
||||
readonly status: UserStatus;
|
||||
readonly statusText?: string;
|
||||
}
|
||||
|
||||
export interface ActiveUsers {
|
||||
export interface IActiveUsers {
|
||||
[key: string]: ActiveUser;
|
||||
}
|
||||
|
||||
const initialState: ActiveUsers = {};
|
||||
const initialState: IActiveUsers = {};
|
||||
|
||||
export default function activeUsers(state = initialState, action: SetActiveUsers): ActiveUsers {
|
||||
export default function activeUsers(state = initialState, action: ApplicationActions): IActiveUsers {
|
||||
switch (action.type) {
|
||||
case SET_ACTIVE_USERS:
|
||||
return {
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
import { IUser, ApplicationActions } from '../types';
|
||||
import { SELECTED_USERS } from '../actions/actionsTypes';
|
||||
|
||||
const initialState = {
|
||||
export interface ISelectedUsers {
|
||||
users: IUser[];
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
const initialState: ISelectedUsers = {
|
||||
users: [],
|
||||
loading: false
|
||||
};
|
||||
|
||||
export default function (state = initialState, action) {
|
||||
export default function (state = initialState, action: ApplicationActions): ISelectedUsers {
|
||||
switch (action.type) {
|
||||
case SELECTED_USERS.ADD_USER:
|
||||
return {
|
|
@ -7,4 +7,19 @@ export interface BaseScreen {
|
|||
theme: string;
|
||||
}
|
||||
|
||||
export interface IUser {
|
||||
_id: string;
|
||||
name: string;
|
||||
fname: string;
|
||||
search?: boolean;
|
||||
// username is used when is from searching
|
||||
username?: string;
|
||||
}
|
||||
|
||||
type UserStatus = 'online' | 'offline';
|
||||
export interface ActiveUser {
|
||||
status: UserStatus;
|
||||
statusText?: string;
|
||||
}
|
||||
|
||||
export * from './redux';
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import { SetActiveUsers } from '../../actions/activeUsers';
|
||||
import { ActiveUsers } from '../../reducers/activeUsers';
|
||||
import { IActionSelectedUsers } from '../../actions/selectedUsers';
|
||||
import { IActionActiveUsers } from '../../actions/activeUsers';
|
||||
// REDUCERS
|
||||
import { IActiveUsers } from '../../reducers/activeUsers';
|
||||
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
||||
|
||||
export interface ApplicationState {
|
||||
settings: any;
|
||||
login: any;
|
||||
meteor: any;
|
||||
server: any;
|
||||
selectedUsers: any;
|
||||
selectedUsers: ISelectedUsers;
|
||||
createChannel: any;
|
||||
app: any;
|
||||
room: any;
|
||||
|
@ -14,7 +17,7 @@ export interface ApplicationState {
|
|||
sortPreferences: any;
|
||||
share: any;
|
||||
customEmojis: any;
|
||||
activeUsers: ActiveUsers;
|
||||
activeUsers: IActiveUsers;
|
||||
usersTyping: any;
|
||||
inviteLinks: any;
|
||||
createDiscussion: any;
|
||||
|
@ -25,4 +28,4 @@ export interface ApplicationState {
|
|||
roles: any;
|
||||
}
|
||||
|
||||
export type ApplicationActions = SetActiveUsers;
|
||||
export type ApplicationActions = IActionActiveUsers & IActionSelectedUsers;
|
||||
|
|
Loading…
Reference in New Issue