Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as actionTypes from '../actions/actionTypes';
- const initialState = {
- notFound: false,
- loadedUser: false,
- alertMessage: null,
- alertPreserve: false,
- isFetchingUsersInfo: false,
- isFetchingUserLogin: false,
- isFetchingUserLogout: false,
- isFetchingContent: false,
- isSendingData: false
- };
- export default function appState(state = initialState, action) {
- switch (action.type) {
- case actionTypes.NOT_FOUND_RENDER: {
- return {
- ...state,
- notFound: true,
- isFetchingContent: false,
- }
- }
- case actionTypes.NOT_FOUND_RESET: {
- return {
- ...state,
- notFound: initialState.notFound,
- }
- }
- case actionTypes.FETCH_USER_BASIC_INFO_REQUEST_TRIGGERED: {
- return {
- ...state,
- isFetchingUsersInfo: true,
- }
- }
- case actionTypes.FETCH_USER_BASIC_INFO_REQUEST_SUCCESS: {
- return {
- ...state,
- loadedUser: true,
- isFetchingUsersInfo: false,
- };
- }
- case actionTypes.FETCH_USER_BASIC_INFO_REQUEST_FAILURE: {
- return {
- ...state,
- isFetchingUsersInfo: false,
- };
- }
- // Fetch User Login
- case actionTypes.FETCH_USER_LOGIN_REQUEST_TRIGGERED: {
- return {
- ...state,
- isFetchingUserLogin: true,
- };
- }
- case actionTypes.FETCH_USER_LOGIN_REQUEST_SUCCESS:
- case actionTypes.FETCH_USER_LOGIN_REQUEST_FAILURE: {
- return {
- ...state,
- isFetchingContent: false,
- isFetchingUserLogin: initialState.isFetchingUserLogin,
- };
- }
- // Fetch User Logout
- case actionTypes.FETCH_USER_LOGOUT_REQUEST_TRIGGERED: {
- return {
- ...state,
- isFetchingUserLogout: true,
- };
- }
- case actionTypes.FETCH_USER_LOGOUT_REQUEST_SUCCESS:
- case actionTypes.FETCH_USER_LOGOUT_REQUEST_FAILURE: {
- return {
- ...state,
- isFetchingUserLogout: initialState.isFetchingUserLogout,
- };
- }
- // Fetch Content
- case actionTypes.FETCH_CONTENT_REQUEST_TRIGGERED: {
- return {
- ...state,
- isFetchingContent: true,
- isSendingData: false,
- };
- }
- case actionTypes.FETCH_CONTENT_REQUEST_FAILED: {
- return {
- ...state,
- isFetchingContent: initialState.isFetchingContent
- }
- }
- case actionTypes.FETCH_CONTENT_REQUEST_SUCCESS:
- case actionTypes.FETCH_FORUMS_LIST_REQUEST_SUCCESS:
- case actionTypes.FETCH_FORUM_REQUEST_SUCCESS:
- case actionTypes.FETCH_TOPIC_REQUEST_SUCCESS:
- case actionTypes.USER_RESET_PASSWORD_FETCHED:
- case actionTypes.USER_FETCHED_PROFILE: {
- return {
- ...state,
- isFetchingContent: initialState.isFetchingContent,
- };
- }
- case actionTypes.FORM_SUBMIT_TRIGGERED: {
- return {
- ...state,
- isSendingData: true
- }
- }
- case actionTypes.FORM_SUBMIT_FAILURE:
- case actionTypes.FORUM_POST_DESTROY:
- case actionTypes.FORUM_POST_UPDATE:
- case actionTypes.FORUM_CREATE_POST_SUCCESS:
- case actionTypes.USER_ADD_AVATAR:
- case actionTypes.USER_SIGN_UP:
- case actionTypes.USER_PROFILE_UPDATE: {
- return {
- ...state,
- isSendingData: false
- }
- }
- // Show error message
- case actionTypes.SHOW_ALERT_MESSAGE: {
- return {
- ...state,
- alertMessage: {
- isError: action.isError,
- message: action.message || action.error,
- errors: action.errors
- },
- };
- }
- // Reset alert message
- case actionTypes.RESET_ALERT_MESSAGE: {
- if (state.alertPreserve) {
- return {
- ...state,
- alertPreserve: false,
- }
- } else {
- return {
- ...state,
- alertMessage: initialState.alertMessage,
- };
- }
- }
- case actionTypes.CLOSE_ALERT_MESSAGE: {
- return {
- ...state,
- alertMessage: null,
- alertPreserve: false
- }
- }
- case actionTypes.ALERT_MESSAGE_PRESERVE: {
- return {
- ...state,
- alertPreserve: true
- }
- }
- default: {
- return state;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement