I am building an interface for some data, where clicking on a bunch of buttons will change the data’s view.
To hold the state, the standard web way, I’ve been doing phx-click events, and push_patching when i handle the event eg.
<span class="cursor-pointer"
phx-click={
JS.push("select_category",
value: %{category: key, item: value},
page_loading: true
)
}
phx-page-loading
>
I use handle_params to extract the params from the push_patch, and then re-render the data.
This has worked really well, but i’ve come to realise this is kind of breaking the web experience. Normally I can middle click on a link to open a new tab but it does nothing, because it’s not a real link.
So my plan is to use a real link eg.
<.link
class={[
"cursor-pointer",
@class
]}
phx-click={
JS.push("select_category",
value: %{category: key, item: value},
page_loading: true
)
phx-page-loading
>
This allows middle click to open a new page, but it doesn’t execute the JS.push (obviously!)
So my next thought is to do
<.link
class={[
"cursor-pointer",
@class
]}
navigate={
# code goes here
}
phx-page-loading
>
I know sigil_p would work in the navigate attribute, but sigil_p isn’t exactly what i want. for one, it requires me to hardcode in the path to this component, and if it’s in a component library that’s not very good!
Secondly, I don’t really want to change the link, i just want to merge some new query parameters on top of the existing ones.
I am guessing there is some sort of helper function i can use but so far I haven’t had any success.
Any ideas?