Skip to content

fix(frontend): replace path params with query params for search#28

Open
tkitsunai wants to merge 1 commit into
nemasu:masterfrom
tkitsunai:fix/search-empty-query-routing
Open

fix(frontend): replace path params with query params for search#28
tkitsunai wants to merge 1 commit into
nemasu:masterfrom
tkitsunai:fix/search-empty-query-routing

Conversation

@tkitsunai

Copy link
Copy Markdown
Contributor

Summary

Fixes ambiguous search routing per #27 — an empty search string used to
either fall through to the Legend page or get misread as exact search,
because both were encoded as positional path segments.

  • App.tsx: route /search/:search_string/:exact?/search (no params)
  • NavBar.tsx: the three search handlers now go through a new
    useSearchNavigation() hook instead of calling useNavigate() directly
  • hooks/useSearchNavigation.ts (new): buildSearchPath(searchQuery, exact)
    is a pure function that builds the query-param path; the hook itself is a
    thin wrapper that just calls navigate() with it
  • Search.tsx: useParamsuseSearchParams, reading q/exact from the
    query string instead of path segments

Test plan

  • Unit tests for buildSearchPath: normal string, exact=true, empty
    string + exact (the original bug case), special characters (spaces,
    slashes, multibyte), and a regression test for a literal "exact"
    search string no longer being mistaken for the exact flag
  • npm run typecheck — no errors
  • npm run check (biome) — no errors
  • Manually verified in browser: empty search, exact search, multibyte
    search, symbol search (/ etc.)

Fixes #27

Empty search strings hit an ambiguity in the path-param route
(/search/:search_string/:exact?): they either fell through to the
Legend page, or (with exact) collapsed to /search/exact and got
misread as searching for the literal string "exact".

Move to query params instead:
- App.tsx: route becomes /search (no params)
- NavBar.tsx: search handlers now go through a new
  useSearchNavigation() hook instead of calling useNavigate() directly
- hooks/useSearchNavigation.ts (new): buildSearchPath(searchQuery,
  exact) is a pure function building the query-param path; the hook
  itself just calls navigate() with it
- Search.tsx: useParams -> useSearchParams, reading q/exact from the
  query string

Fixes nemasu#27
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.

fix(frontend): empty search query causes unintended navigation and search behavior

1 participant