import { createReducer, on } from '@ngrx/store';
import { initialState } from './state';
import { fetchSuccess } from './actions';

export const reducer = createReducer(
  initialState,
  on(fetchSuccess, (state, action) => {
    return {
      ...state,
      profileImageRoot: action.profileRoot,
      profileImageUploadUrl: action.profileUploadUrl,
      fileUploadMaxSize:
        !!action.fileAllowSize &&
        !isNaN(action.fileAllowSize) &&
        0 < action.fileAllowSize
          ? action.fileAllowSize
          : 0,
      fileUploadUrl: action.uploadUrl,
      fileDownloadUrl: action.downloadUrl,
      serverIp: action.serverIp
    };
  })
);
