Revert temporary assign

This commit is contained in:
Chris McCord 2021-12-15 22:03:18 -05:00
parent 8da032fed3
commit 67a291ac3a
2 changed files with 10 additions and 16 deletions

View file

@ -91,7 +91,7 @@ defmodule LiveBeatsWeb.ProfileLive do
active_song_id = active_song_id =
if song = MediaLibrary.get_current_active_song(profile) do if song = MediaLibrary.get_current_active_song(profile) do
SongRowComponent.send_status(song, song.status) SongRowComponent.send_status(song.id, song.status)
song.id song.id
end end
@ -170,8 +170,7 @@ defmodule LiveBeatsWeb.ProfileLive do
def handle_info({Accounts, _}, socket), do: {:noreply, socket} def handle_info({Accounts, _}, socket), do: {:noreply, socket}
defp stop_song(socket, song_id) do defp stop_song(socket, song_id) do
song = MediaLibrary.get_song!(song_id) SongRowComponent.send_status(song_id, :stopped)
SongRowComponent.send_status(song, :stopped)
if socket.assigns.active_song_id == song_id do if socket.assigns.active_song_id == song_id do
assign(socket, :active_song_id, nil) assign(socket, :active_song_id, nil)
@ -181,8 +180,7 @@ defmodule LiveBeatsWeb.ProfileLive do
end end
defp pause_song(socket, song_id) do defp pause_song(socket, song_id) do
song = MediaLibrary.get_song!(song_id) SongRowComponent.send_status(song_id, :paused)
SongRowComponent.send_status(song, :paused)
socket socket
end end
@ -191,18 +189,18 @@ defmodule LiveBeatsWeb.ProfileLive do
cond do cond do
active_song_id == song.id -> active_song_id == song.id ->
SongRowComponent.send_status(song, :playing) SongRowComponent.send_status(song.id, :playing)
socket socket
active_song_id -> active_song_id ->
SongRowComponent.send_status(song, :playing) SongRowComponent.send_status(song.id, :playing)
socket socket
|> stop_song(active_song_id) |> stop_song(active_song_id)
|> assign(active_song_id: song.id) |> assign(active_song_id: song.id)
true -> true ->
SongRowComponent.send_status(song, :playing) SongRowComponent.send_status(song.id, :playing)
assign(socket, active_song_id: song.id) assign(socket, active_song_id: song.id)
end end
end end

View file

@ -3,8 +3,8 @@ defmodule LiveBeatsWeb.ProfileLive.SongRowComponent do
alias LiveBeats.MediaLibrary.Song alias LiveBeats.MediaLibrary.Song
def send_status(%Song{} = song, status) when status in [:playing, :paused, :stopped] do def send_status(song_id, status) when status in [:playing, :paused, :stopped] do
send_update(__MODULE__, id: "song-#{song.id}", action: :send, song: song, status: status) send_update(__MODULE__, id: "song-#{song_id}", action: :send, status: status)
end end
def render(assigns) do def render(assigns) do
@ -44,12 +44,8 @@ defmodule LiveBeatsWeb.ProfileLive.SongRowComponent do
""" """
end end
def mount(socket) do def update(%{action: :send, status: status}, socket) when status in [:playing, :paused, :stopped] do
{:ok, socket, temporary_assigns: [song: nil]} {:ok, assign(socket, status: status)}
end
def update(%{action: :send, status: status, song: song}, socket) when status in [:playing, :paused, :stopped] do
{:ok, assign(socket, status: status, song: song)}
end end
def update(assigns, socket) do def update(assigns, socket) do