From 032268ded7dbd4d062e43eeb56b66f8122d74839 Mon Sep 17 00:00:00 2001 From: Theo Sanderson Date: Tue, 20 Aug 2024 11:45:53 +0100 Subject: [PATCH] chore(website): Refactor top navigation items (#2461) * initial refactor * add potential extra items * rename var * Update navigationItems.ts * Automated code formatting * update * Automated code formatting --------- Co-authored-by: Loculus bot --- website/src/routes/extraTopNavigationItems.ts | 1 + website/src/routes/navigationItems.ts | 53 ++++++++++--------- 2 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 website/src/routes/extraTopNavigationItems.ts diff --git a/website/src/routes/extraTopNavigationItems.ts b/website/src/routes/extraTopNavigationItems.ts new file mode 100644 index 000000000..3ec557fed --- /dev/null +++ b/website/src/routes/extraTopNavigationItems.ts @@ -0,0 +1 @@ +export const extraTopNavigationItems = []; diff --git a/website/src/routes/navigationItems.ts b/website/src/routes/navigationItems.ts index d63fcdc7b..1873d977d 100644 --- a/website/src/routes/navigationItems.ts +++ b/website/src/routes/navigationItems.ts @@ -1,46 +1,47 @@ import { bottomNavigationItems } from './bottomNavigationItems.ts'; +import { extraTopNavigationItems } from './extraTopNavigationItems.js'; import { routes } from './routes.ts'; + export const navigationItems = { top: topNavigationItems, bottom: bottomNavigationItems, }; -function topNavigationItems(organism: string | undefined, isLoggedIn: boolean, loginUrl: string | undefined) { - if (organism === undefined) { - return [ - { - text: 'Browse', - path: routes.organismSelectorPage('search'), - }, - { - text: 'Submit', - path: routes.organismSelectorPage('submission'), - }, - { - text: 'SeqSets', - path: routes.seqSetsPage(), - }, - ...(isLoggedIn - ? [{ text: 'My account', path: routes.userOverviewPage() }] - : [{ text: 'Login', path: loginUrl! }]), - ]; - } - +function getSequenceRelatedItems(organism: string | undefined) { return [ { text: 'Browse', - path: routes.searchPage(organism), + path: organism !== undefined ? routes.searchPage(organism) : routes.organismSelectorPage('search'), }, { text: 'Submit', - path: routes.submissionPageWithoutGroup(organism), + path: + organism !== undefined + ? routes.submissionPageWithoutGroup(organism) + : routes.organismSelectorPage('submission'), }, { text: 'SeqSets', path: routes.seqSetsPage(), }, - ...(isLoggedIn - ? [{ text: 'My account', path: routes.userOverviewPage(organism) }] - : [{ text: 'Login', path: loginUrl! }]), ]; } + +function getAccountItem(isLoggedIn: boolean, loginUrl: string | undefined, organism: string | undefined) { + return isLoggedIn + ? { + text: 'My account', + path: organism !== undefined ? routes.userOverviewPage(organism) : routes.userOverviewPage(), + } + : { + text: 'Login', + path: loginUrl!, + }; +} + +function topNavigationItems(organism: string | undefined, isLoggedIn: boolean, loginUrl: string | undefined) { + const sequenceRelatedItems = getSequenceRelatedItems(organism); + const accountItem = getAccountItem(isLoggedIn, loginUrl, organism); + + return [...sequenceRelatedItems, ...extraTopNavigationItems, accountItem]; +}