mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-22 08:01:00 +00:00
Revert temporary assign
This commit is contained in:
parent
8da032fed3
commit
67a291ac3a
2 changed files with 10 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue