Migrate actions,reducers and action types to TS #15

This commit is contained in:
Qolzam
2017-10-10 08:01:25 +07:00
parent 3b3899e7af
commit f9d213f741
113 changed files with 2692 additions and 1275 deletions

View File

@@ -0,0 +1,14 @@
import {NotificationActionType} from 'constants/notificationActionType'
/**
* Notification action interface
*
* @export
* @interface INotificationAction
*/
export interface INotificationAction {
payload: any,
type: NotificationActionType
}

View File

@@ -0,0 +1,26 @@
import { Notification } from "domain/notifications";
/**
* Notification state
*
* @export
* @class NotificationState
*/
export class NotificationState {
/**
* The list of users notification
*
* @type {({[userId: string]: {[notificationId: string]: Notification}} | null)}
* @memberof NotificationState
*/
userNotifies: {[userId: string]: {[notificationId: string]: Notification}} = {};
/**
* If user notifications are loaded {true} or not {false}
*
* @type {Boolean}
* @memberof NotificationState
*/
loaded: Boolean = false;
}

View File

@@ -0,0 +1,3 @@
import { notificationReducer } from "./notificationReducer";
export {notificationReducer};

View File

@@ -0,0 +1,76 @@
// - Import react components
import moment from 'moment'
import _ from 'lodash'
// - Import domain
import { Notification } from "domain/notifications";
// - Import action types
import {NotificationActionType} from 'constants/notificationActionType'
import { NotificationState } from "./NotificationState";
import { INotificationAction } from "./INotificationAction";
/**
* Notify actions
* @param {object} state
* @param {object} action
*/
export var notificationReducer = (state: NotificationState = new NotificationState(), action: INotificationAction) => {
var { payload } = action
switch (action.type) {
/* _____________ CRUD _____________ */
case NotificationActionType.ADD_NOTIFY:
return state
case NotificationActionType.ADD_NOTIFY_LIST:
return {
...state,
userNotifies: {
...payload
},
loaded:true
}
case NotificationActionType.SEEN_NOTIFY:
return {
...state,
userNotifies: {
...state.userNotifies,
[payload]:{
...state.userNotifies![payload],
isSeen:true
}
},
loaded:true
}
case NotificationActionType.DELETE_NOTIFY:
var parsedNotifies = {}
Object.keys(state.userNotifies!).map((id) => {
if (id !== payload) {
_.merge(parsedNotifies, { [id]: { ...state.userNotifies![id] } })
}
})
return {
...state,
userNotifies: {
...parsedNotifies
}
}
case NotificationActionType.CLEAR_ALL_DATA_NOTIFY:
return new NotificationState()
default:
return state;
}
}