feat(search): open postcode searches on the map on phones too
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m12s
PR Checks / Backend Smoke (pull_request) Successful in 10s
PR Checks / Build Backend (no push) (pull_request) Successful in 18s
PR Checks / Build Frontend (no push) (pull_request) Successful in 1m19s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 11s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 21s
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m12s
PR Checks / Backend Smoke (pull_request) Successful in 10s
PR Checks / Build Backend (no push) (pull_request) Successful in 18s
PR Checks / Build Frontend (no push) (pull_request) Successful in 1m19s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 11s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 21s
Trial the map as the default for every postcode search, not only on desktop (DEFAULT_LOCATION_VIEW in HomeView; results_view_changed shows how often readers switch away). The view is now derived: the reader's choice once made, else the default for the kind of search. That follows a hero search through client-side navigation without syncing state. With nothing left varying by device, the user-agent default goes (lib/device.ts, the headers() read in page.tsx). That settles two review points: the HTML no longer needs Vary: User-Agent, and there is no narrow-window fallback left to flash the map before the list. Review fix in LeafletMapInner: the card reopened only when the selection or the school list changed, so a rebuild caused by the centre, reference point or radius closed it for good while the page still had the school selected. The selection effect now follows a pins-rebuilt counter. SchoolMap memoises its fallback centre, which was a fresh array on every render and would have rebuilt every pin each time. Phones hide the map view's list pane, so it no longer builds up to 500 hidden cards there (decided after mount, so hydration still matches). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4e4b30e812
commit
1bb3e0360f
11 files changed
+130
-141
No files matched your search
@@ -5,7 +5,7 @@
|
||||
|
||||
'use client';
|
||||
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import L from 'leaflet';
|
||||
import 'leaflet/dist/leaflet.css';
|
||||
import type { School } from '@/lib/types';
|
||||
@@ -124,6 +124,10 @@ export default function LeafletMapInner({
|
||||
const overlayRef = useRef<L.LayerGroup | null>(null);
|
||||
const popupRef = useRef<L.Popup | null>(null);
|
||||
const selectedRef = useRef<number | null>(null);
|
||||
// Bumped whenever the pins are rebuilt, for any reason, so the selection
|
||||
// effect puts the card back on the new pin rather than only when the
|
||||
// selection or the school list changes.
|
||||
const [pinsVersion, setPinsVersion] = useState(0);
|
||||
|
||||
// The popup is plain HTML outside React, so its handlers read the latest
|
||||
// props through a ref rather than closing over the render they were made in.
|
||||
@@ -216,6 +220,7 @@ export default function LeafletMapInner({
|
||||
} else {
|
||||
map.setView(center, zoom);
|
||||
}
|
||||
setPinsVersion(v => v + 1);
|
||||
}, [schools, center, zoom, referencePoint, radiusMiles]);
|
||||
|
||||
// Selection: restyle the pin, and on wide screens open its card.
|
||||
@@ -267,7 +272,7 @@ export default function LeafletMapInner({
|
||||
if ((e.target as HTMLElement).closest('[data-compare]')) latest.current.onAddToCompare?.(school);
|
||||
});
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [selectedUrn, schools]);
|
||||
}, [selectedUrn, pinsVersion]);
|
||||
|
||||
// The open card follows the compare basket and the averages as they arrive.
|
||||
useEffect(() => {
|
||||
|
||||
Reference in new issue
Block a user