Extract artist_image component
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
defmodule MusicLibraryWeb.ArtistComponents do
|
||||
use MusicLibraryWeb, :html
|
||||
|
||||
alias MusicLibrary.Assets.Transform
|
||||
|
||||
attr :artist, :map, required: true
|
||||
attr :image_hash, :string, required: true
|
||||
attr :class, :string, required: false
|
||||
attr :width, :integer, default: nil
|
||||
|
||||
def artist_image(assigns) do
|
||||
payload =
|
||||
%Transform{hash: assigns.image_hash, width: assigns.width}
|
||||
|> Transform.encode!()
|
||||
|
||||
assigns = assign(assigns, :payload, payload)
|
||||
|
||||
~H"""
|
||||
<img
|
||||
class={@class}
|
||||
src={~p"/assets/#{@payload}"}
|
||||
alt={@artist.name}
|
||||
onerror={"this.src = '" <> ~p"/images/cover-not-found.png" <> "';"}
|
||||
/>
|
||||
"""
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user