Skip to content

Commit

Permalink
Port /pathogens to App Router [#1066]
Browse files Browse the repository at this point in the history
  • Loading branch information
genehack committed Mar 6, 2025
1 parent 40199b3 commit d6f0962
Showing 1 changed file with 69 additions and 55 deletions.
124 changes: 69 additions & 55 deletions static-site/app/pathogens/page.tsx
Original file line number Diff line number Diff line change
@@ -1,63 +1,77 @@
import React from "react";
import {
SmallSpacer,
HugeSpacer,
FlexCenter,
} from "../layouts/generalComponents";
import ListResources from "../components/ListResources/index";
import * as splashStyles from "../components/splash/styles";
import GenericPage from "../layouts/generic-page";
import {coreQuickLinks, coreGroupDisplayNames, coreTiles} from "../../content/resource-listing.yaml";

const title = "Nextstrain-maintained pathogen analyses";
const abstract = (
<>
These data represent analyses and situation-reports produced by the <a href="/team">core Nextstrain team</a>.
Explore analyses produced by others on the <a href="/groups">Groups</a> and <a href="/community">Community</a> pages.
<br/><br/>
We aim to provide a continually-updated view of publicly available data to show pathogen evolution and epidemic spread.
The pipeline used to generate each dataset is available on <a href="https://github.com/nextstrain/">our GitHub page</a> or by loading a dataset and
clicking the &ldquo;built with&rdquo; link at the top of the page.
</>
);

const resourceListingCallback = async () => {
const sourceId = "core"

import FlexCenter from "../../components/flex-center";
import { FocusParagraphCentered } from "../../components/focus-paragraph";
import ListResources from "../../components/list-resources";
import { ResourceListingInfo } from "../../components/list-resources/types";
import { SmallSpacer, HugeSpacer } from "../../components/spacers";
import * as coreResources from "../../content/resource-listing.yaml";

/**
* React Server Component that generates and presents a list of
* pathogen resources.
*/
export default function Pathogens(): React.ReactElement {
return (
<>
<HugeSpacer />
<HugeSpacer />

<h1>Nextstrain-maintained pathogen analyses</h1>

<SmallSpacer />

<FlexCenter>
<FocusParagraphCentered>
These data represent analyses and situation-reports produced by the{" "}
<a href="/team">core Nextstrain team</a>. Explore analyses produced by
others on the <a href="/groups">Groups</a> and{" "}
<a href="/community">Community</a> pages.
<br />
<br />
We aim to provide a continually-updated view of publicly available
data to show pathogen evolution and epidemic spread. The pipeline used
to generate each dataset is available on{" "}
<a href="https://github.com/nextstrain/">our GitHub page</a> or by
loading a dataset and clicking the &ldquo;built with&rdquo; link at
the top of the page.
</FocusParagraphCentered>
</FlexCenter>

<HugeSpacer />

<ListResources
defaultGroupLinks
groupDisplayNames={coreResources["coreGroupDisplayNames"]}
quickLinks={coreResources["coreQuickLinks"]}
resourceType="dataset"
tileData={coreResources["coreTiles"]}
versioned
/>

<HugeSpacer />
</>
);
}

/**
* A callback function used by the <ListResources> component (which
* see) to get the resources to display on the `/pathogens` page.
*
* @returns A Promise that resolves to a ResourceListingInfo
*/
export async function pathogenResourceListingCallback(): Promise<ResourceListingInfo> {
const sourceId = "core";
const sourceUrl = `list-resources/${sourceId}`;

const response = await fetch(sourceUrl, {headers: {accept: "application/json"}});
const response = await fetch(sourceUrl, {
headers: { accept: "application/json" },
});
if (response.status !== 200) {
throw new Error(`fetching data from "${sourceUrl}" returned status code ${response.status}`);
throw new Error(
`fetching data from "${sourceUrl}" returned status code ${response.status}`,
);
}

return (await response.json()).dataset[sourceId];
};

class Index extends React.Component {
render() {
return (
<GenericPage>
<splashStyles.H1>{title}</splashStyles.H1>
<SmallSpacer />

<FlexCenter>
<splashStyles.CenteredFocusParagraph>
{abstract}
</splashStyles.CenteredFocusParagraph>
</FlexCenter>

<HugeSpacer/>

<ListResources resourceType="dataset"
tileData={coreTiles}
quickLinks={coreQuickLinks} defaultGroupLinks
groupDisplayNames={coreGroupDisplayNames}
resourceListingCallback={resourceListingCallback}/>

<HugeSpacer/>
</GenericPage>
);
}
}

export default Index;

0 comments on commit d6f0962

Please sign in to comment.