Skip to content

Commit

Permalink
fix: remove unnecessary search params (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansh-saini authored Oct 3, 2023
1 parent 5968cb3 commit 16e4eac
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ const PAGES = [
{
label: TEXTS.timeline_page_title,
key: '/timeline',
searchParamsRequired: true,
},
{
label: TEXTS.gaps_page_title,
key: '/gaps',
searchParamsRequired: true,
},
{
label: TEXTS.realtime_map_page_title,
Expand All @@ -63,6 +65,7 @@ const PAGES = [
{
label: TEXTS.singleline_map_page_title,
key: '/single-line-map',
searchParamsRequired: true,
},
{
label: TEXTS.about_title,
Expand Down Expand Up @@ -117,12 +120,21 @@ const App = () => {
})

useEffect(() => {
setSearchParams({
operatorId: search.operatorId!,
lineNumber: search.lineNumber!,
routeKey: search.routeKey!,
timestamp: search.timestamp.toString(),
})
const page = PAGES.find((page) => page.key === location.pathname)
if (page?.searchParamsRequired) {
const params = new URLSearchParams({ timestamp: search.timestamp.toString() })

if (search.operatorId) {
params.set('operatorId', search.operatorId)
}
if (search.lineNumber) {
params.set('lineNumber', search.lineNumber)
}
if (search.routeKey) {
params.set('routeKey', search.routeKey)
}
setSearchParams(params)
}
}, [search.lineNumber, search.operatorId, search.routeKey, search.timestamp, location.pathname])

const safeSetSearch = useCallback((mutate: (prevState: PageSearchState) => PageSearchState) => {
Expand Down

0 comments on commit 16e4eac

Please sign in to comment.