-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Toggle between summary and details view in itinerary panel #2232
base: main
Are you sure you want to change the base?
Changes from 1 commit
feb0141
c62bc3c
7227668
8505bc5
47fc2ed
340ac26
68e225b
bf1fae7
38a1b26
2608adf
925af40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ defmodule DotcomWeb.Live.TripPlanner do | |
|
||
use DotcomWeb, :live_view | ||
|
||
import DotcomWeb.Components.TripPlanner.ItineraryDetail | ||
import DotcomWeb.Components.TripPlanner.ItineraryGroup, only: [itinerary_group: 1] | ||
import MbtaMetro.Components.{Feedback, Spinner} | ||
|
||
|
@@ -28,6 +29,7 @@ defmodule DotcomWeb.Live.TripPlanner do | |
|> assign(:from, []) | ||
|> assign(:to, []) | ||
|> assign(:submitted_values, nil) | ||
|> assign(:itinerary_details_index, nil) | ||
|> assign_async(:results, fn -> | ||
{:ok, %{results: nil}} | ||
end) | ||
|
@@ -73,7 +75,7 @@ defmodule DotcomWeb.Live.TripPlanner do | |
</div> | ||
<.async_result :let={results} assign={@results}> | ||
<div :if={results} class="w-full p-4"> | ||
<.itinerary_group :for={result <- results} {result} /> | ||
<.itinerary_panel results={results} details_index={@itinerary_details_index} /> | ||
</div> | ||
</.async_result> | ||
<.live_component | ||
|
@@ -88,7 +90,65 @@ defmodule DotcomWeb.Live.TripPlanner do | |
""" | ||
end | ||
|
||
defp itinerary_panel(%{details_index: details_index} = assigns) do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I want to pull The one complicating factor is the map, since on mobile the map gets rendered in the middle of the details panel. That complicating factor is why I left it like this in this PR, but I sort of do want to figure out at least some strategy for this before merging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wound up pulling out |
||
case details_index do | ||
nil -> | ||
~H""" | ||
<.itinerary_panel_with_all_results results={@results} /> | ||
""" | ||
|
||
_ -> | ||
~H""" | ||
<.itinerary_panel_with_specific_result results={@results} details_index={@details_index} /> | ||
""" | ||
end | ||
end | ||
|
||
defp itinerary_panel_with_all_results(assigns) do | ||
~H""" | ||
<.itinerary_group :for={{result, index} <- Enum.with_index(@results)} index={index} {result} /> | ||
""" | ||
end | ||
|
||
defp itinerary_panel_with_specific_result( | ||
%{results: results, details_index: details_index} = assigns | ||
) do | ||
assigns = | ||
assigns | ||
|> assign( | ||
:itineraries, | ||
results | ||
|> Enum.at(details_index) | ||
|> Map.get(:itineraries) | ||
) | ||
|
||
~H""" | ||
<div class="mt-30"> | ||
<button type="button" phx-click="show_itinerary_summary" class="btn-link"> | ||
<p class="flex flex-row items-center"> | ||
<.icon class="fill-brand-primary h-4 mr-2" name="chevron-left" /> | ||
<span class="font-medium">View All Options</span> | ||
</p> | ||
</button> | ||
<.itinerary_detail :for={itinerary <- @itineraries} itinerary={itinerary} /> | ||
</div> | ||
""" | ||
end | ||
|
||
@impl true | ||
def handle_event("show_itinerary_details" = event, %{"index" => index_str} = params, socket) do | ||
dbg(event) | ||
joshlarson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dbg(params) | ||
|
||
{index, ""} = Integer.parse(index_str) | ||
|
||
{:noreply, socket |> assign(:itinerary_details_index, index)} | ||
end | ||
|
||
def handle_event("show_itinerary_summary", _params, socket) do | ||
{:noreply, socket |> assign(:itinerary_details_index, nil)} | ||
end | ||
|
||
def handle_event(_event, _params, socket) do | ||
{:noreply, socket} | ||
end | ||
|
@@ -112,7 +172,10 @@ defmodule DotcomWeb.Live.TripPlanner do | |
|> assign_async(:results, fn -> | ||
case Dotcom.TripPlan.OpenTripPlanner.plan(data) do | ||
{:ok, itineraries} -> | ||
{:ok, %{results: ItineraryGroups.from_itineraries(itineraries)}} | ||
{:ok, | ||
%{ | ||
results: ItineraryGroups.from_itineraries(itineraries) | ||
}} | ||
|
||
error -> | ||
error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In react-land, this would be a callback that would be explicitly passed into this component -
onDetailsClick
or something like that. I feel like we need some analogous strategy for that here, because I really don't like having"show_itinerary_details"
being hard-coded in both this file andtrip_planner.ex
.Do you have any suggestions? I can also experiment before merging, maybe by passing in a
phx-details-click
assign
or something like that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://hexdocs.pm/phoenix_live_view/Phoenix.LiveComponent.html#module-unifying-liveview-and-livecomponent-communication
☝️ this seems like a promising idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha, I was going to link to this exact doc! can totally do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't end up passing in a callback because
itinerary_group
isn't a live component (pretty sure only live components can do anything meaningful with callbacks?). I did passdetails_click_event
andtarget
in as assigns, which sort of accomplishes the same goal.