Skip to content

Commit

Permalink
chore(website): Refactor top navigation items (#2461)
Browse files Browse the repository at this point in the history
* initial refactor

* add potential extra items

* rename var

* Update navigationItems.ts

* Automated code formatting

* update

* Automated code formatting

---------

Co-authored-by: Loculus bot <bot@loculus.org>
  • Loading branch information
theosanderson and Loculus bot committed Aug 20, 2024
1 parent be208eb commit 032268d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
1 change: 1 addition & 0 deletions website/src/routes/extraTopNavigationItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const extraTopNavigationItems = [];
53 changes: 27 additions & 26 deletions website/src/routes/navigationItems.ts
Original file line number Diff line number Diff line change
@@ -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];
}

0 comments on commit 032268d

Please sign in to comment.