Repository navigation
feat(search): offer a country website when no programs are listed - #84
Merged
Merged
Conversation
A search landing in a country with no Sahaja Yoga programs dead-ended on "No events found." Ship shrimataji.org's national-site list as static data and, when the searched country is genuinely empty, offer its own site. - `src/data/country-sites.ts` — 95 uppercase ISO alpha-2 → URL entries - `src/lib/geocode.ts` — the guarded `?cc` reader; hosts the canonical `isoCountryCode` (fetch.ts now shares it instead of a private copy) - `src/lib/shape/country.ts` — `countryHasPrograms`, a region-subtree test over the full feed; an unknown country resolves to NO programs (which is why it can't reuse `buildRegionMatcher`) - `CountrySiteOffer` molecule on the existing Alert + Link atoms - `EmptyResults` gates offer → distance cap → filters: the offer must win, since a program-less country's nearest results are usually beyond the 500 km cap and would otherwise bury it - `?cc` written by SearchField + the accepted geolocation suggestion; the re-encode in `preserveSearchState` drops it, so it never leaks forward Closes #82 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The two SearchView cases both need a URL, so they seed one onto the decorator's own router via the existing SeedSearchParams helper (react-router v7 throws on a nested <Router>, which is why that helper exists) and derive their query key from the same string — seed and read can't drift. Adds `mockRegionNodes`, the wholesale region tree the harness now seeds for every view story. Country slugs are lowercase ISO codes, matching the live data post-SahajCloud#556 — the invariant `countryHasPrograms` looks a country up by — and Iceland is deliberately absent. Closes #82 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Applied the cleanup findings from the four review lenses: - Fixed a real gap the simplification lens caught: the empty-state gate guarded `geojson` but NOT `regions`, so a loaded feed with an unloaded region tree made `countryHasPrograms` answer false and offered a foreign website to a country that HAS classes. The (now-false) comment claimed the guard was unnecessary. Both reads are required-loaded in one place. - `src/data/` → `src/lib/country-sites.ts` with a case-normalizing `countrySite()` accessor, mirroring the existing `PLATFORMS_BY_COUNTRY` / `platformsForCountry` in `lib/share/platforms.ts` — the repo already homes this exact kind of static country-keyed table there, so `src/data/` was a new tier for nothing. - Extracted `useCountrySite` (src/hooks/), mirroring `useRegionMatcher`: the URL read + table lookup + two cache reads + the gate leave the organism, so `EmptyResults` is presentational again. Dropped the two `enabled` flags with it — both keys already have ungated observers on this screen (ActiveFilterPills, GeolocationSuggestion), so they saved nothing. - Added the `eventsQuery` factory (config/api) so the list's suspense read and the story's cache seed build ONE key — the drift the story's comment claimed to prevent was still two constructions. - `parseCenter` moved beside `searchPath` (lib/shape/path.ts), whose docblock already claimed to own the `?center=lng,lat` format jointly with it; `SEARCH_COUNTRY_PARAM` named there too, replacing three `'cc'` literals. - `isoCountryCode` moved from the Mapbox-shaped `lib/geocode.ts` to `lib/shape/country.ts`, so the data layer no longer imports a geocoder module for a string guard — and `useViewerCountry` now uses it too, which stops an unvalidated `"usa"` reaching `platformsForCountry`. - `countryHasPrograms` takes required inputs (loading is the caller's concern); mock Cambridge derives from the feed's own region ref. Skipped: rebuilding `countryHasPrograms` on `buildRegionMatcher` — behaviour is identical today, but it would couple "has programs" to the filter's unknown-slug policy, which must stay opposite. Skipped a `geojsonQuery()` factory (7 pre-existing inline copies — its own PR). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Two independent review passes (correctness + git-history) converged on the filters interaction, and the history pass found the commit whose affordance the first cut dropped: - The offer now stands down while ANY filter is active (076bf43's "clear all filters" escape hatch is that state's, so the offer waits for a clear rather than replacing it). This also kills a wrong-country offer: a filter edit deliberately preserves `?cc`, so searching Reykjavík and then filtering Region=United Kingdom used to empty the list *because of the filter* and still offer Iceland's website. It stays ahead of the "< N km" branch, which is what makes the feature reachable at all. - `countryHasPrograms` now requires the matched node to be `level: 'country'` — slugs are unique across the whole tree, not per level, so a two-letter city slug (`as`) would otherwise answer for its namesake country. - Memoized the feed scan: the geocoder rewrites `?q` per keystroke, so the region index + subtree set were rebuilt once per character typed. - `RegionedFeature.region` is required, matching the feed schema (`AgnosticFeedEventSchema.region` is non-nullable) — the old `null` branch and its test asserted a shape that can't occur. Replaced with the real case: an online class filed under a country DOES count as a program. - Story fixtures: seed every case's key (switching the Example control paired the previous case's URL with the new case's client for one render, missing cache and hitting the absent backend); `mockIpLocation` carries a `country_code`, so the second `?cc` writer has coverage. - Copy uses Alert's `description` slot, not `title`, so it renders at the weight of the empty states it replaces. - Corrected two now-false comments: the FilterView story's "no region tree here" (the harness seeds one now) and the `http://` count (57, not 45). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…rrer leak From the security review (no High/Critical; the `?cc` → href chain is allowlisted end to end, and src/config/api/ changed only mechanically). - The source page publishes 57 of the 95 sites as plain `http://`. Probed all 57 over HTTPS: 43 answer 200 without downgrading in the redirect chain, so those are now stored as `https://`. The widget presents these as a country's authoritative contact point — several carry join-a-class forms — so a plaintext hop on a hostile network let an attacker serve a convincing fake while borrowing the trust the widget just lent it. The 14 with no working HTTPS stay as published rather than becoming dead links, and a test pins that list so a future refresh has to re-probe rather than regress. - `referrerPolicy="no-referrer"` on the flag `<img>`, which loads from react-circle-flags' own CDN — the embedding host's URL was riding along to a third party on every render. Applied to CountriesView's flag too, so the two surfaces don't drift. - `COUNTRY_SITES` is typed `string | undefined`: with `noUncheckedIndexedAccess` off a bare index typed as `string` while returning undefined, and the story was doing exactly that. - Two anchoring cases for `isoCountryCode` — it's the only gate between an attacker-supplied `?cc` and both the record index and the CDN path segment. Noted and deliberately not changed: six entries sit on re-registrable free-tier subdomains (the fix is the ticket's own out-of-scope "move the mapping into SahajCloud"); `?cc` isn't cross-checked against `?center`, which is unclosable here by design — a program-less country has no geometry to resolve a point against, which is why the code rides in the URL at all. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ag CSP - README: `img-src https://react-circle-flags.pages.dev` in the embedding-host CSP section, which only covered Turnstile — a host with a strict `img-src` silently lost the country flags. Notes what blocking it costs (glyphs only) and that the requests are `no-referrer`. - `.claude/rules/i18n-and-state.md`: the searched-location params as their own URL slice, including `?cc` — why they're read raw rather than codec'd (replaced by a new search, not merged) and why the country can't simply be re-derived at the read site. - `.claude/rules/data-layer.md`: the `eventsQuery` factory beside `eventQuery`. - `DESIGN_SYSTEM.md`: the `CountrySiteOffer` molecule row. - `CLAUDE.md`: added the missing `src/lib/` entry — it's where the static country-keyed tables live, which is the question this branch had to answer — and corrected `config/api/`'s stale "axios client" (it's the Payload SDK). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deploying sahajatlas-design with
|
| Latest commit: |
9cd73f7
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://cd35e5ad.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://feat-country-site-offer.sahajatlas-design.pages.dev |
Deploying sahajatlas with
|
| Latest commit: |
9cd73f7
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c1a74be0.sahajatlas.pages.dev |
| Branch Preview URL: | https://feat-country-site-offer.sahajatlas.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/lib/country-sites.ts, scraped from shrimataji.org/map/world.html) — no fetch, no CMS round trip.Changes
src/lib/country-sites.ts— 95 uppercase-ISO → URL entries plus a case-normalizingcountrySite()accessor, mirroring the existingPLATFORMS_BY_COUNTRY/platformsForCountryinlib/share/platforms.ts.src/lib/shape/country.ts—countryHasPrograms(a region-subtree test over the full feed) and the canonicalisoCountryCode, moved here fromconfig/api/fetch.tsso the data layer, the?ccreader and the IP guess share one guard.src/lib/geocode.ts— readscountry_codeoff the Mapbox geocode context, which the vendor types omit.src/hooks/use-country-site.ts— composes the whole trigger (mirrorsuseRegionMatcher), soEmptyResultsstays presentational.src/lib/shape/path.ts—SEARCH_COUNTRY_PARAM+parseCenterbesidesearchPath, which already claimed to co-own the?center=lng,latformat.src/config/api/index.ts— aneventsQueryfactory, so the results list and the SearchView story build one key.Verification
pnpm lint)pnpm typecheck)pnpm test:run) — 463 testspnpm ladle:buildclean; the production build runs in CIManual / visual verification
Driven in the running widget (both
/searchand?map=0), against the seeded local SahajCloud — which has 25 countries with programs and no Iceland:?cc=IS)sahajayoga.is,target="_blank" rel="noopener noreferrer"context.country, not a country-level result?ccreplacedIS→AT; Austria has 30 classes, so no offer?cc=BR)?langs=zz?region=gb?cc=AO, no site)?cc=ISL(malformed)?ccpreserved; offer returnsBoth new Ladle cases render, including switching between all four Example values in sequence.
Notes for reviewer
One ordering call worth understanding. The offer is checked before the "< 500 km" branch.
getEventsreturns the nearest N events with no distance limit, so a program-less country's nearest results are typically ~1900 km away — the cap fires for virtually every such search and would bury the offer entirely. Verified: the plain Iceland search does show the cap pill.Two deviations from the ticket, both deliberate:
src/data/country-sites.ts; the repo already homes exactly this kind of static country-keyed table insrc/lib/(share/platforms.ts), so a new top-level tier wasn't warranted.searchprop onViewHarnesswrapping a nestedMemoryRouter. react-router v7 throws on a nested<Router>— which is whysrc/components/ladle/SeedSearchParams.tsxexists andCalendarView.stories.tsxalready uses it for a view. The stories use that instead.The ticket's trigger list omitted filters; two review passes flagged the gap. The offer now stands down while any filter is active. That restores the "Clear all" affordance to the state that owns it (the offer arrives one click later), and it closes a real bug: a filter edit deliberately preserves
?cc, so searching Reykjavík and then filtering Region = United Kingdom emptied the list because of the filter while still offering Iceland's website.Security review (triggered —
src/config/api/changed): no High/Critical. The?cc→hrefchain is allowlisted end to end andconfig/api/changed only mechanically. Two findings acted on:http://. All 57 were probed over HTTPS; the 43 that answer 200 without downgrading are now stored ashttps://. These are presented as a country's authoritative contact point and several carry join-a-class forms, so a plaintext hop let a hostile network serve a convincing fake. The 14 with no working HTTPS stay as published rather than becoming dead links, and a test pins that list so a refresh has to re-probe.referrerPolicy="no-referrer"on the flag<img>(it loads fromreact-circle-flags' CDN, so the host page's URL was riding along). Applied toCountriesView's flag too, so the two don't drift.Knowingly not fixed:
*.weebly.com,*.blogspot.com,freeservers.com). The real fix is the ticket's own out-of-scope item — moving the mapping into SahajCloud so it's editable without a redeploy. Documented in the module.?ccisn't cross-checked against?center, so a hand-crafted?center=<Berlin>&cc=ISmislabels the country. Unclosable here by design: a program-less country has no feed features and so no geometry to resolve a point against, which is why the geocoder's answer has to ride in the URL. The destination is always one of the 95, so it's confusing rather than a redirect.localeprop (and?locale=) reachesi18n.changeLanguageunvalidated, so a bad tag throwsRangeErrorout ofIntl.DisplayNamesand drops the whole widget to the ErrorBoundary.supportedLngsinconfig/i18n.tswould close it.Closes #82
🤖 Generated with Claude Code