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 SUCCESS = 'SUCCESS';
|
||||||
const FAILURE = 'FAILURE';
|
const FAILURE = 'FAILURE';
|
||||||
const defaultTypes = [REQUEST, SUCCESS, FAILURE];
|
const defaultTypes = [REQUEST, SUCCESS, FAILURE];
|
||||||
function createRequestTypes(base, types = defaultTypes) {
|
function createRequestTypes(base = {}, types = defaultTypes): Record<any, any> {
|
||||||
const res = {};
|
const res: Record<any, any> = {};
|
||||||
types.forEach(type => (res[type] = `${base}_${type}`));
|
types.forEach(type => (res[type] = `${base}_${type}`));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
|
@ -1,14 +1,15 @@
|
||||||
import { Action } from 'redux';
|
import { Action } from 'redux';
|
||||||
|
|
||||||
import { ActiveUsers } from '../reducers/activeUsers';
|
import { IActiveUsers } from '../reducers/activeUsers';
|
||||||
import { SET_ACTIVE_USERS } from './actionsTypes';
|
import { SET_ACTIVE_USERS } from './actionsTypes';
|
||||||
|
|
||||||
export interface SetActiveUsers extends Action {
|
export interface SetActiveUsers extends Action {
|
||||||
type: typeof SET_ACTIVE_USERS;
|
activeUsers: IActiveUsers;
|
||||||
activeUsers: ActiveUsers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setActiveUsers = (activeUsers: ActiveUsers): SetActiveUsers => ({
|
export type IActionActiveUsers = SetActiveUsers;
|
||||||
|
|
||||||
|
export const setActiveUsers = (activeUsers: IActiveUsers): SetActiveUsers => ({
|
||||||
type: SET_ACTIVE_USERS,
|
type: SET_ACTIVE_USERS,
|
||||||
activeUsers
|
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';
|
import { SET_ACTIVE_USERS } from '../actions/actionsTypes';
|
||||||
|
|
||||||
type UserStatus = 'online' | 'offline';
|
export interface IActiveUsers {
|
||||||
|
|
||||||
interface ActiveUser {
|
|
||||||
readonly status: UserStatus;
|
|
||||||
readonly statusText?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ActiveUsers {
|
|
||||||
[key: string]: ActiveUser;
|
[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) {
|
switch (action.type) {
|
||||||
case SET_ACTIVE_USERS:
|
case SET_ACTIVE_USERS:
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
|
import { IUser, ApplicationActions } from '../types';
|
||||||
import { SELECTED_USERS } from '../actions/actionsTypes';
|
import { SELECTED_USERS } from '../actions/actionsTypes';
|
||||||
|
|
||||||
const initialState = {
|
export interface ISelectedUsers {
|
||||||
|
users: IUser[];
|
||||||
|
loading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialState: ISelectedUsers = {
|
||||||
users: [],
|
users: [],
|
||||||
loading: false
|
loading: false
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function (state = initialState, action) {
|
export default function (state = initialState, action: ApplicationActions): ISelectedUsers {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case SELECTED_USERS.ADD_USER:
|
case SELECTED_USERS.ADD_USER:
|
||||||
return {
|
return {
|
|
@ -7,4 +7,19 @@ export interface BaseScreen {
|
||||||
theme: string;
|
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';
|
export * from './redux';
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
import { SetActiveUsers } from '../../actions/activeUsers';
|
import { IActionSelectedUsers } from '../../actions/selectedUsers';
|
||||||
import { ActiveUsers } from '../../reducers/activeUsers';
|
import { IActionActiveUsers } from '../../actions/activeUsers';
|
||||||
|
// REDUCERS
|
||||||
|
import { IActiveUsers } from '../../reducers/activeUsers';
|
||||||
|
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
||||||
|
|
||||||
export interface ApplicationState {
|
export interface ApplicationState {
|
||||||
settings: any;
|
settings: any;
|
||||||
login: any;
|
login: any;
|
||||||
meteor: any;
|
meteor: any;
|
||||||
server: any;
|
server: any;
|
||||||
selectedUsers: any;
|
selectedUsers: ISelectedUsers;
|
||||||
createChannel: any;
|
createChannel: any;
|
||||||
app: any;
|
app: any;
|
||||||
room: any;
|
room: any;
|
||||||
|
@ -14,7 +17,7 @@ export interface ApplicationState {
|
||||||
sortPreferences: any;
|
sortPreferences: any;
|
||||||
share: any;
|
share: any;
|
||||||
customEmojis: any;
|
customEmojis: any;
|
||||||
activeUsers: ActiveUsers;
|
activeUsers: IActiveUsers;
|
||||||
usersTyping: any;
|
usersTyping: any;
|
||||||
inviteLinks: any;
|
inviteLinks: any;
|
||||||
createDiscussion: any;
|
createDiscussion: any;
|
||||||
|
@ -25,4 +28,4 @@ export interface ApplicationState {
|
||||||
roles: any;
|
roles: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ApplicationActions = SetActiveUsers;
|
export type ApplicationActions = IActionActiveUsers & IActionSelectedUsers;
|
||||||
|
|
Loading…
Reference in New Issue