You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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?
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.
The text was updated successfully, but these errors were encountered: