I’m continuing to struggle with how to pass session data between two LiveViews. LiveView 1 allows for searching for resources (no authentication needed) and LiveView 2 allows user to save resource (which requires authentication).
Users can filter resources based on certain filter criteria. I need to pass the selected filter criteria to LiveView2 and then back to LiveView1 so that the user doesn’t lose the filters they set.
Criteria is a list that looks like this:
[mediums: [1,4,5], topics: , res_types: , supplies: [1, 3]]
I unsuccessfully tried passing this list in live_redirect as follows:
<span><%= live_redirect "Save", to: Routes.resourceform_save_resource_path(@socket, :save, resourceform.id, "<%=@criteria%>" ) %></span>
This failed. So I tried this and it also fails:
<span><%= live_redirect "Save", to: Routes.resourceform_save_resource_path(@socket, :save, resourceform.id, @criteria ) %></span>
I can’t send a list as a param in live_redirect. So I need to pack my list into a string that looks like this:
"[mediums: , topics: , res_types: , supplies: ]"
Then I need to unpack it out of the string when it returns to LiveView1 so that I can apply the criteria filters.
How do I put a List inside of a string and then take it out again?