Files
astuto/app/javascript/reducers/replyFormReducer.ts
Riccardo Graziosi dad382d2b1 Post follow and updates notifications V1 (#111)
* It is now possible to follow a post in order to receive updates about it
* Notifications are now sent when updates are published
* Post status changes are now tracked
* Update sidebar now shows the post status history
* Mark a comment as a post update using the comment form
* ... more ...
2022-05-28 11:03:36 +02:00

98 lines
1.9 KiB
TypeScript

import {
CommentRequestSuccessAction,
COMMENT_REQUEST_SUCCESS,
} from '../actions/Comment/requestComment';
import {
HandleCommentRepliesType,
TOGGLE_COMMENT_REPLY,
SET_COMMENT_REPLY_BODY,
TOGGLE_COMMENT_IS_POST_UPDATE_FLAG,
} from '../actions/Comment/handleCommentReplies';
import {
CommentSubmitActionTypes,
COMMENT_SUBMIT_START,
COMMENT_SUBMIT_SUCCESS,
COMMENT_SUBMIT_FAILURE,
} from '../actions/Comment/submitComment';
export interface ReplyFormState {
commentId: number;
isOpen: boolean;
body: string;
isPostUpdate: boolean;
isSubmitting: boolean;
error: string;
}
const initialState: ReplyFormState = {
commentId: undefined,
isOpen: false,
body: '',
isPostUpdate: false,
isSubmitting: false,
error: '',
}
const replyFormReducer = (
state = initialState,
action:
CommentRequestSuccessAction |
HandleCommentRepliesType |
CommentSubmitActionTypes,
) => {
switch (action.type) {
case COMMENT_REQUEST_SUCCESS:
return {
...initialState,
commentId: action.comment.id,
};
case TOGGLE_COMMENT_REPLY:
return {
...state,
isOpen: !state.isOpen,
};
case SET_COMMENT_REPLY_BODY:
return {
...state,
body: action.body,
};
case TOGGLE_COMMENT_IS_POST_UPDATE_FLAG:
return {
...state,
isPostUpdate: !state.isPostUpdate,
};
case COMMENT_SUBMIT_START:
return {
...state,
isSubmitting: true,
};
case COMMENT_SUBMIT_SUCCESS:
return {
...state,
isOpen: false,
body: '',
isPostUpdate: false,
isSubmitting: false,
error: '',
};
case COMMENT_SUBMIT_FAILURE:
return {
...state,
error: action.error,
isSubmitting: false,
};
default:
return state;
}
}
export default replyFormReducer;