Skip to content

Conversation

ludvigz
Copy link
Member

@ludvigz ludvigz commented Nov 13, 2026

Purpose

Search queries, filters, and sorting were stored in local React state, so users lost their selected settings when refreshing the page or navigating away, and could not share filtered results. This PR stores them in URL query parameters.

Changes

  • Add useCatalogParams hook (frontend/src/hooks/useCatalogParams.ts) that reads and writes search, category, sortBy and sortDirection in the URL. Invalid values are ignored.
  • Remove the shared search state and the key={search} workaround from App.tsx; the header search now navigates to /explore?search=…, so NavBar no longer takes an onSearch prop.
  • Typing in the search field replaces the current history entry (no entry per keystroke); changing filters or sorting adds one, so back/forward restores them. Reset removes the category and sort parameters and keeps the search.
  • Add tests in frontend/src/test/useCatalogParams.test.tsx.

Related issues

Closes #94

Verification

  • `npx vitest run: 31 tests pass (6 new).

Manual testing:

  1. On /explore, set a search, category and sort. The URL updates.
  2. Refresh, or open the URL in a new tab; the same results are shown.
  3. Change filters, then use browser Back/Forward; the filters and results follow.

Checklist

  • I have reviewed my own changes.
  • The changes meet the linked issue's acceptance criteria, where applicable.
  • I have verified the changes and recorded the results above.
  • I have added or updated tests where needed.
  • I have updated documentation where needed.
  • I have included screenshots for visual changes, or marked them not applicable.

@ludvigz ludvigz self-assigned this Nov 13, 2026
@ludvigz ludvigz requested a review from a team as a code owner November 13, 2026 16:58
Copy link
Member

@wilhelsr wilhelsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement to the user experience. URL state handling looks solid, and the tests cover the key scenarios. Approved

@wilhelsr wilhelsr merged commit a86c093 into dev Nov 13, 2026
@wilhelsr wilhelsr deleted the 94-persist-search-filters-and-sorting-in-url branch November 13, 2026 17:10
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants