Update push_redirect to push_navigate

This commit is contained in:
Alex
2024-04-07 10:27:12 +02:00
parent 3722af506f
commit 3da4c4912d
10 changed files with 135 additions and 134 deletions

View File

@@ -20,7 +20,7 @@ defmodule ClaperWeb.EmbedLive.FormComponent do
embed = Embeds.get_embed!(id) embed = Embeds.get_embed!(id)
{:ok, _} = Embeds.delete_embed(socket.assigns.event_uuid, embed) {:ok, _} = Embeds.delete_embed(socket.assigns.event_uuid, embed)
{:noreply, socket |> push_redirect(to: socket.assigns.return_to)} {:noreply, socket |> push_navigate(to: socket.assigns.return_to)}
end end
@impl true @impl true
@@ -47,7 +47,7 @@ defmodule ClaperWeb.EmbedLive.FormComponent do
{:ok, _embed} -> {:ok, _embed} ->
{:noreply, {:noreply,
socket socket
|> push_redirect(to: socket.assigns.return_to)} |> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)} {:noreply, assign(socket, :changeset, changeset)}
@@ -65,7 +65,7 @@ defmodule ClaperWeb.EmbedLive.FormComponent do
{:noreply, {:noreply,
socket socket
|> maybe_change_current_embed(embed) |> maybe_change_current_embed(embed)
|> push_redirect(to: socket.assigns.return_to)} |> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)} {:noreply, assign(socket, changeset: changeset)}

View File

@@ -74,125 +74,123 @@ defmodule ClaperWeb.EventLive.EventCardComponent do
<% end %> <% end %>
<%= if !Event.finished?(@event) do %> <%= if !Event.finished?(@event) do %>
<%= if @event.presentation_file.status != "progress" do %> <div :if={@event.presentation_file.status == "done"} class="mt-2 flex flex-col space-y-2 sm:space-y-0 justify-between sm:flex-row items-center">
<div class="mt-2 flex flex-col space-y-2 sm:space-y-0 justify-between sm:flex-row items-center"> <div
<div id={"event-infos-#{@event.uuid}"}
id={"event-infos-#{@event.uuid}"} class="text-sm w-full sm:w-auto font-medium text-gray-700 flex justify-center space-x-1 sm:space-y-0 items-center relative"
class="text-sm w-full sm:w-auto font-medium text-gray-700 flex justify-center space-x-1 sm:space-y-0 items-center relative" >
<button
phx-click-away={JS.hide(to: "#dropdown-#{@event.uuid}")}
phx-click={JS.toggle(to: "#dropdown-#{@event.uuid}")}
phx-target={@myself}
class="flex w-full lg:w-auto pl-3 pr-4 text-white items-center justify-between py-2 rounded-md tracking-wide font-bold focus:outline-none focus:shadow-outline hover:bg-primary-600 bg-primary-500"
> >
<button <span class="mr-2"><%= gettext("Access") %></span>
phx-click-away={JS.hide(to: "#dropdown-#{@event.uuid}")} <svg
phx-click={JS.toggle(to: "#dropdown-#{@event.uuid}")} xmlns="http://www.w3.org/2000/svg"
phx-target={@myself} fill="none"
class="flex w-full lg:w-auto pl-3 pr-4 text-white items-center justify-between py-2 rounded-md tracking-wide font-bold focus:outline-none focus:shadow-outline hover:bg-primary-600 bg-primary-500" viewBox="0 0 24 24"
stroke-width="2.5"
stroke="currentColor"
class="w-4 h-4"
> >
<span class="mr-2"><%= gettext("Access") %></span> <path
<svg stroke-linecap="round"
xmlns="http://www.w3.org/2000/svg" stroke-linejoin="round"
fill="none" d="m19.5 8.25-7.5 7.5-7.5-7.5"
viewBox="0 0 24 24" />
stroke-width="2.5" </svg>
stroke="currentColor" </button>
class="w-4 h-4" <div
> phx-hook="Dropdown"
<path id={"dropdown-#{@event.uuid}"}
stroke-linecap="round" class="hidden rounded shadow-lg bg-white border px-2 py-1 absolute -left-1 top-9 w-max"
stroke-linejoin="round" >
d="m19.5 8.25-7.5 7.5-7.5-7.5" <ul>
/> <li>
</svg> <a
</button> data-phx-link="patch"
<div data-phx-link-state="push"
phx-hook="Dropdown" class="py-2 px-2 rounded text-gray-600 hover:bg-gray-100 flex items-center gap-x-2"
id={"dropdown-#{@event.uuid}"} href={~p"/e/#{@event.code}/manage"}
class="hidden rounded shadow-lg bg-white border px-2 py-1 absolute -left-1 top-9 w-max" >
> <svg
<ul> xmlns="http://www.w3.org/2000/svg"
<li> viewBox="0 0 24 24"
<a fill="currentColor"
data-phx-link="patch" class="w-6 h-6"
data-phx-link-state="push"
class="py-2 px-2 rounded text-gray-600 hover:bg-gray-100 flex items-center gap-x-2"
href={~p"/e/#{@event.code}/manage"}
> >
<svg <path
xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd"
viewBox="0 0 24 24" d="M2.25 2.25a.75.75 0 0 0 0 1.5H3v10.5a3 3 0 0 0 3 3h1.21l-1.172 3.513a.75.75 0 0 0 1.424.474l.329-.987h8.418l.33.987a.75.75 0 0 0 1.422-.474l-1.17-3.513H18a3 3 0 0 0 3-3V3.75h.75a.75.75 0 0 0 0-1.5H2.25Zm6.04 16.5.5-1.5h6.42l.5 1.5H8.29Zm7.46-12a.75.75 0 0 0-1.5 0v6a.75.75 0 0 0 1.5 0v-6Zm-3 2.25a.75.75 0 0 0-1.5 0v3.75a.75.75 0 0 0 1.5 0V9Zm-3 2.25a.75.75 0 0 0-1.5 0v1.5a.75.75 0 0 0 1.5 0v-1.5Z"
fill="currentColor" clip-rule="evenodd"
class="w-6 h-6" />
> </svg>
<path <span><%= gettext("Presentation manager") %></span>
fill-rule="evenodd" </a>
d="M2.25 2.25a.75.75 0 0 0 0 1.5H3v10.5a3 3 0 0 0 3 3h1.21l-1.172 3.513a.75.75 0 0 0 1.424.474l.329-.987h8.418l.33.987a.75.75 0 0 0 1.422-.474l-1.17-3.513H18a3 3 0 0 0 3-3V3.75h.75a.75.75 0 0 0 0-1.5H2.25Zm6.04 16.5.5-1.5h6.42l.5 1.5H8.29Zm7.46-12a.75.75 0 0 0-1.5 0v6a.75.75 0 0 0 1.5 0v-6Zm-3 2.25a.75.75 0 0 0-1.5 0v3.75a.75.75 0 0 0 1.5 0V9Zm-3 2.25a.75.75 0 0 0-1.5 0v1.5a.75.75 0 0 0 1.5 0v-1.5Z" </li>
clip-rule="evenodd" <li>
/> <a
</svg> data-phx-link="patch"
<span><%= gettext("Presentation manager") %></span> data-phx-link-state="push"
</a> class="py-2 px-2 rounded text-gray-600 hover:bg-gray-100 flex items-center gap-x-2"
</li> href={~p"/e/#{@event.code}"}
<li> >
<a <svg
data-phx-link="patch" xmlns="http://www.w3.org/2000/svg"
data-phx-link-state="push" viewBox="0 0 24 24"
class="py-2 px-2 rounded text-gray-600 hover:bg-gray-100 flex items-center gap-x-2" fill="currentColor"
href={~p"/e/#{@event.code}"} class="w-6 h-6"
> >
<svg <path
xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd"
viewBox="0 0 24 24" d="M8.25 6.75a3.75 3.75 0 1 1 7.5 0 3.75 3.75 0 0 1-7.5 0ZM15.75 9.75a3 3 0 1 1 6 0 3 3 0 0 1-6 0ZM2.25 9.75a3 3 0 1 1 6 0 3 3 0 0 1-6 0ZM6.31 15.117A6.745 6.745 0 0 1 12 12a6.745 6.745 0 0 1 6.709 7.498.75.75 0 0 1-.372.568A12.696 12.696 0 0 1 12 21.75c-2.305 0-4.47-.612-6.337-1.684a.75.75 0 0 1-.372-.568 6.787 6.787 0 0 1 1.019-4.38Z"
fill="currentColor" clip-rule="evenodd"
class="w-6 h-6" />
> <path d="M5.082 14.254a8.287 8.287 0 0 0-1.308 5.135 9.687 9.687 0 0 1-1.764-.44l-.115-.04a.563.563 0 0 1-.373-.487l-.01-.121a3.75 3.75 0 0 1 3.57-4.047ZM20.226 19.389a8.287 8.287 0 0 0-1.308-5.135 3.75 3.75 0 0 1 3.57 4.047l-.01.121a.563.563 0 0 1-.373.486l-.115.04c-.567.2-1.156.349-1.764.441Z" />
<path </svg>
fill-rule="evenodd" <span><%= gettext("Attendees room") %></span>
d="M8.25 6.75a3.75 3.75 0 1 1 7.5 0 3.75 3.75 0 0 1-7.5 0ZM15.75 9.75a3 3 0 1 1 6 0 3 3 0 0 1-6 0ZM2.25 9.75a3 3 0 1 1 6 0 3 3 0 0 1-6 0ZM6.31 15.117A6.745 6.745 0 0 1 12 12a6.745 6.745 0 0 1 6.709 7.498.75.75 0 0 1-.372.568A12.696 12.696 0 0 1 12 21.75c-2.305 0-4.47-.612-6.337-1.684a.75.75 0 0 1-.372-.568 6.787 6.787 0 0 1 1.019-4.38Z" </a>
clip-rule="evenodd" </li>
/> </ul>
<path d="M5.082 14.254a8.287 8.287 0 0 0-1.308 5.135 9.687 9.687 0 0 1-1.764-.44l-.115-.04a.563.563 0 0 1-.373-.487l-.01-.121a3.75 3.75 0 0 1 3.57-4.047ZM20.226 19.389a8.287 8.287 0 0 0-1.308-5.135 3.75 3.75 0 0 1 3.57 4.047l-.01.121a.563.563 0 0 1-.373.486l-.115.04c-.567.2-1.156.349-1.764.441Z" /> </div>
</svg> <.link
<span><%= gettext("Attendees room") %></span> :if={Event.started?(@event)}
</a> data-confirm={
</li> gettext(
</ul> "Are you sure you want to terminate this event? This action cannot be undone."
</div> )
<.link }
:if={Event.started?(@event)} phx-value-id={@event.uuid}
data-confirm={ phx-click="terminate"
gettext( class="flex w-full lg:w-auto pl-3 pr-4 text-white items-center justify-between py-2 rounded-md tracking-wide font-bold focus:outline-none focus:shadow-outline bg-red-500 hover:bg-red-600 transition"
"Are you sure you want to terminate this event? This action cannot be undone." >
) <svg
} xmlns="http://www.w3.org/2000/svg"
phx-value-id={@event.uuid} fill="none"
phx-click="terminate" viewBox="0 0 24 24"
class="flex w-full lg:w-auto pl-3 pr-4 text-white items-center justify-between py-2 rounded-md tracking-wide font-bold focus:outline-none focus:shadow-outline bg-red-500 hover:bg-red-600 transition" stroke-width="2.5"
stroke="currentColor"
class="w-5 h-5 mr-2"
> >
<svg <path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" />
xmlns="http://www.w3.org/2000/svg" </svg>
fill="none" <span><%= gettext("Terminate") %></span>
viewBox="0 0 24 24" </.link>
stroke-width="2.5"
stroke="currentColor"
class="w-5 h-5 mr-2"
>
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" />
</svg>
<span><%= gettext("Terminate") %></span>
</.link>
</div>
<div>
<%= if not @is_leader do %>
<a
data-phx-link="patch"
data-phx-link-state="push"
href={~p"/events/#{@event.uuid}/edit"}
class="flex w-full lg:w-auto rounded-md tracking-wide focus:outline-none focus:shadow-outline text-primary-500 text-sm items-center"
>
<span><%= gettext("Edit") %></span>
</a>
<% end %>
</div>
</div> </div>
<% end %> <div>
<%= if not @is_leader do %>
<a
data-phx-link="patch"
data-phx-link-state="push"
href={~p"/events/#{@event.uuid}/edit"}
class="flex w-full lg:w-auto rounded-md tracking-wide focus:outline-none focus:shadow-outline text-primary-500 text-sm items-center"
>
<span><%= gettext("Edit") %></span>
</a>
<% end %>
</div>
</div>
<div <div
:if={@event.presentation_file.status == "fail" && is_nil(@event.presentation_file.hash)} :if={@event.presentation_file.status == "fail" && is_nil(@event.presentation_file.hash)}

View File

@@ -165,7 +165,10 @@ defmodule ClaperWeb.EventLive.EventFormComponent do
:new, :new,
event_params event_params
) do ) do
create_event(socket, event_params) case uploaded_entries(socket, :presentation_file) do
{[_ | _], []} -> save_file(socket, event_params, &create_event/4)
_ -> create_event(socket, event_params)
end
end end
defp create_event(socket, event_params) do defp create_event(socket, event_params) do
@@ -192,7 +195,7 @@ defmodule ClaperWeb.EventLive.EventFormComponent do
{:noreply, {:noreply,
socket socket
|> put_flash(:info, gettext("Created successfully")) |> put_flash(:info, gettext("Created successfully"))
|> push_redirect(to: socket.assigns.return_to)} |> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)} {:noreply, assign(socket, changeset: changeset)}
@@ -228,7 +231,7 @@ defmodule ClaperWeb.EventLive.EventFormComponent do
{:noreply, {:noreply,
socket socket
|> put_flash(:info, gettext("Created successfully")) |> put_flash(:info, gettext("Created successfully"))
|> push_redirect(to: socket.assigns.return_to)} |> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)} {:noreply, assign(socket, changeset: changeset)}
@@ -248,7 +251,7 @@ defmodule ClaperWeb.EventLive.EventFormComponent do
{:noreply, {:noreply,
socket socket
|> put_flash(:info, gettext("Updated successfully")) |> put_flash(:info, gettext("Updated successfully"))
|> push_redirect(to: socket.assigns.return_to)} |> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)} {:noreply, assign(socket, :changeset, changeset)}

View File

@@ -71,7 +71,7 @@ defmodule ClaperWeb.EventLive.Index do
{:noreply, {:noreply,
socket socket
|> put_flash(:info, gettext("Quick event created successfully")) |> put_flash(:info, gettext("Quick event created successfully"))
|> push_redirect(to: ~p"/events")} |> push_navigate(to: ~p"/events")}
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, quick_event_changeset: changeset)} {:noreply, assign(socket, quick_event_changeset: changeset)}

View File

@@ -28,7 +28,7 @@ defmodule ClaperWeb.EventLive.Join do
@impl true @impl true
def handle_event("join", %{"event" => %{"code" => code}}, socket) do def handle_event("join", %{"event" => %{"code" => code}}, socket) do
{:noreply, socket |> push_redirect(to: ~p"/e/#{String.downcase(code)}")} {:noreply, socket |> push_navigate(to: ~p"/e/#{String.downcase(code)}")}
end end
defp apply_action(socket, :join, _params) do defp apply_action(socket, :join, _params) do

View File

@@ -642,7 +642,7 @@ defmodule ClaperWeb.EventLive.Manage do
if socket.assigns.create != nil do if socket.assigns.create != nil do
{:noreply, {:noreply,
socket socket
|> push_redirect(to: ~p"/e/#{socket.assigns.event.code}/manage")} |> push_navigate(to: ~p"/e/#{socket.assigns.event.code}/manage")}
else else
{:noreply, socket} {:noreply, socket}
end end

View File

@@ -191,7 +191,7 @@ defmodule ClaperWeb.EventLive.Show do
{:noreply, {:noreply,
socket socket
|> put_flash(:error, gettext("This event has been terminated")) |> put_flash(:error, gettext("This event has been terminated"))
|> push_redirect(to: ~p"/")} |> push_navigate(to: ~p"/")}
end end
@impl true @impl true
@@ -204,7 +204,7 @@ defmodule ClaperWeb.EventLive.Show do
{:noreply, {:noreply,
socket socket
|> put_flash(:error, gettext("You have been banned from this event")) |> put_flash(:error, gettext("You have been banned from this event"))
|> push_redirect(to: ~p"/")} |> push_navigate(to: ~p"/")}
else else
{:noreply, socket} {:noreply, socket}
end end
@@ -219,7 +219,7 @@ defmodule ClaperWeb.EventLive.Show do
{:noreply, {:noreply,
socket socket
|> put_flash(:error, gettext("You have been banned from this event")) |> put_flash(:error, gettext("You have been banned from this event"))
|> push_redirect(to: ~p"/")} |> push_navigate(to: ~p"/")}
else else
{:noreply, socket} {:noreply, socket}
end end

View File

@@ -20,7 +20,7 @@ defmodule ClaperWeb.FormLive.FormComponent do
form = Forms.get_form!(id) form = Forms.get_form!(id)
{:ok, _} = Forms.delete_form(socket.assigns.event_uuid, form) {:ok, _} = Forms.delete_form(socket.assigns.event_uuid, form)
{:noreply, socket |> push_redirect(to: socket.assigns.return_to)} {:noreply, socket |> push_navigate(to: socket.assigns.return_to)}
end end
@impl true @impl true
@@ -65,7 +65,7 @@ defmodule ClaperWeb.FormLive.FormComponent do
{:ok, _form} -> {:ok, _form} ->
{:noreply, {:noreply,
socket socket
|> push_redirect(to: socket.assigns.return_to)} |> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)} {:noreply, assign(socket, :changeset, changeset)}
@@ -83,7 +83,7 @@ defmodule ClaperWeb.FormLive.FormComponent do
{:noreply, {:noreply,
socket socket
|> maybe_change_current_form(form) |> maybe_change_current_form(form)
|> push_redirect(to: socket.assigns.return_to)} |> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)} {:noreply, assign(socket, changeset: changeset)}

View File

@@ -20,7 +20,7 @@ defmodule ClaperWeb.PollLive.FormComponent do
poll = Polls.get_poll!(id) poll = Polls.get_poll!(id)
{:ok, _} = Polls.delete_poll(socket.assigns.event_uuid, poll) {:ok, _} = Polls.delete_poll(socket.assigns.event_uuid, poll)
{:noreply, socket |> push_redirect(to: socket.assigns.return_to)} {:noreply, socket |> push_navigate(to: socket.assigns.return_to)}
end end
@impl true @impl true
@@ -65,7 +65,7 @@ defmodule ClaperWeb.PollLive.FormComponent do
{:ok, _poll} -> {:ok, _poll} ->
{:noreply, {:noreply,
socket socket
|> push_redirect(to: socket.assigns.return_to)} |> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)} {:noreply, assign(socket, :changeset, changeset)}
@@ -83,7 +83,7 @@ defmodule ClaperWeb.PollLive.FormComponent do
{:noreply, {:noreply,
socket socket
|> maybe_change_current_poll(poll) |> maybe_change_current_poll(poll)
|> push_redirect(to: socket.assigns.return_to)} |> push_navigate(to: socket.assigns.return_to)}
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)} {:noreply, assign(socket, changeset: changeset)}

View File

@@ -68,7 +68,7 @@ defmodule ClaperWeb.UserSettingsLive.Show do
:info, :info,
gettext("A link to confirm your email change has been sent to the new address.") gettext("A link to confirm your email change has been sent to the new address.")
) )
|> push_redirect(to: ~p"/users/settings")} |> push_navigate(to: ~p"/users/settings")}
{:error, changeset} -> {:error, changeset} ->
{:noreply, assign(socket, :email_changeset, changeset)} {:noreply, assign(socket, :email_changeset, changeset)}
@@ -90,7 +90,7 @@ defmodule ClaperWeb.UserSettingsLive.Show do
:info, :info,
gettext("Your password has been updated.") gettext("Your password has been updated.")
) )
|> push_redirect(to: ~p"/users/settings")} |> push_navigate(to: ~p"/users/settings")}
{:error, changeset} -> {:error, changeset} ->
{:noreply, assign(socket, :password_changeset, changeset)} {:noreply, assign(socket, :password_changeset, changeset)}