mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 11:47:56 +01:00
Add comment replies toggle and body to state
This commit is contained in:
@@ -4,20 +4,31 @@ import {
|
||||
COMMENTS_REQUEST_SUCCESS,
|
||||
COMMENTS_REQUEST_FAILURE,
|
||||
} from '../actions/requestComments';
|
||||
|
||||
import { commentRequestSuccess } from '../actions/requestComment';
|
||||
|
||||
import {
|
||||
HandleCommentRepliesType,
|
||||
TOGGLE_COMMENT_REPLY,
|
||||
SET_COMMENT_REPLY_BODY,
|
||||
} from '../actions/handleCommentReplies';
|
||||
|
||||
import commentReducer from './commentReducer';
|
||||
import commentRepliesReducer from './commentRepliesReducer';
|
||||
|
||||
import IComment from '../interfaces/IComment';
|
||||
import { CommentRepliesState } from './commentRepliesReducer';
|
||||
|
||||
export interface CommentsState {
|
||||
items: Array<IComment>;
|
||||
replies: Array<CommentRepliesState>;
|
||||
areLoading: boolean;
|
||||
error: string;
|
||||
}
|
||||
|
||||
const initialState: CommentsState = {
|
||||
items: [],
|
||||
replies: [],
|
||||
areLoading: false,
|
||||
error: '',
|
||||
};
|
||||
@@ -39,6 +50,9 @@ const commentsReducer = (
|
||||
items: action.comments.map(
|
||||
comment => commentReducer(undefined, commentRequestSuccess(comment))
|
||||
),
|
||||
replies: action.comments.map(
|
||||
comment => commentRepliesReducer(undefined, commentRequestSuccess(comment))
|
||||
),
|
||||
areLoading: false,
|
||||
error: '',
|
||||
};
|
||||
@@ -50,6 +64,20 @@ const commentsReducer = (
|
||||
error: action.error,
|
||||
};
|
||||
|
||||
case TOGGLE_COMMENT_REPLY:
|
||||
case SET_COMMENT_REPLY_BODY:
|
||||
return {
|
||||
...state,
|
||||
replies: state.replies.map(
|
||||
reply => (
|
||||
reply.commentId === action.commentId ?
|
||||
commentRepliesReducer(reply, action)
|
||||
:
|
||||
reply
|
||||
)
|
||||
),
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user