Skip to content

Commit

Permalink
Fix(#266): added reactions and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Philimuhire committed Dec 2, 2024
1 parent 7989e1f commit e707465
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/redux/actions/commentActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export const createCommentAction = (blogId: string, content: string) => async (d
type: CREATE_COMMENT_SUCCESS,
payload: createdComment,
});
toast.success("Comment created successfully!");
} catch (err: any) {
const errorMessage =
err.response?.data?.errors?.[0]?.message || err.message || "Failed to create comment";
Expand Down Expand Up @@ -165,7 +164,7 @@ export const updateCommentAction = (commentId: string, updateFields: any) => asy
type: UPDATE_COMMENT_SUCCESS,
payload: updatedComment,
});
toast.success("Comment updated successfully!");

} catch (err: any) {
const errorMessage = err.response?.data?.errors?.[0]?.message || err.message || "Failed to update comment";
dispatch({
Expand Down Expand Up @@ -193,7 +192,7 @@ export const deleteCommentAction = (commentId: string) => async (dispatch: any)
type: DELETE_COMMENT_SUCCESS,
payload: commentId,
});
toast.success("Comment deleted successfully!");

} catch (err: any) {
const errorMessage = err.response?.data?.errors?.[0]?.message || err.message || "Failed to delete comment";
dispatch({
Expand Down Expand Up @@ -306,7 +305,7 @@ export const addReplyToComment = (content: string, commentId: string) => async (
type: ADD_REPLY_SUCCESS,
payload: { commentId, reply: newReply },
});
toast.success("Reply added successfully!");

} catch (err: any) {
const errorMessage =
err.response?.data?.errors?.[0]?.message || err.message || "Failed to add reply";
Expand Down
5 changes: 1 addition & 4 deletions src/redux/actions/reactionActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const getReactionsByBlogId = (blogId: string) => async (dispatch: any) =>
dispatch(creator(fetchReactions.FETCH_REACTIONS_SUCCESS, reactionCounts));
} catch (err: any) {
dispatch(creator(fetchReactions.FETCH_REACTIONS_FAILURE, err.message));
toast.error("Failed to fetch reactions.");
}
};

Expand Down Expand Up @@ -73,7 +72,7 @@ export const addReactionAction = (blogId: string, type: string) => async (dispat

const reaction = response?.data?.data?.addReaction;
dispatch(creator(addReaction.ADD_REACTION_SUCCESS, reaction));
toast.success("Reaction added successfully!");

} catch (err: any) {
dispatch(creator(addReaction.ADD_REACTION_FAIL, err.message));
toast.error("Failed to add reaction.");
Expand Down Expand Up @@ -103,9 +102,7 @@ export const removeReactionAction = (blogId: string) => async (dispatch: any) =>
});

dispatch(creator(removeReaction.REMOVE_REACTION_SUCCESS, { userId, blogId }));
toast.success("Reaction removed successfully!");
} catch (err: any) {
dispatch(creator(removeReaction.REMOVE_REACTION_FAIL, err.message));
toast.error("Failed to remove reaction.");
}
};

0 comments on commit e707465

Please sign in to comment.