mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-21 15:41:00 +00:00
Rename SongLive modules to ProfileLive
This commit is contained in:
parent
8b5c77ca90
commit
bb23d8e071
11 changed files with 28 additions and 130 deletions
|
@ -8,12 +8,14 @@ defmodule LiveBeatsWeb.LiveHelpers do
|
|||
alias LiveBeats.Accounts
|
||||
alias LiveBeats.MediaLibrary
|
||||
|
||||
def profile_path(%Accounts.User{} = current_user) do
|
||||
Routes.song_index_path(LiveBeatsWeb.Endpoint, :index, current_user.username)
|
||||
def profile_path(current_user_or_profile, action \\ :index)
|
||||
|
||||
def profile_path(%Accounts.User{} = current_user, action) do
|
||||
Routes.profile_path(LiveBeatsWeb.Endpoint, action, current_user.username)
|
||||
end
|
||||
|
||||
def profile_path(%MediaLibrary.Profile{} = profile) do
|
||||
Routes.song_index_path(LiveBeatsWeb.Endpoint, :index, profile.username)
|
||||
def profile_path(%MediaLibrary.Profile{} = profile, action) do
|
||||
Routes.profile_path(LiveBeatsWeb.Endpoint, action, profile.username)
|
||||
end
|
||||
|
||||
def connection_status(assigns) do
|
||||
|
|
|
@ -2,14 +2,20 @@ defmodule LiveBeatsWeb.Nav do
|
|||
import Phoenix.LiveView
|
||||
|
||||
alias LiveBeats.MediaLibrary
|
||||
alias LiveBeatsWeb.{ProfileLive, SettingsLive}
|
||||
|
||||
def on_mount(:default, params, _session, socket) do
|
||||
active_tab =
|
||||
case params do
|
||||
%{"profile_username" => _profile} -> :index
|
||||
_ -> :settings
|
||||
end
|
||||
case {socket.view, params} do
|
||||
{ProfileLive, %{"profile_username" => _profile}} -> :profile
|
||||
{SettingsLive, _} -> :settings
|
||||
{_, _} -> nil
|
||||
end
|
||||
|
||||
{:cont, assign(socket, [active_users: MediaLibrary.list_active_profiles(limit: 20), active_tab: active_tab])}
|
||||
{:cont,
|
||||
assign(socket,
|
||||
active_users: MediaLibrary.list_active_profiles(limit: 20),
|
||||
active_tab: active_tab
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
defmodule LiveBeatsWeb.SongLive.Index do
|
||||
defmodule LiveBeatsWeb.ProfileLive do
|
||||
use LiveBeatsWeb, :live_view
|
||||
|
||||
alias LiveBeats.{Accounts, MediaLibrary, MP3Stat}
|
||||
alias LiveBeatsWeb.{LayoutComponent, Presence}
|
||||
alias LiveBeatsWeb.SongLive.{SongRowComponent, UploadFormComponent}
|
||||
alias LiveBeatsWeb.ProfileLive.{SongRowComponent, UploadFormComponent}
|
||||
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
|
@ -32,7 +32,7 @@ defmodule LiveBeatsWeb.SongLive.Index do
|
|||
</.button>
|
||||
<% end %>
|
||||
<%= if @owns_profile? do %>
|
||||
<.button primary patch_to={Routes.song_index_path(@socket, :new, @current_user.username)}>
|
||||
<.button primary patch_to={profile_path(@current_user, :new)}>
|
||||
<.icon name={:upload}/><span class="ml-2">Upload Songs</span>
|
||||
</.button>
|
||||
<% end %>
|
|
@ -1,4 +1,4 @@
|
|||
defmodule LiveBeatsWeb.SongLive.SongEntryComponent do
|
||||
defmodule LiveBeatsWeb.ProfileLive.SongEntryComponent do
|
||||
use LiveBeatsWeb, :live_component
|
||||
|
||||
alias LiveBeats.MP3Stat
|
|
@ -1,4 +1,4 @@
|
|||
defmodule LiveBeatsWeb.SongLive.SongRowComponent do
|
||||
defmodule LiveBeatsWeb.ProfileLive.SongRowComponent do
|
||||
use LiveBeatsWeb, :live_component
|
||||
|
||||
def send_status(id, status) when status in [:playing, :paused, :stopped] do
|
|
@ -1,8 +1,8 @@
|
|||
defmodule LiveBeatsWeb.SongLive.UploadFormComponent do
|
||||
defmodule LiveBeatsWeb.ProfileLive.UploadFormComponent do
|
||||
use LiveBeatsWeb, :live_component
|
||||
|
||||
alias LiveBeats.{MediaLibrary, MP3Stat}
|
||||
alias LiveBeatsWeb.SongLive.SongEntryComponent
|
||||
alias LiveBeatsWeb.ProfileLive.SongEntryComponent
|
||||
|
||||
@max_songs 10
|
||||
|
|
@ -54,8 +54,8 @@ defmodule LiveBeatsWeb.Router do
|
|||
|
||||
live_session :authenticated,
|
||||
on_mount: [{LiveBeatsWeb.UserAuth, :ensure_authenticated}, LiveBeatsWeb.Nav] do
|
||||
live "/:profile_username/songs/new", SongLive.Index, :new
|
||||
live "/:profile_username", SongLive.Index, :index
|
||||
live "/:profile_username/songs/new", ProfileLive, :new
|
||||
live "/:profile_username", ProfileLive, :index
|
||||
live "/profile/settings", SettingsLive, :edit
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,7 +33,7 @@ defmodule LiveBeatsWeb.LayoutView do
|
|||
<%= if @current_user do %>
|
||||
<.link
|
||||
redirect_to={profile_path(@current_user)}
|
||||
class={"text-gray-700 hover:text-gray-900 hover:bg-gray-50 group flex items-center px-2 py-2 text-sm font-medium rounded-md #{if @active_tab == :index, do: "bg-gray-200 hover:bg-gray-200"}"}
|
||||
class={"text-gray-700 hover:text-gray-900 hover:bg-gray-50 group flex items-center px-2 py-2 text-sm font-medium rounded-md #{if @active_tab == :profile, do: "bg-gray-200 hover:bg-gray-200"}"}
|
||||
>
|
||||
<.icon name={:music_note} outlined class="text-gray-400 group-hover:text-gray-500 mr-3 flex-shrink-0 h-6 w-6"/>
|
||||
My Songs
|
||||
|
|
|
@ -86,7 +86,7 @@ defmodule LiveBeatsWeb.UserAuthTest do
|
|||
test "redirects if user is not authenticated", %{conn: conn} do
|
||||
conn = conn |> fetch_flash() |> UserAuth.require_authenticated_user([])
|
||||
assert conn.halted
|
||||
assert redirected_to(conn) == Routes.song_index_path(conn, :index)
|
||||
assert redirected_to(conn)
|
||||
assert get_flash(conn, :error) == "You must log in to access this page."
|
||||
end
|
||||
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
defmodule LiveBeatsWeb.SongLiveTest do
|
||||
use LiveBeatsWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import LiveBeats.MediaLibraryFixtures
|
||||
|
||||
@create_attrs %{album_artist: "some album_artist", artist: "some artist", date_recorded: %{day: 26, hour: 20, minute: 11, month: 10, year: 2021}, date_released: %{day: 26, hour: 20, minute: 11, month: 10, year: 2021}, duration: 42, title: "some title"}
|
||||
@update_attrs %{album_artist: "some updated album_artist", artist: "some updated artist", date_recorded: %{day: 27, hour: 20, minute: 11, month: 10, year: 2021}, date_released: %{day: 27, hour: 20, minute: 11, month: 10, year: 2021}, duration: 43, title: "some updated title"}
|
||||
@invalid_attrs %{album_artist: nil, artist: nil, date_recorded: %{day: 30, hour: 20, minute: 11, month: 2, year: 2021}, date_released: %{day: 30, hour: 20, minute: 11, month: 2, year: 2021}, duration: nil, title: nil}
|
||||
|
||||
defp create_song(_) do
|
||||
song = song_fixture()
|
||||
%{song: song}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_song]
|
||||
|
||||
test "lists all songs", %{conn: conn, song: song} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.song_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Listing Songs"
|
||||
assert html =~ song.album_artist
|
||||
end
|
||||
|
||||
test "saves new song", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.song_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "New Song") |> render_click() =~
|
||||
"New Song"
|
||||
|
||||
assert_patch(index_live, Routes.song_index_path(conn, :new))
|
||||
|
||||
assert index_live
|
||||
|> form("#song-form", song: @invalid_attrs)
|
||||
|> render_change() =~ "is invalid"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#song-form", song: @create_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.song_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Song created successfully"
|
||||
assert html =~ "some album_artist"
|
||||
end
|
||||
|
||||
test "updates song in listing", %{conn: conn, song: song} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.song_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#song-#{song.id} a", "Edit") |> render_click() =~
|
||||
"Edit Song"
|
||||
|
||||
assert_patch(index_live, Routes.song_index_path(conn, :edit, song))
|
||||
|
||||
assert index_live
|
||||
|> form("#song-form", song: @invalid_attrs)
|
||||
|> render_change() =~ "is invalid"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#song-form", song: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.song_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Song updated successfully"
|
||||
assert html =~ "some updated album_artist"
|
||||
end
|
||||
|
||||
test "deletes song in listing", %{conn: conn, song: song} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.song_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#song-#{song.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#song-#{song.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_song]
|
||||
|
||||
test "displays song", %{conn: conn, song: song} do
|
||||
{:ok, _show_live, html} = live(conn, Routes.song_show_path(conn, :show, song))
|
||||
|
||||
assert html =~ "Show Song"
|
||||
assert html =~ song.album_artist
|
||||
end
|
||||
|
||||
test "updates song within modal", %{conn: conn, song: song} do
|
||||
{:ok, show_live, _html} = live(conn, Routes.song_show_path(conn, :show, song))
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Song"
|
||||
|
||||
assert_patch(show_live, Routes.song_show_path(conn, :edit, song))
|
||||
|
||||
assert show_live
|
||||
|> form("#song-form", song: @invalid_attrs)
|
||||
|> render_change() =~ "is invalid"
|
||||
|
||||
{:ok, _, html} =
|
||||
show_live
|
||||
|> form("#song-form", song: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.song_show_path(conn, :show, song))
|
||||
|
||||
assert html =~ "Song updated successfully"
|
||||
assert html =~ "some updated album_artist"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue