Skip to content

Commit

Permalink
fix: Restore stop URL links
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlarson committed Dec 18, 2024
1 parent 732984f commit 2a4cfb0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
45 changes: 30 additions & 15 deletions lib/dotcom_web/components/trip_planner/place.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,27 +18,41 @@ defmodule DotcomWeb.Components.TripPlanner.Place do
{render_slot(@icon)}
</div>
<strong class="text-sm">
{@name}
<.icon
:if={@accessible}
type="icon-svg"
name="icon-accessible-default"
class="h-3 w-3 shrink-0 ml-1.5"
aria-hidden="true"
/>
</strong>
<.wrap_with_url url={@url}>
<strong class="text-sm">
{@name}
<.icon
:if={@accessible}
type="icon-svg"
name="icon-accessible-default"
class="h-3 w-3 shrink-0 ml-1.5"
aria-hidden="true"
/>
</strong>
</.wrap_with_url>
<time class="ml-auto text-right text-sm text-nowrap">{format_time(@time)}</time>
</div>
"""
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"""
<a class="hover:no-underline text-black leading-5" href={@url} target="_blank">
{render_slot(@inner_block)}
</a>
"""
end

defp format_time(datetime), do: Timex.format!(datetime, "%-I:%M %p", :strftime)
end
16 changes: 0 additions & 16 deletions lib/dotcom_web/components/trip_planner/start_or_end_place.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
<div class="bg-gray-bordered-background rounded-lg p-3">
<.place name={@place.name} time={@time}>
Expand All @@ -36,10 +26,4 @@ defmodule DotcomWeb.Components.TripPlanner.StartOrEndPlace do
</div>
"""
end

defp stop_url(%Route{external_agency_name: nil}, %Stop{} = stop) do
~p"/stops/#{stop}"
end

defp stop_url(_, _), do: nil
end
9 changes: 8 additions & 1 deletion lib/dotcom_web/components/trip_planner/transit_leg.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>
<div class="h-5 w-5">
Expand All @@ -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
Expand Down

0 comments on commit 2a4cfb0

Please sign in to comment.