Skip to content

Commit

Permalink
use visibleTabs instead of tabs for filter out old tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
vuongnmdevblock committed Sep 4, 2024
1 parent 24a18be commit 9dacb79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/pages/profile/[name]/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const ProfileContent = ({ isSelf, isLoading: parentIsLoading, name }: Props) =>
name,
decodedName: profile?.decodedName,
normalisedName,
tabs,
visibileTabs,
tab,
})
}, [profile?.decodedName, normalisedName, name, isSelf, router, tab])
Expand Down
15 changes: 11 additions & 4 deletions src/utils/shouldRedirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type RouteParams = {
name: string | undefined
decodedName: string | undefined
normalisedName: string | undefined
tabs: readonly string[]
tab: string | undefined
visibileTabs: readonly string[]
tab: string
}

'DnsClaim.tsx': {
Expand Down Expand Up @@ -99,7 +99,7 @@ export const shouldRedirect = (
['Profile.tsx', { isSelf: P.boolean, name: P.string }],
(_params) => _params && router.isReady,
(_params) => {
const { name, isSelf, decodedName, normalisedName, tabs, tab } = _params[1]
const { name, isSelf, decodedName, normalisedName, visibileTabs, tab } = _params[1]

if (
name !== decodedName &&
Expand Down Expand Up @@ -137,8 +137,15 @@ export const shouldRedirect = (
return router.replace(`${destination}/${name}`)
}

if (!tab || !tabs.includes(tab)) {
const hasValidTab = visibileTabs.includes(tab)
const tabQuery = tab !== 'profile' && hasValidTab ? `?tab=${tab}` : ''

if (!hasValidTab) {
console.log('rerouting to profile')
return router.replace(`${destination}/${normalisedName}`)
} else {
console.log(`rerouting to ${tabQuery}`)
return router.replace(`${destination}/${name}${tabQuery}`)
}
},
)
Expand Down

0 comments on commit 9dacb79

Please sign in to comment.