Skip to content

Commit

Permalink
refactor: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
sundasnoreen12 committed Jul 19, 2024
1 parent c45eea7 commit 933ce08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const CommentEditor = ({
} else {
await dispatch(setDraftResponses(updatedResponses));
}
}, [parentId, id, threadId]);
}, [parentId, id, threadId, setDraftComments, setDraftResponses]);

const saveUpdatedComment = useCallback(async (values, { resetForm }) => {
if (id) {
Expand Down
16 changes: 13 additions & 3 deletions src/discussions/post-comments/data/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,19 @@ export const useDraftContent = () => {
});

const addDraftContent = (content, parentId, id, threadId) => {
const newObject = {
threadId, content, parentId, id: id || uuidv4(), isNewContent: !id,
};
const data = parentId ? comments : responses;
const draftParentId = parentId || threadId;
const isComment = !!parentId;
const existingObj = getObjectByParentId(data, draftParentId, isComment, id);
const newObject = existingObj
? { ...existingObj, content }

Check warning on line 127 in src/discussions/post-comments/data/hooks.js

View check run for this annotation

Codecov / codecov/patch

src/discussions/post-comments/data/hooks.js#L127

Added line #L127 was not covered by tests
: {
threadId,
content,
parentId,
id: id || uuidv4(),
isNewContent: !id,
};

const updatedComments = parentId ? updateDraftData(comments, newObject) : comments;
const updatedResponses = !parentId ? updateDraftData(responses, newObject) : responses;
Expand Down

0 comments on commit 933ce08

Please sign in to comment.