Repository navigation
Description
Summary
sortEvents and calculateOrder are pure list ordering living in a data-connected component (src/components/organisms/EventsList/DynamicEventsList.tsx:45-88). src/lib/shape/sort.ts already owns the sort order — the SortOrder type, SORT_ORDERS, DEFAULT_SORT and the ?sort= codec — and AGENTS.md:165 puts pure domain helpers there, "no React or i18n".
Deferred out of #221's review thread. Filed so the deferral outlives that PR body.
⚠ This ticket described #221's branch, not main
Three of the original premises hold only on claude/feat-220-unverified-badge (#221, open and still draft):
| Premise as filed | On main |
|---|---|
sortEvents is exported only so its spec can reach it |
Not exported. DynamicEventsList.tsx:71, module-private, as is calculateOrder at :45 |
DynamicEventsList.sort.test.ts imports a component module to test a pure function |
The file does not exist |
recommended carries an unverified ×1.5 factor |
Three factors only: language ×2, soon ×0.5, online ×1.5 |
So the work cannot start before #221 merges — it would conflict inside the same function. See the Blocked by: line.
Approach
The i18n coupling is one line, not a signature change to calculateOrder. The original body said calculateOrder reads i18n.resolvedLanguage directly. It does not, on either branch: it already takes language: string | undefined as its second parameter (DynamicEventsList.tsx:45; :46 on #221's branch). The single read sits in sortEvents's default arm — :80, and :83 on the branch — which is what forces the spec's vi.mock('@/config/i18n'), and it is the only use of the i18n import at :32.
- Thread the language through
sortEvents.sortEvents(events, order, language); delete the read at:80and the import at:32.DynamicEventsListalready holds the value —useLocale()at:101— so this adds no hook. - Add it to the memo deps.
:116isuseMemo(() => sortEvents(events, order), [events, order]), becoming[events, order, language]. Today a language switch re-sorts only indirectly:eventsQuery(latitude, longitude, filters, locale)at:109keys on the locale, so switching yields a neweventsreference. Making the dependency explicit costs nothing and stops that being load-bearing. - Move both functions into
src/lib/shape/sort.tswith their comments, and drop feat(widget): badge unverified listings before registration #221'sexportfromDynamicEventsList. - Fold the spec into
src/lib/shape/sort.test.ts. Mechanical: the branch spec'svi.mock('@/config/i18n', () => ({ default: { resolvedLanguage: 'en' } }))becomes a third argument,'en'.mockEventSlim.languagesis['en'](src/mocks/events.ts:75), so those fixtures carry no language penalty either way and the assertions port unchanged.
⚠ Which value gets passed is the decision this turns on
The original body offered "useLocale()'s value (or i18n.resolvedLanguage, matching today's behaviour exactly)" as interchangeable. They are not. useLocale().locale is i18n.resolvedLanguage || 'en' (src/hooks/use-locale.ts:72), and the penalty is a loose compare, if (language != languageCode) order *= 2:
| passed | for an event whose languages[0] is 'en' |
|---|---|
i18n.resolvedLanguage, before it resolves (undefined) |
undefined != 'en' → ×2 |
useLocale().locale → 'en' |
no penalty |
i18n.resolvedLanguage is the value that satisfies the byte-identical criterion. useLocale().locale changes the ordering in the window before a locale resolves.
Acceptance criteria
-
sortEventsandcalculateOrderlive insrc/lib/shape/sort.ts.DynamicEventsListexports neither. - Neither function imports
@/config/i18n, andDynamicEventsList.tsxno longer imports it either. The resolved language is a parameter. - The value passed is
i18n.resolvedLanguage, notuseLocale().localeand notlanguageCode, unless the open question below is settled otherwise. -
languageis in theuseMemodependency list atDynamicEventsList.tsx:116. -
src/lib/shape/sort.test.tscovers the three branches with novi.mockof@/config/i18n, andDynamicEventsList.sort.test.tsis deleted. - The three orderings are byte-identical for the same input:
recommendedkeeps every factor and weight — language ×2, soon ×0.5, online ×1.5, and feat(widget): badge unverified listings before registration #221's unverified ×1.5 — andclosestandsooneststay the literal comparators. - The list still re-sorts without refetching when
?sort=changes. -
pnpm lint,pnpm typecheck,pnpm test:runpass.
Verification checklist
-
pnpm test:run. - Reintroduce each moved factor's defect at its new site in
sort.tsand watch the spec go red — a moved assertion is a new assertion (docs/testing.md). - Pass
undefinedas the language in a spec case and assert the ×2 penalty still lands on an'en'event. This is what pins criterion 3: a spec that only ever passes'en'cannot see the difference. - Drop
languagefrom the:116memo deps and confirm something goes red. If nothing does, that dependency is untested. -
pnpm dev, search a place, then switch Recommended / Closest / Soonest: the order matchesmain's, and the network tab shows no refetch.
Open questions
- Keep the
en-USquirk, or fix it here?useLocale()also returnslanguageCode(locale.split('-')[0],use-locale.ts:109). Passing that would fix a real pre-existing bug — anen-USbrowser gets'en-US' != 'en'→ ×2 on every English event — but it changes the ordering, so it cannot land under the byte-identical criterion above. Fix it here and relax that criterion, or keep today's behaviour and file it separately?
Notes
Blocked by: #220 — #221 adds the export, the spec file, and the unverified factor that this ticket moves.
- No host-facing contract change: nothing here is observable through
<sahaj-atlas>'s attributes, origins or URL shape, sodocs/embedding.mdandCHANGELOG.mdstay untouched. A visitor sees no reordering either — that is the point. - The "no React or i18n" rule for
src/lib/is in the rootAGENTS.md:165(CLAUDE.mdsymlinks to it), notsrc/AGENTS.mdas first cited.src/lib/has no runtime@/config/i18nimport today, sosort.tsreaching for one would be the first. revealRowsowns segmenting and slicing after the sort —DynamicEventsList.tsx:138-141, not:71-72as first written, which points insidesortEvents. Out of scope. Do not move it in the same PR.- The original body framed step 1 as moving the read "from once per
sortEventscall to once per render of the list".sortEventsalready runs only inside the:116memo, anduseLocale()at:101is already subscribed, so neither shape costs anything. The decision above is the real review surface.
Related
- feat(widget): badge unverified listings on the event page #220, feat(widget): badge unverified listings before registration #221 (the review thread that filed this: feat(widget): badge unverified listings before registration #221 (comment))
- feat(search): lift the 50-result cap with a "Load more" control #85 — why the sort runs over the whole matching set rather than a capped 50.
🤖 Written by the sydevs autonomous loop — see what this is
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Hold Until
Projects
- StatusShow more project fieldsDone
Activity
sydevs-bot commentedon Sep 21, 2026
🤖 no session running
recent dispatches
Written by the sydevs dispatcher. Sessions never edit this comment.
sydevs-bot commentedon Sep 21, 2026
Revised against the code. Three premises here described #221's branch, not
main.On
mainneither function is exported,DynamicEventsList.sort.test.tsdoes not exist, and there is nounverifiedfactor. All three arrive with #221. Added aBlocked by:line on #220 — starting first would conflict inside the same function.Corrected the central claim.
calculateOrderdoes not readi18n.resolvedLanguage. It already takeslanguageas a parameter. The read is one line insortEvents(:80). Step 1 threads one argument.Added the decision the ticket was missing.
useLocale().localeisi18n.resolvedLanguage || 'en', so the two are not interchangeable. An unresolved locale penalises an'en'event ×2. A resolved'en'does not. Criterion 3 now names the byte-identical value.One open question: an
en-USbrowser penalises every English event today. Fixing it changes the ordering.Effort stays
Easy, PriorityLow.@sydevs-bot implementstarts the work. This revision authorises nothing.🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
sydevs-bot commentedon Sep 22, 2026
@Ardnived unblocked: every blocker is closed. Say
@sydevs-bot implementto start.🤖 sydevs dispatcher
Ardnived commentedon Sep 22, 2026
@sydevs-bot implement
fix(list): sort on locale, not the raw resolvedLanguage