Skip to content

Commit

Permalink
refactor: Inline <.itinerary_group /> component into TripPlannerResul…
Browse files Browse the repository at this point in the history
…tsSection (#2241)
  • Loading branch information
joshlarson authored Dec 2, 2024
1 parent c184f1a commit 6d85121
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerResultsSection do
use DotcomWeb, :live_component

import DotcomWeb.Components.TripPlanner.{ItineraryDetail, ItinerarySummary}
import DotcomWeb.Components.TripPlanner.ItineraryGroup, only: [itinerary_group: 1]

@impl true
def mount(socket) do
Expand Down Expand Up @@ -75,23 +74,42 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerResultsSection do

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}
/>
<div
:for={{%{summary: summary}, index} <- Enum.with_index(@results)}
class="border border-solid m-4 p-4"
>
<div
:if={summary.tag}
class="whitespace-nowrap leading-none font-bold font-heading text-sm uppercase bg-brand-primary-darkest text-white px-3 py-2 mb-3 -ml-4 -mt-4 rounded-br-lg w-min"
>
<%= summary.tag %>
</div>
<.itinerary_summary summary={summary} />
<div class="flex justify-end items-center">
<div :if={Enum.count(summary.next_starts) > 0} class="grow text-sm text-grey-dark">
Similar trips depart at <%= Enum.map(summary.next_starts, &format_datetime_short/1)
|> Enum.join(", ") %>
</div>
<button
class="btn-link font-semibold underline"
phx-click="set_expanded_itinerary_index"
phx-target={@target}
phx-value-index={index}
>
Details
</button>
</div>
</div>
"""
end

defp itinerary_panel(%{results: results, details_index: details_index} = assigns) do
result = results |> Enum.at(details_index)
%{itineraries: itineraries, summary: summary} = results |> Enum.at(details_index)

assigns =
assigns
|> assign(:itineraries, result |> Map.get(:itineraries))
|> assign(:summary, result |> Map.get(:summary))
|> assign(:itineraries, itineraries)
|> assign(:summary, summary)

~H"""
<div class="mt-30">
Expand All @@ -104,6 +122,17 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerResultsSection do
"""
end

defp itinerary_panel(assigns) do
Sentry.capture_message("Error loading planned trips",
extra: %{assigns: assigns},
tags: %{feature: "Trip Planner"}
)

~H"""
<div>Error loading planned trips</div>
"""
end

@impl true
def handle_event("set_expanded_itinerary_index", %{"index" => index_str}, socket) do
index =
Expand All @@ -114,4 +143,8 @@ defmodule DotcomWeb.Components.LiveComponents.TripPlannerResultsSection do

{:noreply, socket |> assign(:expanded_itinerary_index, index)}
end

defp format_datetime_short(datetime) do
Timex.format!(datetime, "%-I:%M", :strftime)
end
end
61 changes: 0 additions & 61 deletions lib/dotcom_web/components/trip_planner/itinerary_group.ex

This file was deleted.

0 comments on commit 6d85121

Please sign in to comment.