From c476ecb374ba0c25cd59e6c7bea2291ebec60226 Mon Sep 17 00:00:00 2001 From: Luca Milanese Date: Wed, 13 Sep 2023 17:34:19 +0200 Subject: [PATCH] refactor: use words as profile defaultTab --- src/components/Profile/History/index.tsx | 25 ++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/components/Profile/History/index.tsx b/src/components/Profile/History/index.tsx index 56d29c30c..2cb8bd869 100644 --- a/src/components/Profile/History/index.tsx +++ b/src/components/Profile/History/index.tsx @@ -51,6 +51,12 @@ function getTabs( return defaultTabs } +const tabsIndexList = { + published: 0, + downloads: 1, + computeJobs: 2 +} + export default function HistoryPage({ accountIdentifier }: { @@ -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(() => {