I've implemented a feature in my Django view where users can toggle between two different "views" of a list using a toggle button. One option displays a map with markers and information, while the other option shows the same information in a list format.
Switching between views by clicking the toggle button works perfectly thanks to an onClick JavaScript function that changes the display style. However, the issue arises when the page is reloaded.
If the default view is set to the map view but a user switches to the list view before refreshing the page, the list view should be displayed upon reloading. I understand that this can be achieved using cookies, but I'm unsure how to update the cookie every time the toggle button is clicked using vanilla JavaScript or in my Python view.
One possible solution could involve creating separate Django views for "mapView" and "listView," redirecting users to different URLs when they click the toggle buttons. However, I prefer to keep all the information loaded on the same page without resorting to this approach.
I have also attached a GIF demonstrating the current functionality. In the example, I clicked on the map view, reloaded the page, and then switched back to the list view.
https://i.sstatic.net/vJPMI.gif
Thank you!