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

81 lines
1.4 KiB
TypeScript
Raw Normal View History

import {
COMMENT_REQUEST_SUCCESS,
} from '../actions/requestComment';
2019-09-18 13:40:00 +02:00
import {
TOGGLE_COMMENT_REPLY,
SET_COMMENT_REPLY_BODY,
} from '../actions/handleCommentReplies';
2019-09-18 13:40:00 +02:00
import {
COMMENT_SUBMIT_START,
COMMENT_SUBMIT_SUCCESS,
COMMENT_SUBMIT_FAILURE,
} from '../actions/submitComment';
export interface CommentRepliesState {
commentId: number;
isOpen: boolean;
body: string;
2019-09-18 13:40:00 +02:00
isSubmitting: boolean;
error: string;
}
const initialState: CommentRepliesState = {
commentId: undefined,
isOpen: false,
body: '',
2019-09-18 13:40:00 +02:00
isSubmitting: false,
error: '',
}
const commentRepliesReducer = (
state = initialState,
action,
) => {
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,
};
default:
return state;
}
}
export default commentRepliesReducer;