Dynamic text search not updating when deleting thing

I have a liking system that will add a new Like thing if a user clicks on it, providing it doesn’t already exist. If it does, it will delete the corresponding Like. I also have a text field that searches for a count of all relevant likes.

The problem is that when the user likes something, the count instantly increases by 1. However, if they try to unlike something, the count stays the same unless the user refreshes the page. Here’s a scenario:

  1. Count shows 0
  2. User clicks like. A like gets created, so the count shows 1.
  3. User clicks like again, and the like gets deleted. However, the count does not update. The thing is actually deleted if I check the database, but the count still shows 1 when it should be showing 0.
  4. User clicks like a 3rd time, creating a new like. The actual like count is 1, but the count is now showing 2.
  5. User refreshes, and the count of 2 changes to the real number, which is 1.

The maddening thing is, this only happens sometimes. It happens reliably, probably 60% of the time. I can’t figure out why it’s so random.

This is the event that triggers the action:

This is the delete action:

1 Like

Try setting it to zero before deleting it
Bubble can sometimes be inconsistent between the database and the screen.
I had similar issues when creating a button to increase and decrease a value. If you hit the button a few times quickly up and down it couldn’t maintain the count.
I ended up just having it so the using can input the number and gave up on the buttons.

However for your scenario I think setting it to zero would work as the user shouldn’t be mashing the like button

Okay that makes sense, I’ll just do that. Thanks for the input!

This topic was automatically closed after 70 days. New replies are no longer allowed.