For an internal project called βControlManiacβ, which helps us with all the boring numbers juggling in our software studio, I had to add a global filter to the navigation bar, which lets me select the division I want to filter the data for on whatever view I am currently on.
Since we often switch views while using this app, it should keep its selection. It should also keep it upon reloading or revisiting the page and upon deployment of a new version.
This is what it looks like; it is the toggle element on the right:
The Home, Projects, and Costs navigation options are all separate live views, within the same
live_session
.I thought there would be a quite easy solution, but it turned out that all common approaches had their downsides:
Keeping it in the
assigns
only is not an option, since this is cleared upon changing the current live view.Storing it in a session cookie would ensure it survives a full page reload but brings two problems: First, the session information is not reloaded upon changing the live views within the same
live_session
, because this is done entirely via web sockets. Thus, we would get the initial value the session head at the time of the first HTTP request. This brings me to the second problem: I neither can update the session since there is no HTTP request upon live navigation, and the session cookie cannot be updated via web socket.Storing it in an ETS table solves the problem of switching live views within the same
live_session
, but of course, it would not survive an app restart, as is the case upon deployment of a new version.I could, of course, pursue the session approach and just make sure to add a parameter every time I switch between the main live views, but this does feel very odd.
I eventually decided to go with a classic cookie-based session combined with an additional layer stored in an ETS table.
continue reading on 9elements.com
β οΈ This post links to an external website. β οΈ
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.