Skip to content

Commit

Permalink
chore: adjusted report card edit UX
Browse files Browse the repository at this point in the history
keep the current tab when editing report card overlay
  • Loading branch information
endoooo committed Mar 8, 2024
1 parent 9c06897 commit a2cbfd2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
32 changes: 11 additions & 21 deletions lib/lanttern_web/live/pages/report_cards/id/report_card_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,10 @@ defmodule LantternWeb.ReportCardLive do
# lifecycle

@impl true
def mount(params, _session, socket) do
socket =
socket
|> maybe_redirect(params)

def mount(_params, _session, socket) do
{:ok, socket, layout: {LantternWeb.Layouts, :app_logged_in_blank}}
end

# prevent user from navigating directly to nested views

defp maybe_redirect(%{assigns: %{live_action: :edit}} = socket, params),
do: redirect(socket, to: ~p"/report_cards/#{params["id"]}?tab=students")

defp maybe_redirect(%{assigns: %{live_action: :edit_strand_report}} = socket, params),
do: redirect(socket, to: ~p"/report_cards/#{params["id"]}?tab=strands")

defp maybe_redirect(socket, _params), do: socket

@impl true
def handle_params(%{"id" => id} = params, _url, socket) do
socket =
Expand All @@ -46,20 +32,24 @@ defmodule LantternWeb.ReportCardLive do
|> assign_new(:report_card, fn ->
Reporting.get_report_card!(id, preloads: [:school_cycle, :year])
end)
|> set_current_tab(params, socket.assigns.live_action)
|> assign_current_tab(params)
|> assign_is_editing(params)

{:noreply, socket}
end

defp set_current_tab(socket, _params, :edit_strand_report),
do: assign(socket, :current_tab, @tabs["strands"])

defp set_current_tab(socket, %{"tab" => tab}, _live_action),
defp assign_current_tab(socket, %{"tab" => tab}),
do: assign(socket, :current_tab, Map.get(@tabs, tab, :students))

defp set_current_tab(socket, _params, _live_action),
defp assign_current_tab(socket, _params),
do: assign(socket, :current_tab, :students)

defp assign_is_editing(socket, %{"is_editing" => "true"}),
do: assign(socket, :is_editing, true)

defp assign_is_editing(socket, _),
do: assign(socket, :is_editing, false)

# event handlers

@impl true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
<:menu_items>
<.menu_button_item
id={"edit-report-card-#{@report_card.id}"}
phx-click={JS.patch(~p"/report_cards/#{@report_card}/edit")}
phx-click={
JS.patch(~p"/report_cards/#{@report_card}?tab=#{@current_tab}&is_editing=true")
}
>
<%= gettext("Edit report card") %>
</.menu_button_item>
Expand Down Expand Up @@ -88,17 +90,17 @@
/>
</div>
<.slide_over
:if={@live_action == :edit}
:if={@is_editing}
id="report-card-form-overlay"
show={true}
on_cancel={JS.patch(~p"/report_cards/#{@report_card}")}
on_cancel={JS.patch(~p"/report_cards/#{@report_card}?tab=#{@current_tab}")}
>
<:title><%= gettext("Edit card") %></:title>
<.live_component
module={ReportCardFormComponent}
id={@report_card.id}
report_card={@report_card}
navigate={~p"/report_cards/#{@report_card}"}
navigate={~p"/report_cards/#{@report_card}?tab=#{@current_tab}"}
hide_submit
/>
<:actions>
Expand Down
1 change: 0 additions & 1 deletion lib/lanttern_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ defmodule LantternWeb.Router do
live "/report_cards", ReportCardsLive, :index
live "/report_cards/new", ReportCardsLive, :new
live "/report_cards/:id", ReportCardLive, :show
live "/report_cards/:id/edit", ReportCardLive, :edit

live "/student_report_card/:id", StudentReportCardLive, :show

Expand Down

0 comments on commit a2cbfd2

Please sign in to comment.