cybercog / laravel-love

Add Social Reactions to Laravel Eloquent Models. It lets people express how they feel about the content. Fully customizable Weighted Reaction System & Reaction Type System with Like, Dislike and any other custom emotion types. Do you react?
https://komarev.com/sources/laravel-love
MIT License
1.17k stars 71 forks source link

Updating reaction_counters on client side #255

Closed jandante closed 1 year ago

jandante commented 1 year ago

Hi,

I have a question rather then an issue.

In my user interface when a user clicks on a react button everything gets updated on the server and Laravel Horizon is taking care of updating the counters.

To reflect this update on the client side I want to return the current reaction counters to display them correctly. However my application is quicker to return the counters then Laravel Horizon is in updating the counters. So my application is getting old information to handle.

How are you handling this on the client side?

Should it be completely on the client that we change this? Updating the reaction_counters on the client side doesn't seem normal to do. That implemantion would require to do a lot of things that I don't want on the client side (check what type should be incremented / decremented, if type not yet in the counters create it, maybe someone cancelled his like -> how to intercept that, ...)

Any advice is greatly appreciated and thanks for this package!

antonkomarev commented 1 year ago

@jandante you may increment/decrement the counter on the frontend. On the next page reload user will get the real value. It is not that bad if the user would not see real value from the database instantly.

antonkomarev commented 1 year ago

If action is successful, then return success response and do the math, otherwise do not do anything.

jandante commented 1 year ago

Thanks @antonkomarev . I ended up adding a increment or decrement property to my return value on reacting. When that was available I triggered a local increment / decrement of the counters.