UNPKG

adastra-ui-comment

Version:

Testing locally 1) in this file - `npm i` install dependencies - `npm run build` or `npm run tsc` to build your module 2) in childApp - in package.json under dependencies add ui-astra-assets with file:(relativePathToRepo) - "ui-astra-a

47 lines 1.96 kB
import { FETCH_COMMENTS_SUCCESS, FETCH_USERS_SUCCESS, CREATE_COMMENT_SUCCESS, SET_THREAD_ID, DELETE_COMMENT_SUCCESS, SET_REPLY_USER, } from 'CommentSection/constants'; export const initialState = { comments: [], users: [], threadId: '201808_AADS_1101', replyUser: '', }; function commentsReducer(state = initialState, action) { switch (action.type) { case SET_THREAD_ID: { return Object.assign(Object.assign({}, state), { threadId: action.payload.threadId }); } case FETCH_COMMENTS_SUCCESS: { return Object.assign(Object.assign({}, state), { comments: action.payload.comments }); } case CREATE_COMMENT_SUCCESS: { const commentData = action.payload.comment; const constructedComment = { id: '123', message: commentData.comment_text, author: 'Me', authorId: 'me', createdDate: (new Date).toString(), isOwner: true, }; const newComments = state.comments; newComments.unshift(constructedComment); return Object.assign(Object.assign({}, state), { comments: newComments }); } case FETCH_USERS_SUCCESS: { return Object.assign(Object.assign({}, state), { users: action.payload.users }); } case DELETE_COMMENT_SUCCESS: { const deletedCommentId = action.payload.comment.id; const newComments = state.comments.filter(c => deletedCommentId !== c.id); return Object.assign(Object.assign({}, state), { comments: newComments }); } case SET_REPLY_USER: { const userString = action.payload.userString; return Object.assign(Object.assign({}, state), { replyUser: userString }); } default: return state; } } export default commentsReducer; //# sourceMappingURL=reducer.js.map