Migrate actions,reducers and action types to TS #15
This commit is contained in:
107
app/reducers/global/GlobalState.ts
Normal file
107
app/reducers/global/GlobalState.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
|
||||
/**
|
||||
* Global state
|
||||
*
|
||||
* @export
|
||||
* @class GlobalState
|
||||
*/
|
||||
export class GlobalState {
|
||||
|
||||
/**
|
||||
* Set percent of loading progress and visibility for Master component
|
||||
*
|
||||
* @type {{
|
||||
* percent: number,
|
||||
* visible: Boolean
|
||||
* }}
|
||||
* @memberof IGlobalState
|
||||
*/
|
||||
progress: {
|
||||
percent: number;
|
||||
visible: Boolean;
|
||||
} = {
|
||||
percent : 0,
|
||||
visible : false
|
||||
}
|
||||
|
||||
/**
|
||||
* If loading is enabled {true} or not false
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof IGlobalState
|
||||
*/
|
||||
loadingStatus: Boolean = true;
|
||||
|
||||
/**
|
||||
* If user date is loaded {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof IGlobalState
|
||||
*/
|
||||
defaultLoadDataStatus: Boolean = false;
|
||||
|
||||
/**
|
||||
* If message popup is open {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof IGlobalState
|
||||
*/
|
||||
messageOpen: Boolean = false;
|
||||
|
||||
/**
|
||||
* The text of popup global message
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof IGlobalState
|
||||
*/
|
||||
message: string = '';
|
||||
|
||||
/**
|
||||
* Window size
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof IGlobalState
|
||||
*/
|
||||
windowWidth: number = 0;
|
||||
|
||||
/**
|
||||
* Window height
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof IGlobalState
|
||||
*/
|
||||
windowHeight: number = 0;
|
||||
|
||||
/**
|
||||
* The text of website header
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof IGlobalState
|
||||
*/
|
||||
headerTitle: string = '';
|
||||
|
||||
/**
|
||||
* Top loading is visible {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof IGlobalState
|
||||
*/
|
||||
showTopLoading: Boolean = false;
|
||||
|
||||
/**
|
||||
* Top loading message queue
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof IGlobalState
|
||||
*/
|
||||
topLoadingQueue: number = 0;
|
||||
|
||||
/**
|
||||
* Temp date storage
|
||||
*
|
||||
* @type {*}
|
||||
* @memberof IGlobalState
|
||||
*/
|
||||
temp: any = {};
|
||||
}
|
||||
|
||||
13
app/reducers/global/IGlobalAction.ts
Normal file
13
app/reducers/global/IGlobalAction.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { GlobalActionType } from 'constants/globalActionType';
|
||||
|
||||
/**
|
||||
* Global action interface
|
||||
*
|
||||
* @export
|
||||
* @interface IGlobalAction
|
||||
*/
|
||||
export interface IGlobalAction {
|
||||
payload: any,
|
||||
type: GlobalActionType
|
||||
|
||||
}
|
||||
101
app/reducers/global/globalReducer.ts
Normal file
101
app/reducers/global/globalReducer.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
// - Import action types
|
||||
import { GlobalActionType } from 'constants/globalActionType';
|
||||
|
||||
|
||||
import { GlobalState } from "./GlobalState";
|
||||
import { IGlobalAction } from "./IGlobalAction";
|
||||
|
||||
|
||||
/**
|
||||
* Global reducer
|
||||
* @param {object} state
|
||||
* @param {object} action
|
||||
*/
|
||||
export const globalReducer = (state: GlobalState = new GlobalState(), action: IGlobalAction) => {
|
||||
const { payload } = action
|
||||
switch (action.type) {
|
||||
case GlobalActionType.PROGRESS_CHANGE:
|
||||
return {
|
||||
...state,
|
||||
progress: {
|
||||
...state.progress,
|
||||
percent: payload.percent,
|
||||
visible: payload.visible
|
||||
}
|
||||
}
|
||||
case GlobalActionType.DEFAULT_DATA_DISABLE:
|
||||
return {
|
||||
...state,
|
||||
defaultLoadDataStatus: false
|
||||
}
|
||||
case GlobalActionType.DEFAULT_DATA_ENABLE:
|
||||
return {
|
||||
...state,
|
||||
defaultLoadDataStatus: true
|
||||
}
|
||||
case GlobalActionType.SHOW_ERROR_MESSAGE_GLOBAL:
|
||||
return {
|
||||
...state,
|
||||
message: action.payload,
|
||||
messageOpen: true
|
||||
}
|
||||
case GlobalActionType.SHOW_NORMAL_MESSAGE_GLOBAL:
|
||||
return {
|
||||
...state,
|
||||
message: action.payload,
|
||||
messageOpen: true
|
||||
}
|
||||
case GlobalActionType.SHOW_SEND_REQUEST_MESSAGE_GLOBAL:
|
||||
return {
|
||||
...state,
|
||||
message: "Request has been sent",
|
||||
messageOpen: true
|
||||
}
|
||||
case GlobalActionType.SHOW_REQUEST_SUCCESS_MESSAGE_GLOBAL:
|
||||
return {
|
||||
...state,
|
||||
message: "Your request has processed successfuly",
|
||||
messageOpen: true
|
||||
}
|
||||
case GlobalActionType.HIDE_MESSAGE_GLOBAL:
|
||||
return {
|
||||
...state,
|
||||
message: '',
|
||||
messageOpen: false,
|
||||
messageColor: ''
|
||||
}
|
||||
case GlobalActionType.SET_HEADER_TITLE:
|
||||
return {
|
||||
...state,
|
||||
headerTitle: action.payload
|
||||
}
|
||||
case GlobalActionType.HIDE_TOP_LOADING:
|
||||
const queue = state.topLoadingQueue > 0 ? (state.topLoadingQueue - 1) : 0
|
||||
return {
|
||||
...state,
|
||||
topLoadingQueue: queue,
|
||||
showTopLoading: (queue > 0 ? true : false)
|
||||
|
||||
}
|
||||
case GlobalActionType.SHOW_TOP_LOADING:
|
||||
return {
|
||||
...state,
|
||||
topLoadingQueue: (state.topLoadingQueue + 1),
|
||||
showTopLoading: true
|
||||
}
|
||||
case GlobalActionType.TEMP:
|
||||
return {
|
||||
...state,
|
||||
temp: {
|
||||
...state.temp,
|
||||
...payload
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return state
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
3
app/reducers/global/index.ts
Normal file
3
app/reducers/global/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { globalReducer } from "./globalReducer";
|
||||
|
||||
export {globalReducer};
|
||||
Reference in New Issue
Block a user