defmodule LiveBeatsWeb.ProfileLive.SongRowComponent do
use LiveBeatsWeb, :live_component
def send_status(song_id, status) when status in [:playing, :paused, :stopped] do
send_update(__MODULE__, id: "song-#{song_id}", action: :send, status: status)
end
def render(assigns) do
~H"""
<%= for {col, i} <- Enum.with_index(@col) do %>
<%= if i == 0 do %>
<%= if @status == :playing do %>
<.icon name={:volume_up} class="h-5 w-5 -mt-1 -ml-1" aria-label="Playing" role="button"/>
<% end %>
<%= if @status == :paused do %>
<.icon name={:volume_up} class="h-5 w-5 -mt-1 -ml-1 text-gray-400" aria-label="Paused" role="button"/>
<% end %>
<%= if @status == :stopped do %>
<%= if @owns_profile? do %>
<.icon name={:play} class="h-5 w-5 text-gray-400" aria-label="Play" role="button"/>
<% end %>
<% end %>
<% end %>
<%= render_slot(col, assigns) %>
|
<% end %>
"""
end
def update(%{action: :send, status: status}, socket) when status in [:playing, :paused, :stopped] do
{:ok, assign(socket, status: status)}
end
def update(assigns, socket) do
{:ok,
assign(socket,
id: assigns.id,
song: assigns.row,
col: assigns.col,
class: assigns.class,
index: assigns.index,
status: :stopped,
owns_profile?: assigns.owns_profile?
)}
end
end