From bb23d8e071960052de9dcca3f96560bc024daaa8 Mon Sep 17 00:00:00 2001 From: Chris McCord Date: Mon, 22 Nov 2021 09:57:24 -0500 Subject: [PATCH] Rename SongLive modules to ProfileLive --- lib/live_beats_web/live/live_helpers.ex | 10 +- lib/live_beats_web/live/nav.ex | 16 ++- .../{song_live/index.ex => profile_live.ex} | 6 +- .../song_entry_component.ex | 2 +- .../song_row_component.ex | 2 +- .../upload_form_component.ex | 4 +- .../upload_form_component.html.heex | 0 lib/live_beats_web/router.ex | 4 +- lib/live_beats_web/views/layout_view.ex | 2 +- .../controllers/user_auth_test.exs | 2 +- test/live_beats_web/live/song_live_test.exs | 110 ------------------ 11 files changed, 28 insertions(+), 130 deletions(-) rename lib/live_beats_web/live/{song_live/index.ex => profile_live.ex} (97%) rename lib/live_beats_web/live/{song_live => profile_live}/song_entry_component.ex (98%) rename lib/live_beats_web/live/{song_live => profile_live}/song_row_component.ex (97%) rename lib/live_beats_web/live/{song_live => profile_live}/upload_form_component.ex (98%) rename lib/live_beats_web/live/{song_live => profile_live}/upload_form_component.html.heex (100%) delete mode 100644 test/live_beats_web/live/song_live_test.exs diff --git a/lib/live_beats_web/live/live_helpers.ex b/lib/live_beats_web/live/live_helpers.ex index 109c3ef..290345e 100644 --- a/lib/live_beats_web/live/live_helpers.ex +++ b/lib/live_beats_web/live/live_helpers.ex @@ -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 diff --git a/lib/live_beats_web/live/nav.ex b/lib/live_beats_web/live/nav.ex index aa89f05..57bd0a5 100644 --- a/lib/live_beats_web/live/nav.ex +++ b/lib/live_beats_web/live/nav.ex @@ -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 diff --git a/lib/live_beats_web/live/song_live/index.ex b/lib/live_beats_web/live/profile_live.ex similarity index 97% rename from lib/live_beats_web/live/song_live/index.ex rename to lib/live_beats_web/live/profile_live.ex index 84d5026..a9a8349 100644 --- a/lib/live_beats_web/live/song_live/index.ex +++ b/lib/live_beats_web/live/profile_live.ex @@ -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 <% 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}/>Upload Songs <% end %> diff --git a/lib/live_beats_web/live/song_live/song_entry_component.ex b/lib/live_beats_web/live/profile_live/song_entry_component.ex similarity index 98% rename from lib/live_beats_web/live/song_live/song_entry_component.ex rename to lib/live_beats_web/live/profile_live/song_entry_component.ex index a2d2d1b..3458d80 100644 --- a/lib/live_beats_web/live/song_live/song_entry_component.ex +++ b/lib/live_beats_web/live/profile_live/song_entry_component.ex @@ -1,4 +1,4 @@ -defmodule LiveBeatsWeb.SongLive.SongEntryComponent do +defmodule LiveBeatsWeb.ProfileLive.SongEntryComponent do use LiveBeatsWeb, :live_component alias LiveBeats.MP3Stat diff --git a/lib/live_beats_web/live/song_live/song_row_component.ex b/lib/live_beats_web/live/profile_live/song_row_component.ex similarity index 97% rename from lib/live_beats_web/live/song_live/song_row_component.ex rename to lib/live_beats_web/live/profile_live/song_row_component.ex index 5074efb..f1184f6 100644 --- a/lib/live_beats_web/live/song_live/song_row_component.ex +++ b/lib/live_beats_web/live/profile_live/song_row_component.ex @@ -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 diff --git a/lib/live_beats_web/live/song_live/upload_form_component.ex b/lib/live_beats_web/live/profile_live/upload_form_component.ex similarity index 98% rename from lib/live_beats_web/live/song_live/upload_form_component.ex rename to lib/live_beats_web/live/profile_live/upload_form_component.ex index f5520d7..de9dee4 100644 --- a/lib/live_beats_web/live/song_live/upload_form_component.ex +++ b/lib/live_beats_web/live/profile_live/upload_form_component.ex @@ -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 diff --git a/lib/live_beats_web/live/song_live/upload_form_component.html.heex b/lib/live_beats_web/live/profile_live/upload_form_component.html.heex similarity index 100% rename from lib/live_beats_web/live/song_live/upload_form_component.html.heex rename to lib/live_beats_web/live/profile_live/upload_form_component.html.heex diff --git a/lib/live_beats_web/router.ex b/lib/live_beats_web/router.ex index 8929233..d59476e 100644 --- a/lib/live_beats_web/router.ex +++ b/lib/live_beats_web/router.ex @@ -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 diff --git a/lib/live_beats_web/views/layout_view.ex b/lib/live_beats_web/views/layout_view.ex index 727edc6..ba3a056 100644 --- a/lib/live_beats_web/views/layout_view.ex +++ b/lib/live_beats_web/views/layout_view.ex @@ -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 diff --git a/test/live_beats_web/controllers/user_auth_test.exs b/test/live_beats_web/controllers/user_auth_test.exs index c13f5de..afe7679 100644 --- a/test/live_beats_web/controllers/user_auth_test.exs +++ b/test/live_beats_web/controllers/user_auth_test.exs @@ -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 diff --git a/test/live_beats_web/live/song_live_test.exs b/test/live_beats_web/live/song_live_test.exs deleted file mode 100644 index b0d6cfe..0000000 --- a/test/live_beats_web/live/song_live_test.exs +++ /dev/null @@ -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