Smal
This commit is contained in:
parent
d34478e13c
commit
1934a38677
5 changed files with 66 additions and 9 deletions
|
|
@ -917,7 +917,7 @@ const en = {
|
|||
body: 'Want to see property data around you? Use your location, or start the demo at Canary Wharf.',
|
||||
useLocation: 'Use my location',
|
||||
locating: 'Locating…',
|
||||
useDefault: 'Show Canary Wharf',
|
||||
useDefault: 'Show London',
|
||||
},
|
||||
|
||||
// ── Mobile Drawer ──────────────────────────────────
|
||||
|
|
|
|||
|
|
@ -196,6 +196,32 @@ describe('url-state', () => {
|
|||
expect(state.overlays).toEqual(new Set(['noise', 'crime-hotspots']));
|
||||
});
|
||||
|
||||
it('enables crime + trees overlays by default on a fresh visit', () => {
|
||||
const state = parseUrlState();
|
||||
|
||||
expect(state.overlays).toEqual(new Set(['crime-hotspots', 'trees-outside-woodlands']));
|
||||
});
|
||||
|
||||
it('round-trips an explicit "all overlays off" via the __none sentinel', () => {
|
||||
const params = stateToParams(
|
||||
null,
|
||||
{},
|
||||
[],
|
||||
new Set(),
|
||||
'area',
|
||||
undefined,
|
||||
undefined,
|
||||
new Set()
|
||||
);
|
||||
|
||||
expect(params.getAll('overlay')).toEqual(['__none']);
|
||||
|
||||
window.history.replaceState({}, '', `/?${params.toString()}`);
|
||||
const state = parseUrlState();
|
||||
|
||||
expect(state.overlays).toEqual(new Set());
|
||||
});
|
||||
|
||||
it('round-trips satellite basemap selection', () => {
|
||||
const params = stateToParams(
|
||||
null,
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ import {
|
|||
type PoiFilterName,
|
||||
} from './poi-distance-filter';
|
||||
import { dedupeTravelTimeEntries } from './travel-params';
|
||||
import { isOverlayId, type OverlayId } from './overlays';
|
||||
import { isOverlayId, DEFAULT_OVERLAY_IDS, type OverlayId } from './overlays';
|
||||
import { CRIME_TYPES, isCrimeTypeValue } from './crime-types';
|
||||
import { isBasemapId, type BasemapId } from './basemaps';
|
||||
import {
|
||||
|
|
@ -59,6 +59,7 @@ import {
|
|||
|
||||
const POI_NONE_PARAM = '__none';
|
||||
const CRIME_TYPES_NONE_PARAM = '__none';
|
||||
const OVERLAY_NONE_PARAM = '__none';
|
||||
const CRIME_OVERLAY_ID: OverlayId = 'crime-hotspots';
|
||||
|
||||
export interface UrlState {
|
||||
|
|
@ -227,7 +228,7 @@ export function parseUrlState(): UrlState {
|
|||
hasExplicitView: false,
|
||||
filters: parseFilters(params),
|
||||
poiCategories: new Set(),
|
||||
overlays: new Set(),
|
||||
overlays: new Set(DEFAULT_OVERLAY_IDS),
|
||||
basemap: 'standard',
|
||||
colorOpacity: DEFAULT_COLOR_OPACITY,
|
||||
tab: 'area',
|
||||
|
|
@ -266,9 +267,14 @@ export function parseUrlState(): UrlState {
|
|||
}
|
||||
}
|
||||
|
||||
// Overlays default to DEFAULT_OVERLAY_IDS on a fresh visit; explicit `overlay`
|
||||
// params override that, and the `__none` sentinel records "all off" so it
|
||||
// survives a reload instead of silently restoring the defaults.
|
||||
const overlayParams = params.getAll('overlay');
|
||||
if (overlayParams.length > 0) {
|
||||
result.overlays = new Set(overlayParams.filter(isOverlayId));
|
||||
result.overlays = overlayParams.includes(OVERLAY_NONE_PARAM)
|
||||
? new Set()
|
||||
: new Set(overlayParams.filter(isOverlayId));
|
||||
}
|
||||
|
||||
// Crime-type filter: repeated `crimeType` params, or the `__none` sentinel.
|
||||
|
|
@ -451,8 +457,14 @@ export function stateToParams(
|
|||
}
|
||||
|
||||
if (selectedOverlays) {
|
||||
for (const overlay of selectedOverlays) {
|
||||
params.append('overlay', overlay);
|
||||
if (selectedOverlays.size === 0) {
|
||||
// Distinguish a deliberate "all overlays off" from a fresh visit, which
|
||||
// would otherwise re-apply the defaults on reload.
|
||||
params.append('overlay', OVERLAY_NONE_PARAM);
|
||||
} else {
|
||||
for (const overlay of selectedOverlays) {
|
||||
params.append('overlay', overlay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue