From 67a291ac3a2ce5419289877758629e75ff2e1eee Mon Sep 17 00:00:00 2001 From: Chris McCord Date: Wed, 15 Dec 2021 22:03:18 -0500 Subject: [PATCH] Revert temporary assign --- lib/live_beats_web/live/profile_live.ex | 14 ++++++-------- .../live/profile_live/song_row_component.ex | 12 ++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/live_beats_web/live/profile_live.ex b/lib/live_beats_web/live/profile_live.ex index 2b3fe8e..61041cc 100644 --- a/lib/live_beats_web/live/profile_live.ex +++ b/lib/live_beats_web/live/profile_live.ex @@ -91,7 +91,7 @@ defmodule LiveBeatsWeb.ProfileLive do active_song_id = if song = MediaLibrary.get_current_active_song(profile) do - SongRowComponent.send_status(song, song.status) + SongRowComponent.send_status(song.id, song.status) song.id end @@ -170,8 +170,7 @@ defmodule LiveBeatsWeb.ProfileLive do def handle_info({Accounts, _}, socket), do: {:noreply, socket} defp stop_song(socket, song_id) do - song = MediaLibrary.get_song!(song_id) - SongRowComponent.send_status(song, :stopped) + SongRowComponent.send_status(song_id, :stopped) if socket.assigns.active_song_id == song_id do assign(socket, :active_song_id, nil) @@ -181,8 +180,7 @@ defmodule LiveBeatsWeb.ProfileLive do end defp pause_song(socket, song_id) do - song = MediaLibrary.get_song!(song_id) - SongRowComponent.send_status(song, :paused) + SongRowComponent.send_status(song_id, :paused) socket end @@ -191,18 +189,18 @@ defmodule LiveBeatsWeb.ProfileLive do cond do active_song_id == song.id -> - SongRowComponent.send_status(song, :playing) + SongRowComponent.send_status(song.id, :playing) socket active_song_id -> - SongRowComponent.send_status(song, :playing) + SongRowComponent.send_status(song.id, :playing) socket |> stop_song(active_song_id) |> assign(active_song_id: song.id) true -> - SongRowComponent.send_status(song, :playing) + SongRowComponent.send_status(song.id, :playing) assign(socket, active_song_id: song.id) end end diff --git a/lib/live_beats_web/live/profile_live/song_row_component.ex b/lib/live_beats_web/live/profile_live/song_row_component.ex index e66278c..b7381f8 100644 --- a/lib/live_beats_web/live/profile_live/song_row_component.ex +++ b/lib/live_beats_web/live/profile_live/song_row_component.ex @@ -3,8 +3,8 @@ defmodule LiveBeatsWeb.ProfileLive.SongRowComponent do alias LiveBeats.MediaLibrary.Song - def send_status(%Song{} = song, status) when status in [:playing, :paused, :stopped] do - send_update(__MODULE__, id: "song-#{song.id}", action: :send, song: song, status: status) + 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 @@ -44,12 +44,8 @@ defmodule LiveBeatsWeb.ProfileLive.SongRowComponent do """ end - def mount(socket) do - {:ok, socket, temporary_assigns: [song: nil]} - end - - def update(%{action: :send, status: status, song: song}, socket) when status in [:playing, :paused, :stopped] do - {:ok, assign(socket, status: status, song: song)} + 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