mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-22 08:01:00 +00:00
Fix bad url recovery
This commit is contained in:
parent
0ef460675c
commit
d1f57d7514
2 changed files with 28 additions and 23 deletions
|
@ -32,7 +32,7 @@ defmodule LiveBeatsWeb.SongLive.Index do
|
||||||
</.button>
|
</.button>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= if @owns_profile? do %>
|
<%= if @owns_profile? do %>
|
||||||
<.button primary patch_to={Routes.song_index_path(@socket, :new)}>
|
<.button primary patch_to={Routes.song_index_path(@socket, :new, @current_user.username)}>
|
||||||
<.icon name={:upload}/><span class="ml-2">Upload Songs</span>
|
<.icon name={:upload}/><span class="ml-2">Upload Songs</span>
|
||||||
</.button>
|
</.button>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -106,7 +106,8 @@ defmodule LiveBeatsWeb.SongLive.Index do
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_params(params, _url, socket) do
|
def handle_params(params, _url, socket) do
|
||||||
{:noreply, socket |> apply_action(socket.assigns.live_action, params) |> maybe_show_modal()}
|
LayoutComponent.hide_modal()
|
||||||
|
{:noreply, socket |> apply_action(socket.assigns.live_action, params)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event("play_or_pause", %{"id" => id}, socket) do
|
def handle_event("play_or_pause", %{"id" => id}, socket) do
|
||||||
|
@ -196,8 +197,26 @@ defmodule LiveBeatsWeb.SongLive.Index do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_show_modal(socket) do
|
defp apply_action(socket, :new, _params) do
|
||||||
if socket.assigns.live_action in [:new] do
|
if socket.assigns.owns_profile? do
|
||||||
|
socket
|
||||||
|
|> assign(:page_title, "Add Songs")
|
||||||
|
|> assign(:song, %MediaLibrary.Song{})
|
||||||
|
|> show_upload_modal()
|
||||||
|
else
|
||||||
|
socket
|
||||||
|
|> put_flash(:error, "You can't do that")
|
||||||
|
|> redirect(to: profile_path(socket.assigns.current_user))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp apply_action(socket, :index, _params) do
|
||||||
|
socket
|
||||||
|
|> assign(:page_title, "Listing Songs")
|
||||||
|
|> assign(:song, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp show_upload_modal(socket) do
|
||||||
LayoutComponent.show_modal(UploadFormComponent, %{
|
LayoutComponent.show_modal(UploadFormComponent, %{
|
||||||
id: :new,
|
id: :new,
|
||||||
confirm: {"Save", type: "submit", form: "song-form"},
|
confirm: {"Save", type: "submit", form: "song-form"},
|
||||||
|
@ -206,25 +225,10 @@ defmodule LiveBeatsWeb.SongLive.Index do
|
||||||
title: socket.assigns.page_title,
|
title: socket.assigns.page_title,
|
||||||
current_user: socket.assigns.current_user
|
current_user: socket.assigns.current_user
|
||||||
})
|
})
|
||||||
else
|
|
||||||
LayoutComponent.hide_modal()
|
|
||||||
end
|
|
||||||
|
|
||||||
socket
|
socket
|
||||||
end
|
end
|
||||||
|
|
||||||
defp apply_action(socket, :new, _params) do
|
|
||||||
socket
|
|
||||||
|> assign(:page_title, "Add Songs")
|
|
||||||
|> assign(:song, %MediaLibrary.Song{})
|
|
||||||
end
|
|
||||||
|
|
||||||
defp apply_action(socket, :index, _params) do
|
|
||||||
socket
|
|
||||||
|> assign(:page_title, "Listing Songs")
|
|
||||||
|> assign(:song, nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp list_songs(socket) do
|
defp list_songs(socket) do
|
||||||
assign(socket, songs: MediaLibrary.list_profile_songs(socket.assigns.profile, 50))
|
assign(socket, songs: MediaLibrary.list_profile_songs(socket.assigns.profile, 50))
|
||||||
end
|
end
|
||||||
|
@ -235,6 +239,7 @@ defmodule LiveBeatsWeb.SongLive.Index do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp url_text(nil), do: ""
|
defp url_text(nil), do: ""
|
||||||
|
|
||||||
defp url_text(url_str) do
|
defp url_text(url_str) do
|
||||||
uri = URI.parse(url_str)
|
uri = URI.parse(url_str)
|
||||||
uri.host <> uri.path
|
uri.host <> uri.path
|
||||||
|
|
|
@ -54,7 +54,7 @@ defmodule LiveBeatsWeb.Router do
|
||||||
|
|
||||||
live_session :authenticated,
|
live_session :authenticated,
|
||||||
on_mount: [{LiveBeatsWeb.UserAuth, :ensure_authenticated}, LiveBeatsWeb.Nav] do
|
on_mount: [{LiveBeatsWeb.UserAuth, :ensure_authenticated}, LiveBeatsWeb.Nav] do
|
||||||
live "/songs/new", SongLive.Index, :new
|
live "/:profile_username/songs/new", SongLive.Index, :new
|
||||||
live "/:profile_username", SongLive.Index, :index
|
live "/:profile_username", SongLive.Index, :index
|
||||||
live "/profile/settings", SettingsLive, :edit
|
live "/profile/settings", SettingsLive, :edit
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue