Skip to content

Commit

Permalink
refactor: upgrade TNM input to AutocompleteJSv1 (#2041)
Browse files Browse the repository at this point in the history
* refactor: upgrade TNM input to AutocompleteJSv1

* update Playwright test
  • Loading branch information
thecristen authored May 14, 2024
1 parent 09fbe54 commit 5f97417
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 204 deletions.
3 changes: 2 additions & 1 deletion assets/css/_autocomplete-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@
}

#proposed-sales-locations,
#sales-locations {
#sales-locations,
#transit-near-me-locations {
@extend %large-autocomplete;

.c-search-bar__autocomplete-results {
Expand Down
49 changes: 0 additions & 49 deletions assets/ts/tnm/__tests__/transit-near-me-search_test.ts

This file was deleted.

97 changes: 0 additions & 97 deletions assets/ts/tnm/search.ts

This file was deleted.

22 changes: 1 addition & 21 deletions assets/ts/tnm/transit-near-me-loader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import ReactDOM from "react-dom";
import { MapData } from "../leaflet/components/__mapdata";
import TransitNearMeSearch from "./search";
import TransitNearMe from "./components/TransitNearMe";
import { parseQuery } from "../helpers/query";

Expand Down Expand Up @@ -30,27 +29,8 @@ const render = (): void => {
);
};

const renderMap = (): void => {
render();
};

const setupSearch = (): void => {
const el = document.getElementById(TransitNearMeSearch.SELECTORS.container);
if (el) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
search = new TransitNearMeSearch();
}
};

export interface GeolocationData extends CustomEvent {
data: {
url: string;
};
}

export const onLoad = (): void => {
renderMap();
setupSearch();
render();
};

export default onLoad;
5 changes: 4 additions & 1 deletion assets/ts/ui/autocomplete/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ function getLikelyQueryParams(): string | undefined {
window.location.search,
window.decodeURIComponent
);
return searchParams.query || searchParams.name || searchParams.address;
const { query, name, address, latitude, longitude } = searchParams;
const latlon =
latitude && longitude ? `${latitude}, ${longitude}` : undefined;
return query || name || address || latlon;
}

/**
Expand Down
11 changes: 7 additions & 4 deletions integration/scenarios/find-transit-near-me.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ exports.scenario = async ({ page, baseURL }) => {
await page.goto(`${baseURL}/transit-near-me`);

await page
.locator("input#search-transit-near-me__input")
.pressSequentially("Boston City Hall");
await page.waitForSelector("div.c-search-bar__-dataset-locations");
await page.locator("a.c-search-result__link").first().click();
.getByPlaceholder('Enter a location')
.pressSequentially('Boston City Hall');

await page.locator("#search-locations-list[role='listbox']")
.getByRole("option")
.first()
.click();

await page.waitForSelector("div.m-tnm-sidebar__route");
await expect
Expand Down
22 changes: 0 additions & 22 deletions lib/dotcom_web/templates/transit_near_me/_input.html.eex

This file was deleted.

12 changes: 12 additions & 0 deletions lib/dotcom_web/templates/transit_near_me/_input.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h2 class="h5">Find nearby stops and stations</h2>
<div class="m-transit-near-me__input">
<.algolia_autocomplete
id="transit-near-me-locations"
geolocation={true}
locations_count={5}
locations_url_type="transit-near-me"
placeholder="Enter a location"
submit_handler={nil}
initial_state={true}
/>
</div>
9 changes: 0 additions & 9 deletions lib/dotcom_web/views/transit_near_me_view.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule DotcomWeb.TransitNearMeView do
use DotcomWeb, :view
alias LocationService.Address
alias Phoenix.HTML
alias Dotcom.React

Expand All @@ -27,12 +26,4 @@ defmodule DotcomWeb.TransitNearMeView do
}
)
end

defp input_value({:ok, [%Address{formatted: address}]}) do
address
end

defp input_value(_) do
""
end
end

0 comments on commit 5f97417

Please sign in to comment.