import { AnyAction as Action } from "redux" ; import User from "../models/User" ; import { GET_ARTICLE_SUCCESS , GET_MORE_ARTICLE_SUCCESS } from "../actions/article" ; import { CONSENT_REQUEST_SUCCESS , AUTHENTICATE_SUCCESS , LOGIN_SUCCESS , UPDATE_PROFILE_SUCCESS } from "../actions/user" ; const initialState = { } ; const userDictionary = ( state = initialState , action ) : { [ id ] : User ; } => { switch ( action . type ) { case GET_ARTICLE_SUCCESS : case GET_MORE_ARTICLE_SUCCESS : return { ... state , ... action . authors } ; case CONSENT_REQUEST_SUCCESS : case AUTHENTICATE_SUCCESS : case LOGIN_SUCCESS : { if ( action . others ) { const cloneDic = { ... state } ; action . others . forEach ( ( other ) => { cloneDic [ other . _id ] = other ; } ) ; return cloneDic ; } else { return state ; } } case UPDATE_PROFILE_SUCCESS : { const cloneDic = { ... state } ; cloneDic [ ( action . user as User ) . _id ] = action . user ; return cloneDic ; } default : return state ; } } ; export default userDictionary ;