Skip to content
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

WIP - Make map and results summary sticky #2291

Merged
merged 3 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import geoLocation from "./geolocation";
import addressSearch from "./address-search";
import googleTranslate from "./google-translate";
import translateAnalytics from "./translate-analytics.js";
import scrollTo from "./scroll-to";
import stickyTooltip from "./sticky-tooltip";
import timetableScroll from "./timetable-scroll";
import timetableStyle from "./timetable-style";
Expand Down Expand Up @@ -132,7 +131,6 @@ geoLocation();
addressSearch();
googleTranslate();
translateAnalytics();
scrollTo();
tabbedNav();
timetableScroll();
timetableStyle();
Expand Down
38 changes: 0 additions & 38 deletions assets/js/scroll-to.js

This file was deleted.

5 changes: 5 additions & 0 deletions assets/ts/phoenix-hooks/scroll-into-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const ScrollIntoView: Partial<ViewHook> = {
if (this.el) {
this.el.scrollIntoView({ behavior: "smooth" });
}
},
updated() {
if (this.el) {
this.el.scrollIntoView({ behavior: "smooth" });
}
}
};

Expand Down
6 changes: 5 additions & 1 deletion lib/dotcom_web/components/trip_planner/input_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ defmodule DotcomWeb.Components.TripPlanner.InputForm do

Otherwise, we just render the form.
"""

attr :class, :string, default: ""
attr :changeset, :any, required: true

def input_form(assigns) do
~H"""
<section class="px-10 py-8 lg:px-20 lg:py-12 mb-4 bg-gray-100">
<section class={["px-10 py-8 lg:px-20 lg:py-12 bg-gray-100", @class]}>
<.form
:let={f}
class="md:grid md:grid-cols-2 gap-x-8 gap-y-2"
Expand Down
12 changes: 8 additions & 4 deletions lib/dotcom_web/components/trip_planner/results.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ defmodule DotcomWeb.Components.TripPlanner.Results do

def results(assigns) do
~H"""
<section class={[
"w-full",
@class
]}>
<section
id="trip-planner-results"
phx-hook="ScrollIntoView"
class={[
"w-full",
@class
]}
>
<div
:if={Enum.count(@results.itinerary_groups) > 0 && @results.itinerary_group_selection}
class="h-min w-full mb-3.5"
Expand Down
8 changes: 7 additions & 1 deletion lib/dotcom_web/components/trip_planner/results_summary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ defmodule DotcomWeb.Components.TripPlanner.ResultsSummary do

use DotcomWeb, :component

alias Dotcom.TripPlan.InputForm

attr :changeset, :any, required: true
attr :class, :string, default: ""
attr :results, :any, required: true

def results_summary(assigns) do
~H"""
<section
:if={
@results.loading? || Enum.count(@results.itinerary_groups) > 0 ||
(@changeset.action && @changeset.valid?)
}
class="mt-2 mb-6"
class={@class}
>
<p class="text-lg font-semibold mb-0">{submission_summary(@changeset.changes)}</p>
<p>{time_summary(@changeset.changes)}</p>
Expand Down
52 changes: 27 additions & 25 deletions lib/dotcom_web/live/trip_planner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,33 @@ defmodule DotcomWeb.Live.TripPlanner do
def render(assigns) do
~H"""
<h1>Trip Planner <mark style="font-weight: 400">Preview</mark></h1>
<div style="row">
<.input_form changeset={@input_form.changeset} />
<.results_summary changeset={@input_form.changeset} results={@results} />
<div class={[
"flex flex-col gap-4 md:flex-row md:gap-7"
]}>
<.live_component
module={MbtaMetro.Live.Map}
id="trip-planner-map"
class={[
"md:order-last",
"h-64 md:h-[32rem] w-full",
@results.itinerary_group_selection == nil && "hidden md:block",
@results.itinerary_group_selection != nil && "block"
]}
config={@map.config}
lines={@map.lines}
pins={@map.pins}
points={@map.points}
/>
<.results
:if={Enum.count(@results.itinerary_groups) > 0}
class="md:max-w-[25rem]"
results={@results}
/>
<div>
<.input_form class="mb-4" changeset={@input_form.changeset} />
<div>
<.results_summary class="mt-2 mb-6" changeset={@input_form.changeset} results={@results} />
<div class={[
"flex flex-col gap-4 md:flex-row md:gap-7"
]}>
<.live_component
module={MbtaMetro.Live.Map}
id="trip-planner-map"
class={[
"md:order-last md:sticky md:top-4",
"h-64 md:h-[32rem] w-full",
@results.itinerary_group_selection == nil && "hidden md:block",
@results.itinerary_group_selection != nil && "block"
]}
config={@map.config}
lines={@map.lines}
pins={@map.pins}
points={@map.points}
/>
<.results
:if={Enum.count(@results.itinerary_groups) > 0}
class="md:max-w-[25rem] md:sticky md:top-4"
results={@results}
/>
</div>
</div>
</div>
"""
Expand Down
Loading