boolean-uk / team-dev-frontend-client

1 stars 11 forks source link

Like posts - functionality #156

Closed fatimaahmed14 closed 1 year ago

fatimaahmed14 commented 1 year ago

Requirements

UI Approach

Code structure

Wireframe

Likes

UI Functionality

{
    "active": false,
    "postLikeId": 7
}
dogezen commented 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?

fatimaahmed14 commented 1 year ago

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.

dogezen commented 1 year ago

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
}