Repository navigation
Description
Summary
SahajCloud now treats Countries, Regions, Areas, and Venues as one regions
collection with a level discriminator (country | region | city | center).
The widget still carries four parallel view-models, fetchers, page components,
and flat URL prefixes for them. This collapses all four into a single Region
abstraction — one schema, one fetcher, one page — and switches routing to
hierarchical, ancestry-based URLs so the URL mirrors the region tree
instead of a flat /areas/<slug> scheme.
New URL scheme (variable depth = the region's actual breadcrumb slug chain).
The region and venue levels are optional, so the same rule must handle every
depth, e.g. /belgium/antwerp (no region), /belgium/flanders/antwerp/12345
(event, no venue), /belgium/flanders/antwerp/downtown-hall/12345 (full chain):
- Country:
/belgium - Region:
/belgium/flanders - Area (city):
/belgium/flanders/antwerp— or/belgium/antwerpif no region - Venue (center):
/belgium/flanders/antwerp/downtown-hall - Event:
.../<region-chain>/12345(numeric tail = event id)
Region slugs are globally unique across levels (confirmed). That is what
makes variable depth tractable: resolution reads only the terminal segment,
never the path shape. A numeric terminal is an event id; any other terminal is a
region slug. The intermediate country/region/city/venue segments are contextual
only — they need no positional parsing, so region-optional and venue-optional
URLs resolve identically.
Current behavior
src/types/{country,area,venue}.ts+ the region view-models in
src/types/region.tsdefine four nearly-identical shapes that differ only in
the geo accessor (boundsvscenter) and the child collection
(children/areas:RegionListItem[]vsevents:EventSlim[]).src/config/api/fetch.tshasgetCountry/getRegion/getArea/getVenue,
each hard-coding alevelintogetRegionDoc(slug, level)and shaping a
different schema; the aggregation helpers (countUnder,boundsUnder,
eventsUnder) are already level-agnostic.src/pages/{country,region,area,venue}.tsxare four Panel wrappers that
fetch, set the map boundary/center, and render either a<List>of children
or an<EventsList>.- Routing uses four flat prefixes via
LEVEL_ROUTESinsrc/lib/shape/path.ts;
regionPath(level, slug)andeventPath(id)build single-segment paths.
Proposed changes
Types — one Region view-model (src/types/region.ts)
- Introduce a single view-model:
id, slug, name, level, subtitle?, countryCode?, eventCount, bounds: BBox | null, center: Position | null, path, parentPath?, subregions: RegionListItem[], events: EventSlim[].subregionsis populated
forcountry/region;eventsforcity/center;centeris derived for
all (used by venue today);countryCodeis set only forcountry. - Delete
src/types/country.ts,src/types/area.ts,src/types/venue.ts; fold
the home-list shape (today'sCountrySlim) intoRegionListItem(keep
countryCodefor the flag). Update the barrelsrc/types/index.ts. - Extend
BreadcrumbSchemaso each crumb carries the ancestorslug+level
(backend breadcrumbs are{ doc, url, label, id }wheredoccan populate to
a full Region — see Data dependencies).
Data layer — one fetcher (src/config/api/fetch.ts)
- Replace the four hierarchy fetchers with
getRegion(slug): fetch the region
doc by slug (level comes from the response, not a filter), derive
eventCount/bounds/center, and populatesubregions(via
getChildRegions) whenlevel ∈ {country, region}elseevents(via
eventsUnder). Single query key['region', slug]. - Keep
getCountriesfor the home/search list; returnRegionListItems with
countryCode. - Surface the ancestor slug chain so paths can be built (populate breadcrumb
docwithslug/level, or walkparent), on bothgetRegionDocand the
geojson feed (REGION_POPULATE) so per-event paths intoSlimare nestable.
Path helpers — nested build + parse (src/lib/shape/path.ts)
- Replace
LEVEL_ROUTES+ flatregionPathwith a nested builder that joins the
ordered ancestor slug chain:regionPath(region) → "/belgium/flanders/antwerp". eventPath(event)appends the numeric id to its region's chain.- Add a parser
resolvePath(pathname)→{ kind: 'region', slug } | { kind: 'event', id } | nulldriven only by the terminal segment: all
digits → event id; otherwise → region slug. Depth-independent, so every shape
in the list above resolves through one code path (region slugs are unique and
never purely numeric, so there is no region/event ambiguity). - Because intermediate segments are cosmetic, an incoming URL with a partial or
stale ancestry still resolves; canonicalize by redirecting to the target's
true breadcrumb path (regionPath(region)) so the address bar stays
consistent. This also subsumes the legacy-flat-URL redirects.
Pages — one RegionPage (src/pages/region.tsx, delete the other three)
- Branch on
level:country/regionrender<List>ofsubregions;
city/centerrender<EventsList events>. - Preserve today's per-level behaviors:
fitBounds(bounds)when bounds exist,
center-onlymoveMapfallback forcenterlevel, the venue redirect when
< 2events,mapWindow={240}forcenter, the country flag + localized
name viacountryCode, and the areasubheader. - Keep
EventPage; update its back link to the region's nestedparentPath.
Routing (src/App.tsx)
- Replace the four region routes +
/events/:idwith a splat route (path="*")
that runsresolvePathand rendersRegionPageorEventPage. Keep
/search. UpdateinitialPath(fromclient.region) to the nested path. - Update the cluster-click navigate in
src/components/organisms/Mapbox/Map.tsxto build the nested event path from
the feature's region ancestry. - Redirect the legacy flat paths (
/{countries,regions,areas,venues}/:slug,
/events/:id) to their nested equivalents — handled by the same
canonicalization step (resolve terminal → redirect toregionPath/eventPath).
Data dependencies
- Slug uniqueness across the
regionscollection: confirmed — terminal
slug resolves exactly one region, so no positional/chain disambiguation is
needed. - Ancestor slugs are retrievable — breadcrumb
docpopulates with
slug/level(or reconstructable viaparent) on both region reads and
the geojson feed. Needed to build nested paths for regions and events.
(Verify the populate shape against a live SahajCloud response.)
Acceptance criteria
- A single
Regionzod view-model +getRegion(slug)fetcher replace
Country/Area/Venueschemas and the fourgetCountry/Region/Area/Venue
fetchers;src/types/{country,area,venue}.tsare removed and the barrel
updated. - A single
RegionPagerenders all four levels (children list for
country/region, events list for city/center) with the venue redirect,
country flag/name, area subheader, and map framing preserved. - URLs are hierarchical and match the region ancestry for all four levels and
for events (numeric tail); the<SearchBar>back button and event-page back
link navigate to the correct parent path. - Variable-depth URLs all resolve via the terminal segment — region-optional
(/country/city) and venue-optional (/country/city/12345) shapes work,
and any incoming path canonicalizes (redirects) to the target's true
breadcrumb path. - Map cluster clicks and the home/search country list navigate to correct
nested URLs;initialPath(client home region) resolves to a nested path. - Legacy flat URLs (
/countries|regions|areas|venues/:slug,/events/:id)
redirect to their nested equivalents. - No regression to map boundary/center framing, event counts, or the
online-only filter. - Zod parse errors still surface backend shape changes (no silent fallbacks).
-
pnpm lint && pnpm typecheck && pnpm test:run && pnpm buildall pass.
Files affected
src/types/region.ts,src/types/index.ts(+ deletecountry.ts,
area.ts,venue.ts)src/config/api/fetch.tssrc/lib/shape/path.ts(+src/lib/shapebarrel)src/pages/region.tsx(+ deletecountry.tsx,area.tsx,venue.tsx),
src/pages/event.tsxsrc/App.tsx,src/components/organisms/Mapbox/Map.tsx
References
- Backend
Regiontype:src/types/payload/payload-types.ts(level,
breadcrumbs,slug) - Level→route mapping being replaced:
src/lib/shape/path.ts - Ancestry aggregation helpers (reused as-is):
src/lib/shape/hierarchy.ts
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity