coen.bakker
I have story_cards that render a list of authors, among other things. Clicking an author should open a modal, via a function set_modal_data/1. This function needs the to be passed one author (not all authors).
Is there a way to pass the set_modal_click/1 function to the story_card function component call (e.g. <.story_card ... on_author_click={...}/>? Currently, I am using slots to be able assign the set_modal_click/1 to the phx-click that should open the modal.
# current solution
<.story_card
:for={story <- @stories}
story={story}
>
<:author let={author}>
<span
class="pub-cover-author-tag"
phx-click={set_modal_data(%{"id" => author.id, "modal" => "user"})}
>
<%= author.username %>
</span>
</:author>
</.story_card>
# hypothesized solution
<.story_card
:for={story <- @stories}
story={story}
let={author}
on_author_click={set_modal_data(%{"id" => author.id, "modal" => "user"})}
/>
Ty
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
ken-kost
I know you’re not using Surface but perhaps this documentation could help you.
if you have
current_userstored in your socket, you could send it together with authorSomething like that perhaps, then you could check inside story card if the current user is the author or not and act accordingly.
Not sure if I’m being relevant.
coen.bakker
Rereading my post, I notice I should have explained it better.
There is a comprehension for authors inside the story_card function component:
for author <- @authors do .... One story_card shows a html-element with aphx-clickfor each author.So the comprehension giving the
authormap can be found here (made some adjustments for this post so might contain typo’s):sodapopcan
You should be able to pass it as a capture:
and then:
I may also be misunderstand what you’re after, though!
coen.bakker
Oh yes. I see what you mean. I haven’t thought of it that way yet.
The reason for my post was that I like to be able to see all my LiveView event calls from my LiveView modules.
So I try to prevent this:
Instead, I have been doing:
However, some components have bindings (e.g. phx-click) inside them that are inside a comprehension expression. For example:
I was wondering if I can pass that
JS.push("some_event", value: %{item: item})from the last example/code block to the<.some_component/>component from the render function of the LiveView module, somehow.Some like:
sodapopcan
That makes sense!
It should work with the capture:
(sorry I forgot the
@in my original example)Possibly you already got that but I wasn’t sure from your response
coen.bakker
Great. Love it.
Ty
coen.bakker
Just got back to my computer to implement it and I am getting an error saying:
I am not familiar with having to explicitly implement Jason.Encoder protocol for a struct I own (in this case User, which corresponds with the author variable from earlier). Is this error to be expected when implementing the solution you suggested, that you know? This might be a good opportunity for me to learn more about implementing the Jason.Encoder protocol, in that case.
edit:
This is the stack trace I am getting:
sodapopcan
Oh right, I was sort of afraid of that, lol. It’s just saying you can’t encode an Elixir struct into HTML which makes sense. I think you can just put
@derive Json.Encoderin your schema. The idea is that it’s telling it how to convert a schema into JSON. That should work (I’m not actually trying these things as I type them). You could also explicitly pass the artist attributes as in your original example:benwilson512
Be very careful with this. The user struct in this case is being sent to the JS front end unencrypted. I would strongly suggest pulling out specific keys that are relevant to the JS.
sodapopcan
Right, you’d need to make sure you have the redacted fields set. Thanks for chiming in, I did not think of that!