Local storage of unsubmitted work

Continuing the discussion from Why is the Client Side Session Timeout so Short?: @jshaffstall

What I’m trying to do:
I have a simulation game with one game leader and up to 60 players all accessing one app. There is a progression through the simulation: the leader starts the game, the players log into their roles, the players take decisions, submit their decisions, the leader advances the simulations, new results are displayed for the players, etc. All works well unless any one of the users (accidentally?) clicks on their reload button of the browser tab. This can happen to the leader and / or to any of the players.

What I’ve tried and what’s not working:
Currently the tab reloads and starts at the beginning.
The solution is to keep track of where the player was just before they (accidentally?) reloaded the tab and when they reload give them the option to jump to the last screen they saw. That includes the graphs and buttons and forms they saw just before their “mistake”.

I looked at the cookies and anvil.server.session examples which I can work through and adapt to my needs. @jshaffstall you seem to have solved this type of problem before, so maybe I do not need to re-invent the wheel?
Thanks and best
PS If I do need to re-invent the wheel, I will post my solution (which will take a bit of time :slight_smile:

I’ve used the browser’s local storage for this. Anytime the user makes a change to an input field, I save the current state in local storage. When the app starts, I check to see if there’s anything in local storage and load that state in.

I use Anvil Extra’s storage module for interacting with local storage: Storage — Anvil Extras documentation

2 Likes

I don’t understand the problem. The user refreshes the browser, the client calls the server and gets the status of the game. Isn’t this what you want?

There are many users of the app all playing the same game. They are at different states of the game. If anyone refreshes their browser (by accident) I need to know the status of the game for this particular user and serve to him / her their status. @jshaffstall solution works since it allows me to save the state of the game for each user user in their browser. When they refresh, I know the state of their progression through the game and serve the correct entry point for them. Hope this is clearer.

You can save the status in the browser, but that would prevent users from continuing on a different device.

If you store the timestamp of every submission, you’ll know who did what and when, so you can send the partial status to any logged-in user—even if they switched devices.

But maybe I’m completely misunderstanding the nature of the game.

1 Like