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

72 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-09-12 15:51:45 +02:00
import {
2019-09-26 16:03:41 +02:00
PostRequestActionTypes,
2019-09-12 15:51:45 +02:00
POST_REQUEST_SUCCESS,
2022-05-07 11:27:07 +02:00
} from '../actions/Post/requestPost';
2019-09-12 15:51:45 +02:00
2019-09-21 12:54:57 +02:00
import {
2019-09-26 16:03:41 +02:00
ChangePostBoardSuccessAction,
2019-09-21 12:54:57 +02:00
CHANGE_POST_BOARD_SUCCESS,
2022-05-07 11:27:07 +02:00
} from '../actions/Post/changePostBoard';
2019-09-21 12:54:57 +02:00
2019-09-12 15:51:45 +02:00
import {
2019-09-26 16:03:41 +02:00
ChangePostStatusSuccessAction,
2019-09-12 15:51:45 +02:00
CHANGE_POST_STATUS_SUCCESS,
2022-05-07 11:27:07 +02:00
} from '../actions/Post/changePostStatus';
2019-09-12 15:51:45 +02:00
import IPost from '../interfaces/IPost';
const initialState: IPost = {
id: 0,
title: '',
description: null,
boardId: 0,
postStatusId: null,
2019-09-27 16:57:23 +02:00
likesCount: 0,
liked: 0,
commentsCount: 0,
2019-09-27 16:57:23 +02:00
hotness: 0,
userId: 0,
createdAt: '',
};
const postReducer = (
state = initialState,
2019-09-26 16:03:41 +02:00
action:
PostRequestActionTypes |
ChangePostBoardSuccessAction |
ChangePostStatusSuccessAction,
): IPost => {
switch (action.type) {
2019-09-12 15:51:45 +02:00
case POST_REQUEST_SUCCESS:
return {
id: action.post.id,
title: action.post.title,
description: action.post.description,
boardId: action.post.board_id,
postStatusId: action.post.post_status_id,
2019-09-27 16:57:23 +02:00
likesCount: action.post.likes_count,
liked: action.post.liked,
commentsCount: action.post.comments_count,
2019-09-27 16:57:23 +02:00
hotness: action.post.hotness,
userId: action.post.user_id,
createdAt: action.post.created_at,
};
2019-09-21 12:54:57 +02:00
case CHANGE_POST_BOARD_SUCCESS:
return {
...state,
boardId: action.newBoardId,
};
2019-09-12 15:51:45 +02:00
case CHANGE_POST_STATUS_SUCCESS:
return {
...state,
postStatusId: action.newPostStatusId,
};
default:
return state;
}
}
export default postReducer;