Skip to content

Commit

Permalink
organism selector stays on same page (#1129)
Browse files Browse the repository at this point in the history
  • Loading branch information
theosanderson authored Feb 26, 2024
1 parent bd2848c commit 02a0363
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions website/src/components/Navigation/OrganismSelector.astro
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
---
import { cleanOrganism } from './cleanOrganism';
import { type Organism } from '../../config';
import { routes } from '../../routes';
import IwwaArrowDown from '~icons/iwwa/arrow-down';
const { knownOrganisms, organism } = cleanOrganism(Astro.params.organism);
const label = organism === undefined ? 'Organisms' : organism.displayName;
const firstBitOfUrl = Astro.url.pathname.split('/')[1];
const isOrganismPage = knownOrganisms.some((knownOrganism: Organism) => knownOrganism.key === firstBitOfUrl);
const restOfUrl = Astro.url.pathname.split('/').slice(2).join('/');
---

<div class='dropdown dropdown-hover hidden sm:flex relative'>
Expand All @@ -15,9 +19,17 @@ const label = organism === undefined ? 'Organisms' : organism.displayName;
</label>
<ul tabindex='0' class='dropdown-content z-[1] menu p-1 shadow bg-base-100 rounded-btn absolute top-full -left-4'>
{
knownOrganisms.map((knownOrganism) => (
knownOrganisms.map((knownOrganism: Organism) => (
<li>
<a href={routes.organismStartPage(knownOrganism.key)}>{knownOrganism.displayName}</a>
<a
href={
isOrganismPage
? `/${knownOrganism.key}/${restOfUrl}`
: routes.organismStartPage(knownOrganism.key)
}
>
{knownOrganism.displayName}
</a>
</li>
))
}
Expand Down

0 comments on commit 02a0363

Please sign in to comment.