Migrate actions,reducers and action types to TS #15
This commit is contained in:
40
app/reducers/authorize/AuthorizeState.ts
Normal file
40
app/reducers/authorize/AuthorizeState.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Post state
|
||||
*
|
||||
* @export
|
||||
* @class AuthorizeState
|
||||
*/
|
||||
export class AuthorizeState {
|
||||
|
||||
/**
|
||||
* Authorized user identifier
|
||||
*
|
||||
* @type {number}
|
||||
* @memberof AuthorizeState
|
||||
*/
|
||||
uid: number = 0;
|
||||
|
||||
/**
|
||||
* If user is authed {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof AuthorizeState
|
||||
*/
|
||||
authed: Boolean = false;
|
||||
|
||||
/**
|
||||
* If user password is updated {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof AuthorizeState
|
||||
*/
|
||||
updatePassword: Boolean = false;
|
||||
|
||||
/**
|
||||
* If the user is guest {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof AuthorizeState
|
||||
*/
|
||||
guest: Boolean = false;
|
||||
}
|
||||
15
app/reducers/authorize/IAuthorizeAction.ts
Normal file
15
app/reducers/authorize/IAuthorizeAction.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
// - Import action types
|
||||
import {AuthorizeActionType} from 'constants/authorizeActionType'
|
||||
|
||||
|
||||
/**
|
||||
* Authorize action interface
|
||||
*
|
||||
* @export
|
||||
* @interface IAuthorizeAction
|
||||
*/
|
||||
export interface IAuthorizeAction {
|
||||
payload: any;
|
||||
type: AuthorizeActionType;
|
||||
|
||||
}
|
||||
50
app/reducers/authorize/authorizeReducer.ts
Normal file
50
app/reducers/authorize/authorizeReducer.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
// - Import react components
|
||||
import {Reducer, Action} from "redux";
|
||||
|
||||
// - Import action types
|
||||
import {AuthorizeActionType} from 'constants/authorizeActionType'
|
||||
|
||||
import { IAuthorizeAction } from "./IAuthorizeAction";
|
||||
import { AuthorizeState } from "./AuthorizeState";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Authorize reducer
|
||||
* @param {object} state
|
||||
* @param {object} action
|
||||
*/
|
||||
export var authorizeReducer = (state : AuthorizeState = new AuthorizeState(), action: IAuthorizeAction) =>{
|
||||
const { payload } = action;
|
||||
switch (action.type) {
|
||||
case AuthorizeActionType.LOGIN:
|
||||
return{
|
||||
...state,
|
||||
uid: payload.uid,
|
||||
authed: true,
|
||||
guest:false
|
||||
}
|
||||
case AuthorizeActionType.LOGOUT:
|
||||
return{
|
||||
...state,
|
||||
uid: 0,
|
||||
authed: false,
|
||||
guest:true
|
||||
}
|
||||
|
||||
case AuthorizeActionType.SIGNUP:
|
||||
return{
|
||||
...state,
|
||||
uid: payload.userId
|
||||
}
|
||||
case AuthorizeActionType.UPDATE_PASSWORD:
|
||||
return{
|
||||
...state,
|
||||
updatePassword: payload.updatePassword
|
||||
}
|
||||
default:
|
||||
return state
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
3
app/reducers/authorize/index.ts
Normal file
3
app/reducers/authorize/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { authorizeReducer } from "./authorizeReducer";
|
||||
|
||||
export {authorizeReducer};
|
||||
@@ -1,96 +0,0 @@
|
||||
// - Import react components
|
||||
import {Reducer, Action} from "redux";
|
||||
|
||||
// - Import action types
|
||||
import {AuthorizeActionType} from 'constants/authorizeActionType'
|
||||
|
||||
|
||||
/**
|
||||
* Default state
|
||||
*/
|
||||
var defaultState = {
|
||||
uid: 0,
|
||||
authed: false,
|
||||
updatePassword: false,
|
||||
guest:false
|
||||
}
|
||||
|
||||
/**
|
||||
* Default post state interface
|
||||
*
|
||||
* @export
|
||||
* @interface IAuthorizeState
|
||||
*/
|
||||
export interface IAuthorizeState {
|
||||
uid: number,
|
||||
authed: Boolean,
|
||||
updatePassword: Boolean,
|
||||
guest:Boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Default authorize action interface
|
||||
*
|
||||
* @export
|
||||
* @interface IAuthorizeAction
|
||||
*/
|
||||
export interface IAuthorizeAction {
|
||||
payload: any,
|
||||
type: AuthorizeActionType
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Default authorize reducer state
|
||||
*
|
||||
* @export
|
||||
* @class DefaultAuthorizeState
|
||||
* @implements {IAuthorizeState}
|
||||
*/
|
||||
export class DefaultAuthorizeState implements IAuthorizeState{
|
||||
uid: number = 0;
|
||||
authed: Boolean = false;
|
||||
updatePassword: Boolean = false;
|
||||
guest: Boolean = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorize reducer
|
||||
* @param {object} state
|
||||
* @param {object} action
|
||||
*/
|
||||
export var authorizeReducer = (state : IAuthorizeState = new DefaultAuthorizeState(), action: IAuthorizeAction) =>{
|
||||
const { payload } = action;
|
||||
switch (action.type) {
|
||||
case AuthorizeActionType.LOGIN:
|
||||
return{
|
||||
...state,
|
||||
uid: payload.uid,
|
||||
authed: true,
|
||||
guest:false
|
||||
}
|
||||
case AuthorizeActionType.LOGOUT:
|
||||
return{
|
||||
...state,
|
||||
uid: 0,
|
||||
authed: false,
|
||||
guest:true
|
||||
}
|
||||
|
||||
case AuthorizeActionType.SIGNUP:
|
||||
return{
|
||||
...state,
|
||||
uid: payload.userId
|
||||
}
|
||||
case AuthorizeActionType.UPDATE_PASSWORD:
|
||||
return{
|
||||
...state,
|
||||
updatePassword: payload.updatePassword
|
||||
}
|
||||
default:
|
||||
return state
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
26
app/reducers/circles/CircleState.ts
Normal file
26
app/reducers/circles/CircleState.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Circle } from "domain/circles";
|
||||
|
||||
/**
|
||||
* Circle state
|
||||
*
|
||||
* @export
|
||||
* @class CircleState
|
||||
*/
|
||||
export class CircleState {
|
||||
|
||||
/**
|
||||
* The list of Circles belong to users
|
||||
*
|
||||
* @type {({[userId: string]: {[circleId: string]: Circle}} | null)}
|
||||
* @memberof CircleState
|
||||
*/
|
||||
userCircles: {[userId: string]: {[circleId: string]: Circle}} = {};
|
||||
|
||||
/**
|
||||
* If user circles are loaded {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof CircleState
|
||||
*/
|
||||
loaded: Boolean = false;
|
||||
}
|
||||
14
app/reducers/circles/ICircleAction.ts
Normal file
14
app/reducers/circles/ICircleAction.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
import {CircleActionType} from 'constants/circleActionType'
|
||||
|
||||
/**
|
||||
* Circle action interface
|
||||
*
|
||||
* @export
|
||||
* @interface ICircleAction
|
||||
*/
|
||||
export interface ICircleAction {
|
||||
payload: any,
|
||||
type: CircleActionType
|
||||
|
||||
}
|
||||
@@ -1,66 +1,62 @@
|
||||
// - Import react components
|
||||
var uuid = require('uuid');
|
||||
import moment from 'moment'
|
||||
import _ from 'lodash'
|
||||
|
||||
// - Import domain
|
||||
import { User } from "domain/users";
|
||||
import { Circle } from "domain/circles";
|
||||
|
||||
// - Import action types
|
||||
import * as types from 'actionTypes'
|
||||
import {CircleActionType} from 'constants/circleActionType'
|
||||
|
||||
/* ---------------- */
|
||||
import { CircleState } from "./CircleState";
|
||||
import { ICircleAction } from "./ICircleAction";
|
||||
|
||||
|
||||
/**
|
||||
* Default State
|
||||
*/
|
||||
var defaultState = {
|
||||
userCircles: {},
|
||||
loaded: false
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Circle reducer
|
||||
* @param {object} state
|
||||
* @param {object} action
|
||||
* @param state
|
||||
* @param action
|
||||
*/
|
||||
export var circleReducer = (state = defaultState, action) => {
|
||||
export var circleReducer = (state: CircleState = new CircleState(), action: ICircleAction) => {
|
||||
const { payload } = action
|
||||
switch (action.type) {
|
||||
case types.CLEAR_ALL_CIRCLES:
|
||||
return defaultState
|
||||
case CircleActionType.CLEAR_ALL_CIRCLES:
|
||||
return new CircleState();
|
||||
|
||||
case types.ADD_CIRCLE:
|
||||
case CircleActionType.ADD_CIRCLE:
|
||||
return {
|
||||
...state,
|
||||
userCircles: {
|
||||
...state.userCircles,
|
||||
[payload.uid]: {
|
||||
...state.userCircles[payload.uid],
|
||||
[payload.circle.ownerId]: {
|
||||
...state.userCircles![payload.circle.ownerId],
|
||||
[payload.circle.id]: { ...payload.circle }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case types.UPDATE_CIRCLE:
|
||||
case CircleActionType.UPDATE_CIRCLE:
|
||||
return {
|
||||
...state,
|
||||
userCircles: {
|
||||
...state.userCircles,
|
||||
[payload.uid]: {
|
||||
...state.userCircles[payload.uid],
|
||||
...state.userCircles![payload.uid],
|
||||
[payload.circle.id]: {
|
||||
...state.userCircles[payload.uid][payload.circle.id],
|
||||
...state.userCircles![payload.uid][payload.circle.id],
|
||||
...payload.circle,
|
||||
openCircleSettings:false }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case types.DELETE_CIRCLE:
|
||||
case CircleActionType.DELETE_CIRCLE:
|
||||
let filteredCircles = {}
|
||||
Object.keys(state.userCircles[payload.uid]).map((key) => {
|
||||
Object.keys(state.userCircles![payload.uid]).map((key) => {
|
||||
if (key !== payload.id) {
|
||||
return _.merge(filteredCircles, { [key]: { ...state.userCircles[payload.uid][key] } })
|
||||
return _.merge(filteredCircles, { [key]: { ...state.userCircles![payload.uid][key] } })
|
||||
}
|
||||
})
|
||||
return {
|
||||
@@ -72,13 +68,13 @@ export var circleReducer = (state = defaultState, action) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
case types.ADD_LIST_CIRCLE:
|
||||
case CircleActionType.ADD_LIST_CIRCLE:
|
||||
return {
|
||||
...state,
|
||||
userCircles: {
|
||||
...state.userCircles,
|
||||
[payload.uid]: {
|
||||
...state.userCircles[payload.uid],
|
||||
...state.userCircles![payload.uid],
|
||||
...payload.circles
|
||||
}
|
||||
},
|
||||
@@ -86,17 +82,17 @@ export var circleReducer = (state = defaultState, action) => {
|
||||
|
||||
}
|
||||
|
||||
case types.ADD_FOLLOWING_USER:
|
||||
case CircleActionType.ADD_FOLLOWING_USER:
|
||||
return {
|
||||
...state,
|
||||
userCircles: {
|
||||
...state.userCircles,
|
||||
[payload.uid]: {
|
||||
...state.userCircles[payload.uid],
|
||||
...state.userCircles![payload.uid],
|
||||
[payload.cid]: {
|
||||
...state.userCircles[payload.uid][payload.cid],
|
||||
...state.userCircles![payload.uid][payload.cid],
|
||||
users:{
|
||||
...state.userCircles[payload.uid][payload.cid].users,
|
||||
...state.userCircles![payload.uid][payload.cid].users,
|
||||
[payload.followingId]: {
|
||||
...payload.userCircle
|
||||
}
|
||||
@@ -106,11 +102,11 @@ export var circleReducer = (state = defaultState, action) => {
|
||||
}
|
||||
}
|
||||
|
||||
case types.DELETE_FOLLOWING_USER:
|
||||
case CircleActionType.DELETE_FOLLOWING_USER:
|
||||
let filteredUserCircle = {}
|
||||
Object.keys(state.userCircles[payload.uid][payload.cid].users).map((key) => {
|
||||
Object.keys(state.userCircles![payload.uid][payload.cid].users).map((key) => {
|
||||
if (key !== payload.followingId) {
|
||||
return _.merge(filteredUserCircle, { [key]: { ...state.userCircles[payload.uid][payload.cid].users[key] } })
|
||||
return _.merge(filteredUserCircle, { [key]: { ...state.userCircles![payload.uid][payload.cid].users[key] } })
|
||||
}
|
||||
})
|
||||
return {
|
||||
@@ -118,9 +114,9 @@ export var circleReducer = (state = defaultState, action) => {
|
||||
userCircles: {
|
||||
...state.userCircles,
|
||||
[payload.uid]: {
|
||||
...state.userCircles[payload.uid],
|
||||
...state.userCircles![payload.uid],
|
||||
[payload.cid]: {
|
||||
...state.userCircles[payload.uid][payload.cid],
|
||||
...state.userCircles![payload.uid][payload.cid],
|
||||
users:{
|
||||
...filteredUserCircle
|
||||
}
|
||||
@@ -129,30 +125,30 @@ export var circleReducer = (state = defaultState, action) => {
|
||||
}
|
||||
}
|
||||
|
||||
case types.CLOSE_CIRCLE_SETTINGS:
|
||||
case CircleActionType.CLOSE_CIRCLE_SETTINGS:
|
||||
return {
|
||||
...state,
|
||||
userCircles: {
|
||||
...state.userCircles,
|
||||
[payload.uid]: {
|
||||
...state.userCircles[payload.uid],
|
||||
...state.userCircles![payload.uid],
|
||||
[payload.id]: {
|
||||
...state.userCircles[payload.uid][payload.id],
|
||||
...state.userCircles![payload.uid][payload.id],
|
||||
openCircleSettings: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case types.OPEN_CIRCLE_SETTINGS:
|
||||
case CircleActionType.OPEN_CIRCLE_SETTINGS:
|
||||
return {
|
||||
...state,
|
||||
userCircles: {
|
||||
...state.userCircles,
|
||||
[payload.uid]: {
|
||||
...state.userCircles[payload.uid],
|
||||
...state.userCircles![payload.uid],
|
||||
[payload.id]: {
|
||||
...state.userCircles[payload.uid][payload.id],
|
||||
...state.userCircles![payload.uid][payload.id],
|
||||
openCircleSettings: true
|
||||
}
|
||||
}
|
||||
3
app/reducers/circles/index.ts
Normal file
3
app/reducers/circles/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { circleReducer } from "./circleReducer";
|
||||
|
||||
export {circleReducer};
|
||||
27
app/reducers/comments/CommentState.ts
Normal file
27
app/reducers/comments/CommentState.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
import { Comment } from "domain/comments";
|
||||
|
||||
/**
|
||||
* Comment state
|
||||
*
|
||||
* @export
|
||||
* @class CommentState
|
||||
*/
|
||||
export class CommentState {
|
||||
|
||||
/**
|
||||
* The list of comments on the posts
|
||||
*
|
||||
* @type {({[postId: string]: {[commentId: string]: Comment}} | null)}
|
||||
* @memberof CommentState
|
||||
*/
|
||||
postComments: {[postId: string]: {[commentId: string]: Comment}} = {};
|
||||
|
||||
/**
|
||||
* If the comments are loaded {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof CommentState
|
||||
*/
|
||||
loaded: Boolean = false;
|
||||
}
|
||||
14
app/reducers/comments/ICommentAction.ts
Normal file
14
app/reducers/comments/ICommentAction.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
import {CommentActionType} from 'constants/commentActionType'
|
||||
|
||||
/**
|
||||
* Comment action interface
|
||||
*
|
||||
* @export
|
||||
* @interface ICommentAction
|
||||
*/
|
||||
export interface ICommentAction {
|
||||
payload: any;
|
||||
type: CommentActionType;
|
||||
|
||||
}
|
||||
@@ -2,38 +2,34 @@
|
||||
import moment from 'moment'
|
||||
import _ from 'lodash'
|
||||
|
||||
|
||||
// - Import domain
|
||||
import { User } from "domain/users";
|
||||
import { Comment } from "domain/comments";
|
||||
|
||||
// - Import action types
|
||||
import * as types from 'actionTypes'
|
||||
import {CommentActionType} from 'constants/commentActionType'
|
||||
|
||||
|
||||
import { CommentState } from "./CommentState";
|
||||
import { ICommentAction } from "./ICommentAction";
|
||||
|
||||
/**
|
||||
* Default state
|
||||
* Comment reducer
|
||||
* @param state
|
||||
* @param action
|
||||
*/
|
||||
var defaultState = {
|
||||
postComments: {},
|
||||
loaded:false
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Comment actions
|
||||
* @param {object} state
|
||||
* @param {object} action
|
||||
*/
|
||||
export var commentReducer = (state = defaultState, action) => {
|
||||
export var commentReducer = (state: CommentState = new CommentState(), action: ICommentAction) => {
|
||||
var { payload } = action
|
||||
switch (action.type) {
|
||||
|
||||
/* _____________ CRUD _____________ */
|
||||
case types.ADD_COMMENT:
|
||||
case CommentActionType.ADD_COMMENT:
|
||||
return {
|
||||
...state,
|
||||
postComments: {
|
||||
...state.postComments,
|
||||
[payload.postId]: {
|
||||
...state.postComments[payload.postId],
|
||||
...state.postComments![payload.postId],
|
||||
[payload.id]: {
|
||||
...payload.comment,
|
||||
editorStatus: false
|
||||
@@ -42,7 +38,7 @@ export var commentReducer = (state = defaultState, action) => {
|
||||
|
||||
}
|
||||
}
|
||||
case types.ADD_COMMENT_LIST:
|
||||
case CommentActionType.ADD_COMMENT_LIST:
|
||||
return {
|
||||
...state,
|
||||
postComments: {
|
||||
@@ -50,29 +46,29 @@ export var commentReducer = (state = defaultState, action) => {
|
||||
},
|
||||
loaded:true
|
||||
}
|
||||
case types.UPDATE_COMMENT:
|
||||
case CommentActionType.UPDATE_COMMENT:
|
||||
return {
|
||||
...state,
|
||||
postComments: {
|
||||
...state.postComments,
|
||||
[payload.postId]: {
|
||||
...state.postComments[payload.postId],
|
||||
...state.postComments![payload.postId],
|
||||
[payload.id]: {
|
||||
...state.postComments[payload.postId][payload.id],
|
||||
...state.postComments![payload.postId][payload.id],
|
||||
text: payload.text,
|
||||
editorStatus: payload.editorStatus
|
||||
editorStatus: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case types.DELETE_COMMENT:
|
||||
case CommentActionType.DELETE_COMMENT:
|
||||
var parsedComments = {}
|
||||
if (!state.postComments[payload.postId]) {
|
||||
if (!state.postComments![payload.postId]) {
|
||||
return state
|
||||
}
|
||||
Object.keys(state.postComments[payload.postId]).map((id) => {
|
||||
Object.keys(state.postComments![payload.postId]).map((id) => {
|
||||
if (id !== payload.id) {
|
||||
_.merge(parsedComments, { [id]: { ...state.postComments[payload.postId][id] } })
|
||||
_.merge(parsedComments, { [id]: { ...state.postComments![payload.postId][id] } })
|
||||
}
|
||||
|
||||
})
|
||||
@@ -85,37 +81,37 @@ export var commentReducer = (state = defaultState, action) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
case types.CLOSE_COMMENT_EDITOR:
|
||||
case CommentActionType.CLOSE_COMMENT_EDITOR:
|
||||
return {
|
||||
...state,
|
||||
postComments: {
|
||||
...state.postComments,
|
||||
[payload.postId]: {
|
||||
...state.postComments[payload.postId],
|
||||
...state.postComments![payload.postId],
|
||||
[payload.id]: {
|
||||
...state.postComments[payload.postId][payload.id],
|
||||
...state.postComments![payload.postId][payload.id],
|
||||
editorStatus: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case types.OPEN_COMMENT_EDITOR:
|
||||
case CommentActionType.OPEN_COMMENT_EDITOR:
|
||||
return {
|
||||
...state,
|
||||
postComments: {
|
||||
...state.postComments,
|
||||
[payload.postId]: {
|
||||
...state.postComments[payload.postId],
|
||||
...state.postComments![payload.postId],
|
||||
[payload.id]: {
|
||||
...state.postComments[payload.postId][payload.id],
|
||||
...state.postComments![payload.postId][payload.id],
|
||||
editorStatus: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case types.CLEAR_ALL_DATA_COMMENT:
|
||||
return defaultState
|
||||
case CommentActionType.CLEAR_ALL_DATA_COMMENT:
|
||||
return new CommentState();
|
||||
|
||||
|
||||
default:
|
||||
3
app/reducers/comments/index.ts
Normal file
3
app/reducers/comments/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { commentReducer } from "./commentReducer";
|
||||
|
||||
export {commentReducer};
|
||||
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
|
||||
|
||||
}
|
||||
@@ -1,35 +1,9 @@
|
||||
// - Import action types
|
||||
import * as types from 'actionTypes'
|
||||
import { GlobalActionType } from 'constants/globalActionType';
|
||||
|
||||
|
||||
/**
|
||||
* Default state
|
||||
*/
|
||||
var defaultState = {
|
||||
progress: {
|
||||
percent: 0,
|
||||
visible: false
|
||||
},
|
||||
loadingStatus: true,
|
||||
defaultLoadDataStatus: false,
|
||||
messageOpen: false,
|
||||
message: '',
|
||||
sidebarMainStyle: {},
|
||||
sidebarStyle: { width: "210px" },
|
||||
sidebarClass: "",
|
||||
sidebarOpen: (window.innerWidth > 750) ? true : false,
|
||||
windowWidth: 0,
|
||||
windowHeight: 0,
|
||||
overSidebarStatus: false,
|
||||
onResizeOpenSidebar: false,
|
||||
sidebarAuto: false,
|
||||
headerTitle: '',
|
||||
editProfileOpen: false,
|
||||
showTopLoading: false,
|
||||
topLoadingQueue: 0,
|
||||
temp: {}
|
||||
|
||||
}
|
||||
import { GlobalState } from "./GlobalState";
|
||||
import { IGlobalAction } from "./IGlobalAction";
|
||||
|
||||
|
||||
/**
|
||||
@@ -37,10 +11,10 @@ var defaultState = {
|
||||
* @param {object} state
|
||||
* @param {object} action
|
||||
*/
|
||||
export const globalReducer = (state = defaultState, action) => {
|
||||
export const globalReducer = (state: GlobalState = new GlobalState(), action: IGlobalAction) => {
|
||||
const { payload } = action
|
||||
switch (action.type) {
|
||||
case types.PROGRESS_CHANGE:
|
||||
case GlobalActionType.PROGRESS_CHANGE:
|
||||
return {
|
||||
...state,
|
||||
progress: {
|
||||
@@ -49,53 +23,53 @@ export const globalReducer = (state = defaultState, action) => {
|
||||
visible: payload.visible
|
||||
}
|
||||
}
|
||||
case types.DEFAULT_DATA_DISABLE:
|
||||
case GlobalActionType.DEFAULT_DATA_DISABLE:
|
||||
return {
|
||||
...state,
|
||||
defaultLoadDataStatus: false
|
||||
}
|
||||
case types.DEFAULT_DATA_ENABLE:
|
||||
case GlobalActionType.DEFAULT_DATA_ENABLE:
|
||||
return {
|
||||
...state,
|
||||
defaultLoadDataStatus: true
|
||||
}
|
||||
case types.SHOW_ERROR_MESSAGE_GLOBAL:
|
||||
case GlobalActionType.SHOW_ERROR_MESSAGE_GLOBAL:
|
||||
return {
|
||||
...state,
|
||||
message: action.payload,
|
||||
messageOpen: true
|
||||
}
|
||||
case types.SHOW_NORMAL_MESSAGE_GLOBAL:
|
||||
case GlobalActionType.SHOW_NORMAL_MESSAGE_GLOBAL:
|
||||
return {
|
||||
...state,
|
||||
message: action.payload,
|
||||
messageOpen: true
|
||||
}
|
||||
case types.SHOW_SEND_REQUEST_MESSAGE_GLOBAL:
|
||||
case GlobalActionType.SHOW_SEND_REQUEST_MESSAGE_GLOBAL:
|
||||
return {
|
||||
...state,
|
||||
message: "Request has been sent",
|
||||
messageOpen: true
|
||||
}
|
||||
case types.SHOW_REQUEST_SUCCESS_MESSAGE_GLOBAL:
|
||||
case GlobalActionType.SHOW_REQUEST_SUCCESS_MESSAGE_GLOBAL:
|
||||
return {
|
||||
...state,
|
||||
message: "Your request has processed successfuly",
|
||||
messageOpen: true
|
||||
}
|
||||
case types.HIDE_MESSAGE_GLOBAL:
|
||||
case GlobalActionType.HIDE_MESSAGE_GLOBAL:
|
||||
return {
|
||||
...state,
|
||||
message: '',
|
||||
messageOpen: false,
|
||||
messageColor: ''
|
||||
}
|
||||
case types.SET_HEADER_TITLE:
|
||||
case GlobalActionType.SET_HEADER_TITLE:
|
||||
return {
|
||||
...state,
|
||||
headerTitle: action.payload
|
||||
}
|
||||
case types.HIDE_TOP_LOADING:
|
||||
case GlobalActionType.HIDE_TOP_LOADING:
|
||||
const queue = state.topLoadingQueue > 0 ? (state.topLoadingQueue - 1) : 0
|
||||
return {
|
||||
...state,
|
||||
@@ -103,13 +77,13 @@ export const globalReducer = (state = defaultState, action) => {
|
||||
showTopLoading: (queue > 0 ? true : false)
|
||||
|
||||
}
|
||||
case types.SHOW_TOP_LOADING:
|
||||
case GlobalActionType.SHOW_TOP_LOADING:
|
||||
return {
|
||||
...state,
|
||||
topLoadingQueue: (state.topLoadingQueue + 1),
|
||||
showTopLoading: true
|
||||
}
|
||||
case types.TEMP:
|
||||
case GlobalActionType.TEMP:
|
||||
return {
|
||||
...state,
|
||||
temp: {
|
||||
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};
|
||||
13
app/reducers/imageGallery/IImageGalleryAction.ts
Normal file
13
app/reducers/imageGallery/IImageGalleryAction.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import {ImageGalleryActionType} from 'constants/imageGalleryActionType'
|
||||
|
||||
/**
|
||||
* ImageGallery action interface
|
||||
*
|
||||
* @export
|
||||
* @interface IImageGalleryAction
|
||||
*/
|
||||
export interface IImageGalleryAction {
|
||||
payload: any,
|
||||
type: ImageGalleryActionType
|
||||
|
||||
}
|
||||
67
app/reducers/imageGallery/ImageGalleryState.ts
Normal file
67
app/reducers/imageGallery/ImageGalleryState.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { Image } from "domain/imageGallery";
|
||||
|
||||
/**
|
||||
* ImageGallery state
|
||||
*
|
||||
* @export
|
||||
* @class ImageGalleryState
|
||||
*/
|
||||
export class ImageGalleryState {
|
||||
|
||||
/**
|
||||
* Image gallery is open {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
status: Boolean = false;
|
||||
|
||||
/**
|
||||
* The list of image
|
||||
*
|
||||
* @type {(Image[] | null)}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
images: Image[] = [];
|
||||
|
||||
/**
|
||||
* Selected image name
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
selectImage: string = '';
|
||||
|
||||
/**
|
||||
* Selected image address
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
selectURL: string = '';
|
||||
|
||||
/**
|
||||
* If image gallery is loaded {true} or not false
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
loaded: Boolean = false;
|
||||
|
||||
/**
|
||||
* Images address list
|
||||
*
|
||||
* @type {*}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
imageURLList: any = {};
|
||||
|
||||
/**
|
||||
* Store image requested
|
||||
*
|
||||
* @type {*}
|
||||
* @memberof ImageGalleryState
|
||||
*/
|
||||
imageRequests: any = {};
|
||||
|
||||
}
|
||||
71
app/reducers/imageGallery/imageGalleryReducer.ts
Normal file
71
app/reducers/imageGallery/imageGalleryReducer.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
// - Import react components
|
||||
import _ from 'lodash'
|
||||
|
||||
// - Import domain
|
||||
import { User } from "domain/users";
|
||||
import { Image } from "domain/imageGallery";
|
||||
|
||||
// - Import image gallery action types
|
||||
import {ImageGalleryActionType} from 'constants/imageGalleryActionType'
|
||||
|
||||
|
||||
import { IImageGalleryAction } from "./IImageGalleryAction";
|
||||
import { ImageGalleryState } from "./ImageGalleryState";
|
||||
|
||||
|
||||
/**
|
||||
* Image gallery reducer
|
||||
*/
|
||||
export var imageGalleryReducer = (state: ImageGalleryState = new ImageGalleryState(), action: IImageGalleryAction) => {
|
||||
const { payload } = action
|
||||
|
||||
switch (action.type) {
|
||||
/* ----------------- CRUD ----------------- */
|
||||
case ImageGalleryActionType.ADD_IMAGE_GALLERY:
|
||||
return {
|
||||
...state,
|
||||
images: [...state.images!, payload.image]
|
||||
}
|
||||
case ImageGalleryActionType.ADD_IMAGE_LIST_GALLERY:
|
||||
return {
|
||||
...state,
|
||||
images: [...payload],
|
||||
loaded: true
|
||||
}
|
||||
|
||||
case ImageGalleryActionType.DELETE_IMAGE:
|
||||
return {
|
||||
...state,
|
||||
images: [
|
||||
...state.images!.filter((item: Image) => {
|
||||
return item.id !== payload.id
|
||||
})
|
||||
]
|
||||
}
|
||||
case ImageGalleryActionType.SET_IMAGE_URL:
|
||||
return {
|
||||
...state,
|
||||
imageURLList: {
|
||||
...state.imageURLList,
|
||||
[payload.name]: payload.url
|
||||
}
|
||||
}
|
||||
|
||||
case ImageGalleryActionType.SEND_IMAGE_REQUEST:
|
||||
return {
|
||||
...state,
|
||||
imageRequests: [
|
||||
...state.imageRequests,
|
||||
payload
|
||||
]
|
||||
}
|
||||
|
||||
case ImageGalleryActionType.CLEAT_ALL_DATA_IMAGE_GALLERY:
|
||||
return new ImageGalleryState()
|
||||
|
||||
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
3
app/reducers/imageGallery/index.ts
Normal file
3
app/reducers/imageGallery/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { imageGalleryReducer } from "./imageGalleryReducer";
|
||||
|
||||
export {imageGalleryReducer};
|
||||
@@ -1,95 +0,0 @@
|
||||
// - Import react components
|
||||
import _ from 'lodash'
|
||||
|
||||
|
||||
// - Import image gallery action types
|
||||
import * as types from 'actionTypes'
|
||||
|
||||
/**
|
||||
* Default state for reducer
|
||||
*/
|
||||
var defaultState = {
|
||||
status: false,
|
||||
images: [],
|
||||
selectImage: '',
|
||||
selectURL: '',
|
||||
loaded: false,
|
||||
imageURLList: {},
|
||||
imageRequests: []
|
||||
}
|
||||
|
||||
/**
|
||||
* Image gallery reducer
|
||||
*/
|
||||
export var imageGalleryReducer = (state = defaultState, action) => {
|
||||
const { payload } = action
|
||||
|
||||
switch (action.type) {
|
||||
case types.OPEN_IMAGE_GALLERY:
|
||||
return {
|
||||
...state,
|
||||
status: action.status
|
||||
}
|
||||
/* ----------------- CRUD ----------------- */
|
||||
case types.ADD_IMAGE_GALLERY:
|
||||
return {
|
||||
...state,
|
||||
images: [...state.images, action.image]
|
||||
}
|
||||
case types.ADD_IMAGE_LIST_GALLERY:
|
||||
{
|
||||
return {
|
||||
...state,
|
||||
images: [...action.images],
|
||||
loaded: true
|
||||
}
|
||||
}
|
||||
case types.DELETE_IMAGE:
|
||||
return {
|
||||
...state,
|
||||
images: [
|
||||
...state.images.filter((item) => {
|
||||
return item.id !== action.id
|
||||
})
|
||||
]
|
||||
}
|
||||
|
||||
case types.IMAGE_SELECT_GALLERY:
|
||||
return {
|
||||
...state,
|
||||
selectImage: action.image,
|
||||
selectURL: action.URL
|
||||
}
|
||||
case types.CLEARS_SELECT_IMAGE_GALLERY:
|
||||
return {
|
||||
...state,
|
||||
selectImage: '',
|
||||
selectURL: ''
|
||||
}
|
||||
case types.SET_IMAGE_URL:
|
||||
return {
|
||||
...state,
|
||||
imageURLList: {
|
||||
...state.imageURLList,
|
||||
[payload.name]: payload.url
|
||||
}
|
||||
}
|
||||
|
||||
case types.SEND_IMAGE_REQUEST:
|
||||
return {
|
||||
...state,
|
||||
imageRequests: [
|
||||
...state.imageRequests,
|
||||
payload
|
||||
]
|
||||
}
|
||||
|
||||
case types.CLEAT_ALL_DATA_IMAGE_GALLERY:
|
||||
return defaultState
|
||||
|
||||
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
21
app/reducers/index.ts
Normal file
21
app/reducers/index.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { authorizeReducer } from "./authorize";
|
||||
import { circleReducer } from "./circles";
|
||||
import { commentReducer } from "./comments";
|
||||
import { globalReducer } from "./global";
|
||||
import { imageGalleryReducer } from "./imageGallery";
|
||||
import { notificationReducer } from "./notifications";
|
||||
import { postReducer } from "./posts";
|
||||
import { userReducer } from "./users";
|
||||
import { voteReducer } from "./votes";
|
||||
|
||||
export{
|
||||
authorizeReducer,
|
||||
circleReducer,
|
||||
commentReducer,
|
||||
globalReducer,
|
||||
imageGalleryReducer,
|
||||
notificationReducer,
|
||||
postReducer,
|
||||
userReducer,
|
||||
voteReducer
|
||||
}
|
||||
14
app/reducers/notifications/INotificationAction.ts
Normal file
14
app/reducers/notifications/INotificationAction.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import {NotificationActionType} from 'constants/notificationActionType'
|
||||
|
||||
/**
|
||||
* Notification action interface
|
||||
*
|
||||
* @export
|
||||
* @interface INotificationAction
|
||||
*/
|
||||
export interface INotificationAction {
|
||||
payload: any,
|
||||
type: NotificationActionType
|
||||
|
||||
}
|
||||
|
||||
26
app/reducers/notifications/NotificationState.ts
Normal file
26
app/reducers/notifications/NotificationState.ts
Normal 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;
|
||||
}
|
||||
3
app/reducers/notifications/index.ts
Normal file
3
app/reducers/notifications/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { notificationReducer } from "./notificationReducer";
|
||||
|
||||
export {notificationReducer};
|
||||
@@ -2,19 +2,14 @@
|
||||
import moment from 'moment'
|
||||
import _ from 'lodash'
|
||||
|
||||
|
||||
// - Import domain
|
||||
import { Notification } from "domain/notifications";
|
||||
|
||||
// - Import action types
|
||||
import * as types from 'actionTypes'
|
||||
import {NotificationActionType} from 'constants/notificationActionType'
|
||||
|
||||
|
||||
/**
|
||||
* Default state
|
||||
*/
|
||||
var defaultState = {
|
||||
userNotifies: {},
|
||||
loaded:false
|
||||
}
|
||||
import { NotificationState } from "./NotificationState";
|
||||
import { INotificationAction } from "./INotificationAction";
|
||||
|
||||
|
||||
/**
|
||||
@@ -22,15 +17,15 @@ var defaultState = {
|
||||
* @param {object} state
|
||||
* @param {object} action
|
||||
*/
|
||||
export var notifyReducer = (state = defaultState, action) => {
|
||||
export var notificationReducer = (state: NotificationState = new NotificationState(), action: INotificationAction) => {
|
||||
var { payload } = action
|
||||
switch (action.type) {
|
||||
|
||||
/* _____________ CRUD _____________ */
|
||||
case types.ADD_NOTIFY:
|
||||
case NotificationActionType.ADD_NOTIFY:
|
||||
return state
|
||||
|
||||
case types.ADD_NOTIFY_LIST:
|
||||
case NotificationActionType.ADD_NOTIFY_LIST:
|
||||
return {
|
||||
...state,
|
||||
userNotifies: {
|
||||
@@ -39,24 +34,24 @@ export var notifyReducer = (state = defaultState, action) => {
|
||||
loaded:true
|
||||
}
|
||||
|
||||
case types.SEEN_NOTIFY:
|
||||
case NotificationActionType.SEEN_NOTIFY:
|
||||
return {
|
||||
...state,
|
||||
userNotifies: {
|
||||
...state.userNotifies,
|
||||
[payload]:{
|
||||
...state.userNotifies[payload],
|
||||
...state.userNotifies![payload],
|
||||
isSeen:true
|
||||
}
|
||||
},
|
||||
loaded:true
|
||||
}
|
||||
|
||||
case types.DELETE_NOTIFY:
|
||||
case NotificationActionType.DELETE_NOTIFY:
|
||||
var parsedNotifies = {}
|
||||
Object.keys(state.userNotifies).map((id) => {
|
||||
Object.keys(state.userNotifies!).map((id) => {
|
||||
if (id !== payload) {
|
||||
_.merge(parsedNotifies, { [id]: { ...state.userNotifies[id] } })
|
||||
_.merge(parsedNotifies, { [id]: { ...state.userNotifies![id] } })
|
||||
}
|
||||
|
||||
})
|
||||
@@ -68,8 +63,8 @@ export var notifyReducer = (state = defaultState, action) => {
|
||||
}
|
||||
|
||||
|
||||
case types.CLEAR_ALL_DATA_NOTIFY:
|
||||
return defaultState
|
||||
case NotificationActionType.CLEAR_ALL_DATA_NOTIFY:
|
||||
return new NotificationState()
|
||||
|
||||
|
||||
default:
|
||||
13
app/reducers/posts/IPostAction.ts
Normal file
13
app/reducers/posts/IPostAction.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { PostActionType } from "constants/postActionType";
|
||||
|
||||
/**
|
||||
* Post action interface
|
||||
*
|
||||
* @export
|
||||
* @interface IPostAction
|
||||
*/
|
||||
export interface IPostAction {
|
||||
payload: any,
|
||||
type: PostActionType
|
||||
|
||||
}
|
||||
25
app/reducers/posts/PostState.ts
Normal file
25
app/reducers/posts/PostState.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
/**
|
||||
* Post state
|
||||
*
|
||||
* @export
|
||||
* @class PostState
|
||||
*/
|
||||
export class PostState {
|
||||
|
||||
/**
|
||||
* The list of user posts
|
||||
*
|
||||
* @type {*}
|
||||
* @memberof PostState
|
||||
*/
|
||||
userPosts: any = {};
|
||||
|
||||
/**
|
||||
* If user posts are loaded {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof PostState
|
||||
*/
|
||||
loaded: Boolean = false;
|
||||
}
|
||||
3
app/reducers/posts/index.ts
Normal file
3
app/reducers/posts/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { postReducer } from "./postReducer";
|
||||
|
||||
export {postReducer};
|
||||
@@ -1,5 +1,4 @@
|
||||
// - Import react components
|
||||
var uuid = require('uuid');
|
||||
import moment from 'moment'
|
||||
import _ from 'lodash'
|
||||
import {Reducer, Action} from "redux";
|
||||
@@ -8,57 +7,21 @@ import {Reducer, Action} from "redux";
|
||||
// - Import action types
|
||||
import { PostActionType } from "constants/postActionType";
|
||||
|
||||
/* ---------------- */
|
||||
|
||||
import { PostState } from "./PostState";
|
||||
import { IPostAction } from "./IPostAction";
|
||||
|
||||
// - Import react components
|
||||
|
||||
/**
|
||||
* Default post state
|
||||
*
|
||||
* @export
|
||||
* @interface IPostState
|
||||
*/
|
||||
export interface IPostState {
|
||||
userPosts: any,
|
||||
loaded: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @export
|
||||
* @interface IPostAction
|
||||
*/
|
||||
export interface IPostAction {
|
||||
payload: any,
|
||||
type: PostActionType
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Default post reducer state
|
||||
*
|
||||
* @export
|
||||
* @class DefaultPostState
|
||||
* @implements {IPostState}
|
||||
*/
|
||||
export class DefaultPostState implements IPostState{
|
||||
userPosts: any = {};
|
||||
loaded: boolean = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Post reducer
|
||||
* @param {object} state
|
||||
* @param {object} action
|
||||
*/
|
||||
export var postReducer = (state : IPostState = new DefaultPostState(), action : IPostAction) => {
|
||||
export var postReducer = (state : PostState = new PostState(), action : IPostAction) => {
|
||||
const { payload } = action;
|
||||
switch (action.type) {
|
||||
case PostActionType.CLEAR_ALL_DATA_POST:
|
||||
return new DefaultPostState()
|
||||
return new PostState()
|
||||
|
||||
case PostActionType.ADD_IMAGE_POST:
|
||||
return {
|
||||
13
app/reducers/users/IUserAction.ts
Normal file
13
app/reducers/users/IUserAction.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import {UserActionType} from 'constants/userActionType'
|
||||
|
||||
/**
|
||||
* User action interface
|
||||
*
|
||||
* @export
|
||||
* @interface IUserAction
|
||||
*/
|
||||
export interface IUserAction {
|
||||
payload: any,
|
||||
type: UserActionType
|
||||
|
||||
}
|
||||
33
app/reducers/users/UserState.ts
Normal file
33
app/reducers/users/UserState.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { User,Profile } from "domain/users";
|
||||
|
||||
/**
|
||||
* User state
|
||||
*
|
||||
* @export
|
||||
* @class UserState
|
||||
*/
|
||||
export class UserState {
|
||||
/**
|
||||
* The list of users information
|
||||
*
|
||||
* @type {({[userId: string]: Profile} | null)}
|
||||
* @memberof UserState
|
||||
*/
|
||||
info: {[userId: string]: Profile} = {};
|
||||
|
||||
/**
|
||||
* If users profile are loaded
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof UserState
|
||||
*/
|
||||
loaded: Boolean = false;
|
||||
|
||||
/**
|
||||
* If edit profile is open {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof UserState
|
||||
*/
|
||||
openEditProfile: Boolean = false;
|
||||
}
|
||||
3
app/reducers/users/index.ts
Normal file
3
app/reducers/users/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { userReducer } from "./userReducer";
|
||||
|
||||
export {userReducer};
|
||||
@@ -1,22 +1,19 @@
|
||||
// - Import action types
|
||||
import * as types from 'actionTypes'
|
||||
import {UserActionType} from 'constants/userActionType'
|
||||
|
||||
/**
|
||||
* Default state for reducer
|
||||
*/
|
||||
var defaultState = {
|
||||
info: {},
|
||||
loaded: false,
|
||||
openEditProfile: false
|
||||
}
|
||||
// - Import domain
|
||||
import { User,Profile } from "domain/users";
|
||||
|
||||
import { UserState } from "./UserState";
|
||||
import { IUserAction } from "./IUserAction";
|
||||
|
||||
/**
|
||||
* User reducer
|
||||
*/
|
||||
export var userReducer = (state = defaultState, action) => {
|
||||
export var userReducer = (state: UserState = new UserState(), action: IUserAction) => {
|
||||
const { payload } = action
|
||||
switch (action.type) {
|
||||
case types.USER_INFO:
|
||||
case UserActionType.USER_INFO:
|
||||
return {
|
||||
...state,
|
||||
info: {
|
||||
@@ -26,7 +23,7 @@ export var userReducer = (state = defaultState, action) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
case types.ADD_USER_INFO:
|
||||
case UserActionType.ADD_USER_INFO:
|
||||
return {
|
||||
...state,
|
||||
info: {
|
||||
@@ -37,7 +34,7 @@ export var userReducer = (state = defaultState, action) => {
|
||||
},
|
||||
loaded: true
|
||||
}
|
||||
case types.ADD_PEOPLE_INFO:
|
||||
case UserActionType.ADD_PEOPLE_INFO:
|
||||
return {
|
||||
...state,
|
||||
info: {
|
||||
@@ -46,29 +43,29 @@ export var userReducer = (state = defaultState, action) => {
|
||||
}
|
||||
}
|
||||
|
||||
case types.UPDATE_USER_INFO:
|
||||
case UserActionType.UPDATE_USER_INFO:
|
||||
return {
|
||||
...state,
|
||||
info: {
|
||||
...state.info,
|
||||
[payload.uid]: {
|
||||
...state.info[payload.uid],
|
||||
...state.info![payload.uid],
|
||||
...payload.info
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
case types.CLEAR_ALL_DATA_USER:
|
||||
return defaultState
|
||||
case UserActionType.CLEAR_ALL_DATA_USER:
|
||||
return new UserState();
|
||||
|
||||
case types.CLOSE_EDIT_PROFILE:
|
||||
case UserActionType.CLOSE_EDIT_PROFILE:
|
||||
return {
|
||||
...state,
|
||||
openEditProfile: false
|
||||
}
|
||||
|
||||
case types.OPEN_EDIT_PROFILE:
|
||||
case UserActionType.OPEN_EDIT_PROFILE:
|
||||
return {
|
||||
...state,
|
||||
openEditProfile: true
|
||||
14
app/reducers/votes/IVoteAction.ts
Normal file
14
app/reducers/votes/IVoteAction.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import {VoteActionType} from 'constants/voteActionType'
|
||||
|
||||
|
||||
/**
|
||||
* Vote action interface
|
||||
*
|
||||
* @export
|
||||
* @interface IVoteAction
|
||||
*/
|
||||
export interface IVoteAction {
|
||||
payload: any,
|
||||
type: VoteActionType
|
||||
|
||||
}
|
||||
26
app/reducers/votes/VoteState.ts
Normal file
26
app/reducers/votes/VoteState.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Vote } from "domain/votes";
|
||||
|
||||
/**
|
||||
* Vote state
|
||||
*
|
||||
* @export
|
||||
* @class VoteState
|
||||
*/
|
||||
export class VoteState {
|
||||
|
||||
/**
|
||||
* The list of posts vote
|
||||
*
|
||||
* @type {({[postId: string]: {[voteId: string]: Vote}} | null)}
|
||||
* @memberof VoteState
|
||||
*/
|
||||
postVotes: {[postId: string]: {[voteId: string]: Vote}} | null = null;
|
||||
|
||||
/**
|
||||
* If posts vote are loaded {true} or not {false}
|
||||
*
|
||||
* @type {Boolean}
|
||||
* @memberof VoteState
|
||||
*/
|
||||
loaded: Boolean = false;
|
||||
}
|
||||
3
app/reducers/votes/index.ts
Normal file
3
app/reducers/votes/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { voteReducer } from "./voteReducer";
|
||||
|
||||
export {voteReducer};
|
||||
@@ -2,19 +2,15 @@
|
||||
import moment from 'moment'
|
||||
import _ from 'lodash'
|
||||
|
||||
|
||||
|
||||
// - Import action types
|
||||
import * as types from 'actionTypes'
|
||||
import {VoteActionType} from 'constants/voteActionType'
|
||||
|
||||
// Import domain
|
||||
import { Vote } from "domain/votes";
|
||||
|
||||
|
||||
/**
|
||||
* Default state
|
||||
*/
|
||||
var defaultState = {
|
||||
postVotes: {},
|
||||
loaded:false
|
||||
}
|
||||
import { VoteState } from "./VoteState";
|
||||
import { IVoteAction } from "./IVoteAction";
|
||||
|
||||
|
||||
/**
|
||||
@@ -22,26 +18,26 @@ var defaultState = {
|
||||
* @param {object} state
|
||||
* @param {object} action
|
||||
*/
|
||||
export var voteReducer = (state = defaultState, action) => {
|
||||
export var voteReducer = (state: VoteState = new VoteState(), action: IVoteAction) => {
|
||||
var { payload } = action
|
||||
switch (action.type) {
|
||||
|
||||
/* _____________ CRUD _____________ */
|
||||
case types.ADD_VOTE:
|
||||
case VoteActionType.ADD_VOTE:
|
||||
return {
|
||||
...state,
|
||||
postVotes: {
|
||||
...state.postVotes,
|
||||
[payload.postId]: {
|
||||
...state.postVotes[payload.postId],
|
||||
...state.postVotes![payload.postId],
|
||||
[payload.id]: {
|
||||
...payload.vote
|
||||
...payload
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
case types.ADD_VOTE_LIST:
|
||||
case VoteActionType.ADD_VOTE_LIST:
|
||||
return {
|
||||
...state,
|
||||
postVotes: {
|
||||
@@ -50,12 +46,12 @@ export var voteReducer = (state = defaultState, action) => {
|
||||
loaded:true
|
||||
}
|
||||
|
||||
case types.DELETE_VOTE:
|
||||
case VoteActionType.DELETE_VOTE:
|
||||
var parsedVotes = {}
|
||||
if (state.postVotes[payload.postId])
|
||||
Object.keys(state.postVotes[payload.postId]).map((id) => {
|
||||
if (state.postVotes![payload.postId])
|
||||
Object.keys(state.postVotes![payload.postId]).map((id) => {
|
||||
if (id !== payload.id) {
|
||||
_.merge(parsedVotes, { [id]: { ...state.postVotes[payload.postId][id] } })
|
||||
_.merge(parsedVotes, { [id]: { ...state.postVotes![payload.postId][id] } })
|
||||
}
|
||||
|
||||
})
|
||||
@@ -70,8 +66,8 @@ export var voteReducer = (state = defaultState, action) => {
|
||||
}
|
||||
|
||||
|
||||
case types.CLEAR_ALL_DATA_VOTE:
|
||||
return defaultState
|
||||
case VoteActionType.CLEAR_ALL_DATA_VOTE:
|
||||
return new VoteState();
|
||||
|
||||
|
||||
default:
|
||||
Reference in New Issue
Block a user