Files
astuto/app/javascript/reducers/commentReducer.ts
2019-09-26 16:03:41 +02:00

35 lines
754 B
TypeScript

import {
CommentRequestSuccessAction,
COMMENT_REQUEST_SUCCESS,
} from '../actions/requestComment';
import IComment from '../interfaces/IComment';
const initialState: IComment = {
id: 0,
body: '',
parentId: null,
userFullName: '<Unknown user>',
updatedAt: undefined,
};
const commentReducer = (
state = initialState,
action: CommentRequestSuccessAction,
): IComment => {
switch (action.type) {
case COMMENT_REQUEST_SUCCESS:
return {
id: action.comment.id,
body: action.comment.body,
parentId: action.comment.parent_id,
userFullName: action.comment.user_full_name,
updatedAt: action.comment.updated_at,
};
default:
return state;
}
}
export default commentReducer;