CS307-Team24/twistter-frontend/redux/reducers/userReducer.js
2019-10-30 18:31:55 -04:00

31 lines
794 B
JavaScript

import { LIKE_POST, UNLIKE_POST} from '../types';
const initialState = {
likes: [],
credentials: {}
}
export default function(state = initialState, action) {
switch (action.type) {
case LIKE_POST:
return {
...state,
likes: [
...state.likes,
{
userHandle: state.credentials.handle,
postId: action.payload.postId
}
]
}
case UNLIKE_POST:
return {
...state,
likes: state.likes.filter(
(like) => like.postId === action.payload.postId
)
};
default:
return state;
}
}