2019-09-17 19:09:38 +02:00
|
|
|
import {
|
2019-09-26 16:03:41 +02:00
|
|
|
CommentRequestSuccessAction,
|
2019-09-17 19:09:38 +02:00
|
|
|
COMMENT_REQUEST_SUCCESS,
|
2022-05-07 11:27:07 +02:00
|
|
|
} from '../actions/Comment/requestComment';
|
2019-09-18 13:40:00 +02:00
|
|
|
|
2019-09-17 19:09:38 +02:00
|
|
|
import {
|
2019-09-26 16:03:41 +02:00
|
|
|
HandleCommentRepliesType,
|
2019-09-17 19:09:38 +02:00
|
|
|
TOGGLE_COMMENT_REPLY,
|
|
|
|
|
SET_COMMENT_REPLY_BODY,
|
2022-05-07 11:27:07 +02:00
|
|
|
} from '../actions/Comment/handleCommentReplies';
|
2019-09-17 19:09:38 +02:00
|
|
|
|
2019-09-18 13:40:00 +02:00
|
|
|
import {
|
2019-09-26 16:03:41 +02:00
|
|
|
CommentSubmitActionTypes,
|
2019-09-18 13:40:00 +02:00
|
|
|
COMMENT_SUBMIT_START,
|
|
|
|
|
COMMENT_SUBMIT_SUCCESS,
|
|
|
|
|
COMMENT_SUBMIT_FAILURE,
|
2022-05-07 11:27:07 +02:00
|
|
|
} from '../actions/Comment/submitComment';
|
2019-09-18 13:40:00 +02:00
|
|
|
|
2019-09-26 18:22:18 +02:00
|
|
|
export interface ReplyFormState {
|
2019-09-17 19:09:38 +02:00
|
|
|
commentId: number;
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
body: string;
|
2019-09-18 13:40:00 +02:00
|
|
|
isSubmitting: boolean;
|
|
|
|
|
error: string;
|
2019-09-17 19:09:38 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-26 18:22:18 +02:00
|
|
|
const initialState: ReplyFormState = {
|
2019-09-17 19:09:38 +02:00
|
|
|
commentId: undefined,
|
|
|
|
|
isOpen: false,
|
|
|
|
|
body: '',
|
2019-09-18 13:40:00 +02:00
|
|
|
isSubmitting: false,
|
|
|
|
|
error: '',
|
2019-09-17 19:09:38 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-26 18:22:18 +02:00
|
|
|
const replyFormReducer = (
|
2019-09-17 19:09:38 +02:00
|
|
|
state = initialState,
|
2019-09-26 16:03:41 +02:00
|
|
|
action:
|
|
|
|
|
CommentRequestSuccessAction |
|
|
|
|
|
HandleCommentRepliesType |
|
|
|
|
|
CommentSubmitActionTypes,
|
2019-09-17 19:09:38 +02:00
|
|
|
) => {
|
|
|
|
|
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,
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-18 13:40:00 +02:00
|
|
|
case COMMENT_SUBMIT_START:
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
isSubmitting: true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
case COMMENT_SUBMIT_SUCCESS:
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
isOpen: false,
|
|
|
|
|
body: '',
|
|
|
|
|
isSubmitting: false,
|
|
|
|
|
error: '',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
case COMMENT_SUBMIT_FAILURE:
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
error: action.error,
|
2019-09-26 18:22:18 +02:00
|
|
|
isSubmitting: false,
|
2019-09-18 13:40:00 +02:00
|
|
|
};
|
|
|
|
|
|
2019-09-17 19:09:38 +02:00
|
|
|
default:
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-26 18:22:18 +02:00
|
|
|
export default replyFormReducer;
|