Skip to content

Commit

Permalink
Update push_redirect to push_navigate
Browse files Browse the repository at this point in the history
  • Loading branch information
alxlion committed Apr 7, 2024
1 parent 3722af5 commit 3da4c49
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 134 deletions.
6 changes: 3 additions & 3 deletions lib/claper_web/live/embed_live/form_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule ClaperWeb.EmbedLive.FormComponent do
embed = Embeds.get_embed!(id)
{: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

@impl true
Expand All @@ -47,7 +47,7 @@ defmodule ClaperWeb.EmbedLive.FormComponent do
{:ok, _embed} ->
{:noreply,
socket
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)}
Expand All @@ -65,7 +65,7 @@ defmodule ClaperWeb.EmbedLive.FormComponent do
{:noreply,
socket
|> maybe_change_current_embed(embed)
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)}
Expand Down
224 changes: 111 additions & 113 deletions lib/claper_web/live/event_live/event_card_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,125 +74,123 @@ defmodule ClaperWeb.EventLive.EventCardComponent do
<% end %>
<%= if !Event.finished?(@event) do %>
<%= if @event.presentation_file.status != "progress" do %>
<div class="mt-2 flex flex-col space-y-2 sm:space-y-0 justify-between sm:flex-row items-center">
<div
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"
<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
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"
>
<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
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"
>
<span class="mr-2"><%= gettext("Access") %></span>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.5"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m19.5 8.25-7.5 7.5-7.5-7.5"
/>
</svg>
</button>
<div
phx-hook="Dropdown"
id={"dropdown-#{@event.uuid}"}
class="hidden rounded shadow-lg bg-white border px-2 py-1 absolute -left-1 top-9 w-max"
<span class="mr-2"><%= gettext("Access") %></span>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.5"
stroke="currentColor"
class="w-4 h-4"
>
<ul>
<li>
<a
data-phx-link="patch"
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"}
<path
stroke-linecap="round"
stroke-linejoin="round"
d="m19.5 8.25-7.5 7.5-7.5-7.5"
/>
</svg>
</button>
<div
phx-hook="Dropdown"
id={"dropdown-#{@event.uuid}"}
class="hidden rounded shadow-lg bg-white border px-2 py-1 absolute -left-1 top-9 w-max"
>
<ul>
<li>
<a
data-phx-link="patch"
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
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="currentColor"
class="w-6 h-6"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="currentColor"
class="w-6 h-6"
>
<path
fill-rule="evenodd"
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"
clip-rule="evenodd"
/>
</svg>
<span><%= gettext("Presentation manager") %></span>
</a>
</li>
<li>
<a
data-phx-link="patch"
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}"}
<path
fill-rule="evenodd"
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"
clip-rule="evenodd"
/>
</svg>
<span><%= gettext("Presentation manager") %></span>
</a>
</li>
<li>
<a
data-phx-link="patch"
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}"}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="currentColor"
class="w-6 h-6"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="currentColor"
class="w-6 h-6"
>
<path
fill-rule="evenodd"
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"
clip-rule="evenodd"
/>
<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" />
</svg>
<span><%= gettext("Attendees room") %></span>
</a>
</li>
</ul>
</div>
<.link
:if={Event.started?(@event)}
data-confirm={
gettext(
"Are you sure you want to terminate this event? This action cannot be undone."
)
}
phx-value-id={@event.uuid}
phx-click="terminate"
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"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
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 %>
<path
fill-rule="evenodd"
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"
clip-rule="evenodd"
/>
<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" />
</svg>
<span><%= gettext("Attendees room") %></span>
</a>
</li>
</ul>
</div>
<.link
:if={Event.started?(@event)}
data-confirm={
gettext(
"Are you sure you want to terminate this event? This action cannot be undone."
)
}
phx-value-id={@event.uuid}
phx-click="terminate"
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"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
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>
<% end %>
</div>
<div
:if={@event.presentation_file.status == "fail" && is_nil(@event.presentation_file.hash)}
Expand Down
11 changes: 7 additions & 4 deletions lib/claper_web/live/event_live/event_form_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ defmodule ClaperWeb.EventLive.EventFormComponent do
:new,
event_params
) 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

defp create_event(socket, event_params) do
Expand All @@ -192,7 +195,7 @@ defmodule ClaperWeb.EventLive.EventFormComponent do
{:noreply,
socket
|> put_flash(:info, gettext("Created successfully"))
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)}
Expand Down Expand Up @@ -228,7 +231,7 @@ defmodule ClaperWeb.EventLive.EventFormComponent do
{:noreply,
socket
|> put_flash(:info, gettext("Created successfully"))
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)}
Expand All @@ -248,7 +251,7 @@ defmodule ClaperWeb.EventLive.EventFormComponent do
{:noreply,
socket
|> put_flash(:info, gettext("Updated successfully"))
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)}
Expand Down
2 changes: 1 addition & 1 deletion lib/claper_web/live/event_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule ClaperWeb.EventLive.Index do
{:noreply,
socket
|> put_flash(:info, gettext("Quick event created successfully"))
|> push_redirect(to: ~p"/events")}
|> push_navigate(to: ~p"/events")}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, quick_event_changeset: changeset)}
Expand Down
2 changes: 1 addition & 1 deletion lib/claper_web/live/event_live/join.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule ClaperWeb.EventLive.Join do

@impl true
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

defp apply_action(socket, :join, _params) do
Expand Down
2 changes: 1 addition & 1 deletion lib/claper_web/live/event_live/manage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ defmodule ClaperWeb.EventLive.Manage do
if socket.assigns.create != nil do
{:noreply,
socket
|> push_redirect(to: ~p"/e/#{socket.assigns.event.code}/manage")}
|> push_navigate(to: ~p"/e/#{socket.assigns.event.code}/manage")}
else
{:noreply, socket}
end
Expand Down
6 changes: 3 additions & 3 deletions lib/claper_web/live/event_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ defmodule ClaperWeb.EventLive.Show do
{:noreply,
socket
|> put_flash(:error, gettext("This event has been terminated"))
|> push_redirect(to: ~p"/")}
|> push_navigate(to: ~p"/")}
end

@impl true
Expand All @@ -204,7 +204,7 @@ defmodule ClaperWeb.EventLive.Show do
{:noreply,
socket
|> put_flash(:error, gettext("You have been banned from this event"))
|> push_redirect(to: ~p"/")}
|> push_navigate(to: ~p"/")}
else
{:noreply, socket}
end
Expand All @@ -219,7 +219,7 @@ defmodule ClaperWeb.EventLive.Show do
{:noreply,
socket
|> put_flash(:error, gettext("You have been banned from this event"))
|> push_redirect(to: ~p"/")}
|> push_navigate(to: ~p"/")}
else
{:noreply, socket}
end
Expand Down
6 changes: 3 additions & 3 deletions lib/claper_web/live/form_live/form_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule ClaperWeb.FormLive.FormComponent do
form = Forms.get_form!(id)
{: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

@impl true
Expand Down Expand Up @@ -65,7 +65,7 @@ defmodule ClaperWeb.FormLive.FormComponent do
{:ok, _form} ->
{:noreply,
socket
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)}
Expand All @@ -83,7 +83,7 @@ defmodule ClaperWeb.FormLive.FormComponent do
{:noreply,
socket
|> maybe_change_current_form(form)
|> push_redirect(to: socket.assigns.return_to)}
|> push_navigate(to: socket.assigns.return_to)}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)}
Expand Down
Loading

0 comments on commit 3da4c49

Please sign in to comment.