Files
astuto/app/javascript/reducers/commentReducer.ts

39 lines
920 B
TypeScript
Raw Normal View History

import {
2019-09-26 16:03:41 +02:00
CommentRequestSuccessAction,
COMMENT_REQUEST_SUCCESS,
2022-05-07 11:27:07 +02:00
} from '../actions/Comment/requestComment';
import IComment from '../interfaces/IComment';
const initialState: IComment = {
id: 0,
body: '',
2019-09-17 17:04:19 +02:00
parentId: null,
2019-10-01 19:15:03 +02:00
isPostUpdate: false,
2019-09-17 17:04:19 +02:00
userFullName: '<Unknown user>',
2019-09-30 23:28:52 +02:00
userEmail: 'example@example.com',
2019-09-17 17:04:19 +02:00
updatedAt: undefined,
};
const commentReducer = (
state = initialState,
2019-09-26 16:03:41 +02:00
action: CommentRequestSuccessAction,
): IComment => {
switch (action.type) {
case COMMENT_REQUEST_SUCCESS:
return {
id: action.comment.id,
body: action.comment.body,
2019-09-17 17:04:19 +02:00
parentId: action.comment.parent_id,
2019-10-01 19:15:03 +02:00
isPostUpdate: action.comment.is_post_update,
userFullName: action.comment.user_full_name,
2019-09-30 23:28:52 +02:00
userEmail: action.comment.user_email,
updatedAt: action.comment.updated_at,
};
default:
return state;
}
}
export default commentReducer;