import { LikeAction , LikesActionTypes , LikesState , } from '../../types/redux/likes-reducer-types' ; const initialLikesState = { likesCount : 0 , isLoading : false , areLikesFetching : false , isLikePersisted : false , error : null , } ; function param { LikesState } state param { object } action returns { object } export const likesReducer = ( state = initialLikesState , action ) : LikesState => { switch ( action . type ) { case LikesActionTypes . LOAD_ALL_LIKES : return { ... state , areLikesFetching : true } ; case LikesActionTypes . LIKES_DID_LOAD : return { ... state , areLikesFetching : false , likesCount : action . payload } ; case LikesActionTypes . LIKES_LOAD_ERROR : return { ... state , areLikesFetching : false , error : action . payload } ; case LikesActionTypes . PERSIST_LIKE : return { ... state , isLoading : true } ; case LikesActionTypes . LIKE_WAS_PERSISTED : return { ... state , isLoading : false , isLikePersisted : action . payload } ; case LikesActionTypes . LIKE_PERSIST_ERROR : return { ... state , isLoading : false , error : action . payload } ; case LikesActionTypes . CLEAR_STATE : return { ... state , isLoading : false , isLikePersisted : false , error : null , } ; default : return state ; } } ;