Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post Reactions not rendering updated reaction counts #2

Open
hummusonrails opened this issue Mar 13, 2018 · 2 comments
Open

Post Reactions not rendering updated reaction counts #2

hummusonrails opened this issue Mar 13, 2018 · 2 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@hummusonrails
Copy link
Owner

There are three "reaction" types for a post in the ViewPost component: star (called a like), hand and heart. Each time a registered user clicks on one of them it updates the Postlike table with either a 0 or a 1 in the respective heart, star/like, hand column where the post_id is the foreign key for the post and the user_id is the foreign key for the user.

The actions are working both on the backend (the Rails controller successfully updates the database and returns the appropriate data back as JSON) and the frontend (the state in Redux reflects the new reaction counts. Yet, the number next to each reaction type on a post does not re-render when the dispatch action fires.

Help would be appreciated to get the reaction counter numbers on the ViewPost component to successfully refresh when the count in Redux state changes.

@hummusonrails hummusonrails added help wanted Extra attention is needed good first issue Good for newcomers labels Mar 13, 2018
@dotthespeck
Copy link

dotthespeck commented Mar 15, 2018

From what I can see, the code needs to do the following actions on a click:
Step 1) Make a record in the DB with the correct post_id, user_id and postlike value
Step 2) Call a method that gets the total number of postlike values for each type of postlike to show.

I think Step 2 is currently going wrong in the postlikes_controller show method. Instead of getting the total number for each postlike type, you are looping through all of the records and resetting the values. I think instead there should be some kind of JSON object that gives you the values you need based on the returns from the post_like.count methods { "likes": "2", "hands": "3", "stars": "4"}. That loop shouldn't be necessary there, you can get the total values from the DB directly through queries.

@hummusonrails
Copy link
Owner Author

hummusonrails commented Mar 15, 2018

That's exactly what the code needs to do. I believe no. 1 is happening correctly and I also thought no. 2 was happening correctly as well when I examined what was being returned from the show method.

The show method calls three methods in the postlike model that count the total for each reaction type respectively and then adds them to a hash and returns it as JSON. When I examined what was being returned in that hash it looked correct to me and the object in Redux state also updated the count when I saw the Redux action fire.

I am sure there is a better way to do what I am doing through this process though. In fact, a more succinct and cleaner version might even resolve the re-rendering issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants