Skip to content

Feat/272 search filter persistence#284

Merged
RUKAYAT-CODER merged 3 commits into
rinafcode:mainfrom
JohnOluB:feat/272-search-filter-persistence
Apr 28, 2026
Merged

Feat/272 search filter persistence#284
RUKAYAT-CODER merged 3 commits into
rinafcode:mainfrom
JohnOluB:feat/272-search-filter-persistence

Conversation

@JohnOluB
Copy link
Copy Markdown
Contributor

Summary

Closes #272

Search filters, sort order, and query text reset on navigation because
AdvancedSearchInterface held all state in memory via useAdvancedSearch.
This PR adds URL-based persistence so users never lose their search state.

Changes

src/hooks/useSearchState.ts (new)

A thin composition hook that wraps useAdvancedSearch and adds:

  • URL hydration on mount — restores query, filters, and sort from URL
    params and auto-runs the search if any active state is present.
  • URL sync on state change — pushes every update to the URL via
    router.replace({ scroll: false }), keeping the address bar in sync
    without polluting the browser history stack.
  • External navigation sync — detects browser back/forward and patches
    internal state from the updated searchParams, guarded by a ref to
    prevent update loops.
  • getShareableUrl / copyShareableUrl — returns or copies the
    current canonical URL for sharing filtered views.

URL param mapping:

Param Field
q query text
sort sortBy
types filter.types
topics filter.topics
difficulty filter.difficulty
priceMin / priceMax filter.priceRange
rating filter.rating
page page

Default values are omitted from the URL to keep links clean.

src/components/search/AdvancedSearchInterface.tsx (updated)

  • Swapped useAdvancedSearchuseSearchState (one-line change).
  • hasSearched now initialises from the URL so a page reload after a
    search correctly restores the results view.
  • Added a Share button (lucide Share2) that appears when results
    are active and copies the shareable URL with a ✓ COPIED! confirmation.

Acceptance criteria

  • Filters persist across navigation and page reloads
  • Filtered views are shareable via URL
  • State is restored on return (browser back/forward)
  • No new console errors
  • Lucide icons used throughout (Share2, Check)
  • Tailwind CSS with responsive design

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 28, 2026

@JohnOluB Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER RUKAYAT-CODER merged commit 77926d0 into rinafcode:main Apr 28, 2026
1 of 4 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.

Search Filter Persistence

2 participants