-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Toggle between summary and details view in itinerary panel (#2232)
Co-authored-by: Cristen Jones <cjones3@mbta.com>
- Loading branch information
1 parent
205796d
commit ac6d8ed
Showing
5 changed files
with
226 additions
and
32 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
lib/dotcom_web/components/live_components/trip_planner_results_section.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
defmodule DotcomWeb.Components.LiveComponents.TripPlannerResultsSection do | ||
@moduledoc """ | ||
The section of the trip planner page that shows the map and | ||
the summary or details panel | ||
""" | ||
|
||
use DotcomWeb, :live_component | ||
|
||
import DotcomWeb.Components.TripPlanner.ItineraryDetail | ||
import DotcomWeb.Components.TripPlanner.ItineraryGroup, only: [itinerary_group: 1] | ||
|
||
@impl true | ||
def mount(socket) do | ||
{:ok, socket |> assign(:expanded_itinerary_index, nil)} | ||
end | ||
|
||
@impl true | ||
def render(assigns) do | ||
~H""" | ||
<section class="flex w-full border border-solid border-slate-400"> | ||
<div :if={@error} class="w-full p-4 text-rose-400"> | ||
<%= inspect(@error) %> | ||
</div> | ||
<.async_result :let={results} assign={@results}> | ||
<div :if={results} class="w-full p-4"> | ||
<.itinerary_panel | ||
results={results} | ||
details_index={@expanded_itinerary_index} | ||
target={@myself} | ||
/> | ||
</div> | ||
</.async_result> | ||
<.live_component | ||
module={MbtaMetro.Live.Map} | ||
id="trip-planner-map" | ||
class="h-96 w-full relative overflow-none" | ||
config={@map_config} | ||
pins={[@from, @to]} | ||
/> | ||
</section> | ||
""" | ||
end | ||
|
||
defp itinerary_panel(%{details_index: nil} = assigns) do | ||
~H""" | ||
<.itinerary_group | ||
:for={{result, index} <- Enum.with_index(@results)} | ||
index={index} | ||
details_click_event="set_expanded_itinerary_index" | ||
target={@target} | ||
{result} | ||
/> | ||
""" | ||
end | ||
|
||
defp itinerary_panel(%{results: results, details_index: details_index} = assigns) do | ||
assigns = | ||
assign(assigns, :itineraries, results |> Enum.at(details_index) |> Map.get(:itineraries)) | ||
|
||
~H""" | ||
<div class="mt-30"> | ||
<button | ||
type="button" | ||
phx-click="set_expanded_itinerary_index" | ||
phx-value-index="nil" | ||
phx-target={@target} | ||
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("set_expanded_itinerary_index", %{"index" => index_str}, socket) do | ||
index = | ||
case Integer.parse(index_str) do | ||
{index, ""} -> index | ||
_ -> nil | ||
end | ||
|
||
{:noreply, socket |> assign(:expanded_itinerary_index, index)} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters