Skip to content

feat(ngos): keep the explorer sort in the URL - #348

Merged
Ashborne267 merged 1 commit into
StreamGive:mainfrom
chidii:feat/explorer-sort-url
Oct 23, 2026
Merged

Ashborne267 merged 1 commit into
StreamGive:mainfrom
chidii:feat/explorer-sort-url

Conversation

@chidii

@chidii chidii commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Search (q) and page (page) were already synced to the URL on the NGO explorer, but the selected sort was local-only state. Sharing a link or pressing back/forward lost the sort. This syncs sort to the query string and restores it on load, matching the existing q/page behaviour.

Closes #310

Changes

  • src/components/ngos/NgoExplorer.tsx
    • Added parseSort() with a SORT_OPTIONS allowlist; unknown/missing values fall back to 'newest'.
    • sortBy now initialises from searchParams.get('sort') instead of hard-coding 'newest'.
    • The existing URL→state reconciliation block (which already restored q and page) now restores sort too, so back/forward navigation works.
    • syncParams() accepts sort and writes it to the URL (clears it when the default 'newest' is selected, to keep shared links tidy — same pattern used for page=1).
    • handleSortChange() persists the new sort and resets to page 1.
  • src/components/ngos/NgoExplorer.test.tsx
    • New test: restores the sort from the URL on mount (asserts the <select> value and that the list is actually ordered by active streams desc).
    • New test: changing the sort writes it to the URL and clears page.

Acceptance criteria

  • Sync sort with the query string and restore it on load.
  • Add a test for restoring the sort.

Testing

Ran the same steps as .github/workflows/ci.yml locally:

  • npm run lint — pass
  • npm run typecheck — pass
  • npm test — pass (2 new tests included)
  • npm run build — pass

Manually verified: ?sort=most-active-streams on load selects that option and orders cards accordingly; changing the sort while on ?q=…&page=2 produces ?q=…&sort=… (page reset to 1); back/forward restores the sort.

Notes

  • Sort is a client-side concern only — no changes needed in page.tsx; the existing <Suspense> boundary already covers useSearchParams().
  • Default 'newest' is omitted from the URL so existing links stay unchanged; only non-default sorts add ?sort=….

@vercel

vercel Bot commented Oct 23, 2026

Copy link
Copy Markdown

@chidii is attempting to deploy a commit to the Ashborne team Team on Vercel.

A member of the Team first needs to authorize it.

@Ashborne267
Ashborne267 merged commit f28e5dc into StreamGive:main Oct 23, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep the NGO explorer sort option in the URL

2 participants