Closed fatimaahmed14 closed 1 year ago
Missing:
1) more details about how to CREATE that array of likes that you mention 2) are you going to change how the like icon / text looks like if I can Like or Unlike? 3) how could this code be re-used for the LIKES on a comment?
I am not currently sure how to re-use this code for liking a comment, maybe it would be a case of using the same function but sending a GET request to commentLike and sending a POST request to commentLike.
You could split this into 2 components.
The first one just has the HTML jsx and some props to choose what to display (the like button, number of likes and whether user has liked or not, and then also a function to handleClick
The parent component can then be a PostLike which has logic to fetch the post likes, count them and check if user has liked or note
Then a second parent component can be the CommentLike which has similar logic for post likes but for comments.
Example
function LikeButton({likeCount, userHasLikedThis, handleClick}) {
// jsx returns a button with a like icon and the number of likes
// button has different styling whether userHasLikedThis or not
// on button click, call handleClick so that parent component can decide whether to send a create like or remove like
}
Requirements
any user can like or (remove a like) from a post
a user can only like a post they haven't liked previously
a user can only dislike a post they have liked previously
Like button turns blue when post is liked and is empty when post is not liked button is white (using toggle)
Button lights up when hovering over it
UI Approach
Code structure
{{ _.base_url }}/posts
Wireframe
UI Functionality
{{ _.base_url }}/posts/postLike
usingclient.js
{{ _.base_url }}/posts/1/postLike
usingclient.js
{{ _.base_url }}/posts/1/postLike
with the following: