- {PLACE_TYPES.map((type) => {
- const active = selected.includes(type);
- const color = PLACE_TYPE_COLORS[type];
- return (
+
+ {onClear && selected.length > 0 && (
+
+
+ {selected.length} {selected.length === 1 ? "category" : "categories"} selected
+
- );
- })}
+
+ )}
+
+ {onSetTypes && (
+ PLACE_TYPE_LABELS[type]).join(" + ")}
+ count={examCount}
+ onClick={() => onSetTypes(examActive ? [] : [...EXAM_COMBO])}
+ />
+ )}
+ {PLACE_TYPES.map((type) => (
+ onToggle(type)}
+ />
+ ))}
+
);
}
+
+function Chip({
+ active,
+ color,
+ label,
+ title,
+ count,
+ onClick,
+}: {
+ active: boolean;
+ color: string;
+ label: string;
+ title?: string;
+ count: number;
+ onClick: () => void;
+}) {
+ return (
+
+ );
+}
diff --git a/src/components/map/filter-presets.test.tsx b/src/components/map/filter-presets.test.tsx
deleted file mode 100644
index 1d52bd1..0000000
--- a/src/components/map/filter-presets.test.tsx
+++ /dev/null
@@ -1,42 +0,0 @@
-import { cleanup, fireEvent, render, screen } from "@testing-library/react";
-import { afterEach, describe, expect, it, vi } from "vitest";
-
-import { FilterPresets } from "@/components/map/filter-presets";
-
-afterEach(cleanup);
-
-describe("FilterPresets", () => {
- it("lists the preset buttons in a labelled group", () => {
- render(
);
-
- const group = screen.getByRole("group", { name: "Filter presets" });
- expect(group).toBeTruthy();
- for (const label of [
- "Libraries",
- "SAT centres",
- "Exam centres",
- "Govt offices",
- "Airports",
- ]) {
- expect(screen.getByRole("button", { name: label })).toBeTruthy();
- }
- });
-
- it("applies one type for a single-type preset", () => {
- const onApply = vi.fn();
- render(
);
-
- fireEvent.click(screen.getByRole("button", { name: "Airports" }));
-
- expect(onApply).toHaveBeenCalledWith(["airport"]);
- });
-
- it("applies both exam types for the Exam centres preset", () => {
- const onApply = vi.fn();
- render(
);
-
- fireEvent.click(screen.getByRole("button", { name: "Exam centres" }));
-
- expect(onApply).toHaveBeenCalledWith(["sat_centre", "foreign_lang_exam_centre"]);
- });
-});
diff --git a/src/components/map/filter-presets.tsx b/src/components/map/filter-presets.tsx
deleted file mode 100644
index 22d6c92..0000000
--- a/src/components/map/filter-presets.tsx
+++ /dev/null
@@ -1,68 +0,0 @@
-"use client";
-
-import { ClipboardCheck, GraduationCap, Landmark, Library, Plane } from "lucide-react";
-import type { LucideIcon } from "lucide-react";
-
-import type { PlaceType } from "@/lib/types";
-import { Button } from "@/components/ui/button";
-import { cn } from "@/lib/utils";
-
-interface FilterPreset {
- label: string;
- types: PlaceType[];
- icon: LucideIcon;
-}
-
-/**
- * Common filter combos, built from the real `PlaceType`s only (no invented
- * categories). "Exam centres" is the one combo that spans two types -
- * SAT and foreign-language exam centres are both "somewhere a student sits
- * a timed exam", which is a distinct use case from a single-type filter.
- */
-const FILTER_PRESETS: FilterPreset[] = [
- { label: "Libraries", types: ["library"], icon: Library },
- { label: "SAT centres", types: ["sat_centre"], icon: GraduationCap },
- {
- label: "Exam centres",
- types: ["sat_centre", "foreign_lang_exam_centre"],
- icon: ClipboardCheck,
- },
- { label: "Govt offices", types: ["gov_offices"], icon: Landmark },
- { label: "Airports", types: ["airport"], icon: Plane },
-];
-
-interface FilterPresetsProps {
- onApply: (types: PlaceType[]) => void;
- className?: string;
-}
-
-/**
- * One-tap buttons for common filter combos, so a student doesn't have to
- * rebuild "SAT + foreign-lang exam centres" from the category chips every
- * time. Each preset replaces the active type filter with its own list.
- */
-export function FilterPresets({ onApply, className }: FilterPresetsProps) {
- return (
-
- {FILTER_PRESETS.map((preset) => {
- const Icon = preset.icon;
- return (
-
- );
- })}
-
- );
-}
diff --git a/src/components/map/map-panel.tsx b/src/components/map/map-panel.tsx
index 1b535b7..0ab89d4 100644
--- a/src/components/map/map-panel.tsx
+++ b/src/components/map/map-panel.tsx
@@ -8,7 +8,6 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Separator } from "@/components/ui/separator";
import { CategoryChips } from "@/components/map/category-chips";
-import { FilterPresets } from "@/components/map/filter-presets";
import { CityFilter } from "@/components/map/city-filter";
import { CountryFilter } from "@/components/map/country-filter";
import { NearMeButton } from "@/components/map/near-me-button";
@@ -139,11 +138,11 @@ export function MapPanel({
selected={filters.types}
counts={typeCounts}
onToggle={toggleType}
+ onSetTypes={(types) => onFiltersChange({ ...filters, types })}
+ onClear={() => onFiltersChange({ ...filters, types: [] })}
scroll={scrollChips}
/>
-
onFiltersChange({ ...filters, types })} />
-
{
});
});
-describe("PlacesMap filter presets", () => {
- it("narrows the results to the preset's type and sets it in the URL", () => {
+describe("PlacesMap category filter", () => {
+ function renderMap() {
render(
{
defaultZoom={11}
/>,
);
+ }
+
+ it("narrows the results to the chosen type and sets it in the URL", () => {
+ renderMap();
expect(screen.getByText("City Library")).toBeTruthy();
- fireEvent.click(screen.getByRole("button", { name: "Airports" }));
+ fireEvent.click(screen.getByRole("button", { name: /^Airport/ }));
expect(screen.getByText("City Airport")).toBeTruthy();
expect(screen.queryByText("City Library")).toBeNull();
@@ -320,6 +324,26 @@ describe("PlacesMap filter presets", () => {
advance(500);
expect(params().get("types")).toBe("airport");
});
+
+ it("has one filter row, not a second row of presets (#352)", () => {
+ renderMap();
+
+ expect(screen.queryByRole("group", { name: "Filter presets" })).toBeNull();
+ expect(screen.getAllByRole("group", { name: "Filter by place type" })).toHaveLength(
+ 1,
+ );
+ });
+
+ it("shows how many categories are selected and clears them", () => {
+ renderMap();
+ fireEvent.click(screen.getByRole("button", { name: /^Airport/ }));
+ expect(screen.getByText(/1 category selected/)).toBeTruthy();
+
+ fireEvent.click(screen.getByRole("button", { name: "Clear" }));
+
+ expect(screen.queryByText(/category selected/)).toBeNull();
+ expect(screen.getByText("City Library")).toBeTruthy();
+ });
});
describe("PlacesMap country filter", () => {
diff --git a/src/components/map/results-list.test.tsx b/src/components/map/results-list.test.tsx
index ecbbb83..9801b5f 100644
--- a/src/components/map/results-list.test.tsx
+++ b/src/components/map/results-list.test.tsx
@@ -289,3 +289,113 @@ describe("ResultsList details and compare", () => {
expect(onToggle).toHaveBeenCalledWith(expect.objectContaining({ id: "p1" }));
});
});
+
+describe("ResultsList row location (#354)", () => {
+ const base = {
+ type: "airport" as const,
+ lat: 19,
+ lng: 72,
+ gmaps_link: "https://maps.google.com/?q=19,72",
+ added_by: "test",
+ };
+ const emptyState = { activeFilters: [], onReset: vi.fn(), onSuggest: vi.fn() };
+
+ it("tells two places with the same name apart by city and country", () => {
+ render(
+ ,
+ );
+
+ expect(screen.getByText(/Airport · Mumbai, India/)).toBeTruthy();
+ expect(screen.getByText(/Airport · Nagpur, India/)).toBeTruthy();
+ });
+
+ it("puts the distance after the location when it is known", () => {
+ render(
+ ,
+ );
+
+ expect(screen.getByText(/Airport · London, United Kingdom · /)).toBeTruthy();
+ });
+
+ it("omits the country, with no stray comma, for a private place that has none", () => {
+ render(
+ ,
+ );
+
+ expect(screen.getByText("Airport · Thane")).toBeTruthy();
+ });
+
+ it("lets the name wrap to two lines instead of truncating to one", () => {
+ render(
+ ,
+ );
+
+ const name = screen.getByText("A very long place name");
+ expect(name.className).toContain("line-clamp-2");
+ expect(name.className).not.toContain("truncate");
+ });
+
+ it("keeps the accessible names of the row actions", () => {
+ render(
+ ,
+ );
+
+ expect(screen.getByRole("button", { name: "Details for Heathrow" })).toBeTruthy();
+ expect(
+ screen.getByRole("link", { name: "Open Heathrow in Google Maps" }),
+ ).toBeTruthy();
+ expect(screen.getByRole("link", { name: "Directions to Heathrow" })).toBeTruthy();
+ });
+});
diff --git a/src/components/map/results-list.tsx b/src/components/map/results-list.tsx
index 97bc6bb..5165888 100644
--- a/src/components/map/results-list.tsx
+++ b/src/components/map/results-list.tsx
@@ -11,7 +11,8 @@ import {
} from "lucide-react";
import type { Place } from "@/lib/types";
-import { PLACE_TYPE_LABELS } from "@/lib/types";
+import { PLACE_TYPE_LABELS, humanizeCity } from "@/lib/types";
+import { countryName } from "@/lib/places-utils";
import { directionsUrl } from "@/lib/map";
import { formatDistance } from "@/lib/geo";
import { Button } from "@/components/ui/button";
@@ -53,6 +54,16 @@ interface ResultsListProps {
pageSize?: number;
}
+/** "Mumbai, India": the city and, when the place has one, its country, so same-named places are told apart (#354). */
+export function placeLocationLabel(place: Place): string {
+ const city = humanizeCity(place.city);
+ return place.country ? `${city}, ${countryName(place.country)}` : city;
+}
+
+/** Touch-sized (44px) below the `lg` sidebar breakpoint, where the list sits in the mobile sheet. */
+const ROW_ACTION_CLASS =
+ "flex min-h-11 min-w-11 shrink-0 items-center justify-center rounded-md p-2 text-muted-foreground transition-colors hover:bg-background hover:text-foreground focus-visible:bg-background focus-visible:text-foreground lg:min-h-0 lg:min-w-0";
+
/** Rows rendered before "Show more", so the unfiltered map does not build ~2,000 rows. */
export const RESULTS_PAGE_SIZE = 100;
@@ -187,13 +198,13 @@ export function ResultsList({
title={`${place.name} (${PLACE_TYPE_LABELS[place.type]})`}
>
-
+
{place.name}
- {PLACE_TYPE_LABELS[place.type]}
+ {PLACE_TYPE_LABELS[place.type]} · {placeLocationLabel(place)}
{distanceKm !== undefined && ` · ${formatDistance(distanceKm)}`}
@@ -202,7 +213,7 @@ export function ResultsList({
type="button"
onClick={() => onDetails(place)}
aria-label={"Details for " + place.name}
- className="shrink-0 rounded-md p-2 text-muted-foreground transition-colors hover:bg-background hover:text-foreground focus-visible:bg-background focus-visible:text-foreground"
+ className={ROW_ACTION_CLASS}
>
@@ -214,7 +225,7 @@ export function ResultsList({
rel="noreferrer"
onClick={(e) => e.stopPropagation()}
aria-label={`Open ${place.name} in Google Maps`}
- className="shrink-0 rounded-md p-2 text-muted-foreground transition-colors hover:bg-background hover:text-foreground focus-visible:bg-background focus-visible:text-foreground"
+ className={ROW_ACTION_CLASS}
>
@@ -225,7 +236,7 @@ export function ResultsList({
rel="noreferrer"
onClick={(e) => e.stopPropagation()}
aria-label={`Directions to ${place.name}`}
- className="shrink-0 rounded-md p-2 text-muted-foreground transition-colors hover:bg-background hover:text-foreground focus-visible:bg-background focus-visible:text-foreground"
+ className={ROW_ACTION_CLASS}
>