diff --git a/lib/dotcom_web/components/trip_planner/place.ex b/lib/dotcom_web/components/trip_planner/place.ex index aa6f210ce8..34944880c6 100644 --- a/lib/dotcom_web/components/trip_planner/place.ex +++ b/lib/dotcom_web/components/trip_planner/place.ex @@ -5,9 +5,10 @@ defmodule DotcomWeb.Components.TripPlanner.Place do use DotcomWeb, :component + attr :accessible, :boolean, default: false attr :name, :string, required: true attr :time, :any, required: true - attr :accessible, :boolean, default: false + attr :url, :string, default: nil slot :icon def place(assigns) do @@ -17,27 +18,41 @@ defmodule DotcomWeb.Components.TripPlanner.Place do {render_slot(@icon)} - - {@name} - <.icon - :if={@accessible} - type="icon-svg" - name="icon-accessible-default" - class="h-3 w-3 shrink-0 ml-1.5" - aria-hidden="true" - /> - + <.wrap_with_url url={@url}> + + {@name} + <.icon + :if={@accessible} + type="icon-svg" + name="icon-accessible-default" + class="h-3 w-3 shrink-0 ml-1.5" + aria-hidden="true" + /> + + """ end - # defp stop_url(%Route{external_agency_name: nil}, %Stop{} = stop) do - # ~p"/stops/#{stop}" - # end + attr :url, :string, required: true + slot :inner_block + defp wrap_with_url(assigns) - # defp stop_url(_, _), do: nil + defp wrap_with_url(%{url: nil} = assigns) do + ~H""" + {render_slot(@inner_block)} + """ + end + + defp wrap_with_url(assigns) do + ~H""" + + {render_slot(@inner_block)} + + """ + end defp format_time(datetime), do: Timex.format!(datetime, "%-I:%M %p", :strftime) end diff --git a/lib/dotcom_web/components/trip_planner/start_or_end_place.ex b/lib/dotcom_web/components/trip_planner/start_or_end_place.ex index ccba901d0d..e94babe80c 100644 --- a/lib/dotcom_web/components/trip_planner/start_or_end_place.ex +++ b/lib/dotcom_web/components/trip_planner/start_or_end_place.ex @@ -16,16 +16,6 @@ defmodule DotcomWeb.Components.TripPlanner.StartOrEndPlace do attr :alerts, :list, default: [] def start_or_end_place(assigns) do - # TODO come back to this - - stop_url = stop_url(assigns.route, assigns.place.stop) - - assigns = - assign(assigns, %{ - stop_url: stop_url, - tag_name: if(stop_url, do: "a", else: "div") - }) - ~H"""
<.place name={@place.name} time={@time}> @@ -36,10 +26,4 @@ defmodule DotcomWeb.Components.TripPlanner.StartOrEndPlace do
""" end - - defp stop_url(%Route{external_agency_name: nil}, %Stop{} = stop) do - ~p"/stops/#{stop}" - end - - defp stop_url(_, _), do: nil end diff --git a/lib/dotcom_web/components/trip_planner/transit_leg.ex b/lib/dotcom_web/components/trip_planner/transit_leg.ex index fea15fe393..7a0757ed8e 100644 --- a/lib/dotcom_web/components/trip_planner/transit_leg.ex +++ b/lib/dotcom_web/components/trip_planner/transit_leg.ex @@ -4,7 +4,7 @@ defmodule DotcomWeb.Components.TripPlanner.TransitLeg do Includes styling for the traversed route & a list of intermediate stops. """ - use Phoenix.Component + use DotcomWeb, :component import DotcomWeb.Components.RouteSymbols, only: [route_symbol: 1] import DotcomWeb.Components.TripPlanner.Place @@ -89,6 +89,7 @@ defmodule DotcomWeb.Components.TripPlanner.TransitLeg do time={@time} name={@place.stop.name} accessible={!is_nil(@place.stop) and Stop.accessible?(@place.stop)} + url={stop_url(@route, @place.stop)} > <:icon>
@@ -110,6 +111,12 @@ defmodule DotcomWeb.Components.TripPlanner.TransitLeg do """ end + defp stop_url(%Route{external_agency_name: nil}, %Stop{} = stop) do + ~p"/stops/#{stop}" + end + + defp stop_url(_, _), do: nil + defp leg_line_class(%Route{external_agency_name: "Massport"}) do "bg-massport" end