I’m really trying to see what would work best for me. I’m trying to update a product quantity after pressing the “+” button without updating the database, i don’t know if that is smart or it’s better to update the database directly.
The reason I would not like to update the database directly after the “+” button is the delay it would cause and only updating the quantity in database after clicking “ADD” would be smarter in my opinion.
I have set the following:
Initial content: 1
APP DATA Product - Quantity = “1”
you can do it with two states.
first state captures current count then second state is a buffer that displays your first state current count + 1, i think if you want to be extra fancy you use javascript for how many button presses in what time to change what “+ amount you give per workflow cycle”
I think sliders are probably a bit better if this concern you though, depends on what youre selling,
if its conventional to buy a lot or more than one, slider is way to go but if its one or two products at a time the delay shouldnt really matter at all.
It’s a wholesale bulk purchase, so it would be nice to add Javascript to manage the counter. Will look into it and will let you know if I can solve this. Thanks for the advice guys.
On page load, load the list of quantities from the database to a custom state.
Have the elements on the page set to reference the custom state and not the database.
When a user changes the quantity on the UI, then 1st update the custom state - this way it happens instantly for the user
In the same workflow, update the database. Note, I like to add a condition to this action so it runs only if the quantity is the same as I’m adding back to the database (so if a user changes it a few times in a row, the database doesn’t get updated with the wrong data at all).
As such, you get the immediate responsiveness of client side interaction while also maintaining an always up-to-date version in the database.