Skip to content

Commit

Permalink
refactor: use words as profile defaultTab
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaMilanese90 committed Sep 13, 2023
1 parent 2a85c62 commit c476ecb
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/components/Profile/History/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ function getTabs(
return defaultTabs
}

const tabsIndexList = {
published: 0,
downloads: 1,
computeJobs: 2
}

export default function HistoryPage({
accountIdentifier
}: {
Expand Down Expand Up @@ -106,17 +112,16 @@ export default function HistoryPage({
const getDefaultIndex = useCallback((): number => {
const url = new URL(location.href)
const defaultTabString = url.searchParams.get('defaultTab')
const defaultTabIndex = /^\d+$/.test(defaultTabString)
? parseInt(defaultTabString)
: 0

// we need to make sure the default index is not bigger than the highest
// tab index available otherwise the Tabs component will display no content
if (accountId === accountIdentifier) {
return defaultTabIndex > 2 ? 2 : defaultTabIndex
}
const defaultTabIndex = tabsIndexList?.[defaultTabString]

if (!defaultTabIndex) return 0
if (
defaultTabIndex === tabsIndexList.computeJobs &&
accountId !== accountIdentifier
)
return 0

return defaultTabIndex > 1 ? 1 : defaultTabIndex
return defaultTabIndex
}, [accountId, accountIdentifier])

useEffect(() => {
Expand Down

0 comments on commit c476ecb

Please sign in to comment.