Skip to content

Commit

Permalink
support overview image
Browse files Browse the repository at this point in the history
  • Loading branch information
onursumer committed Dec 24, 2024
1 parent 6da54b3 commit 31bec4f
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions components/HtaCenterPage.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
float: left;
width: 200px;
}

.overviewImg {
width: 100%;
max-width: 600px;
}
33 changes: 29 additions & 4 deletions components/HtaCenterPage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import _ from 'lodash';
import { useEffect, useState } from 'react';
import { Container, Row } from 'react-bootstrap';

import { HtaCenter, PrincipalInvestigator } from '../types';
import styles from './HtaCenterPage.module.scss';

export interface HtaCenterPageProps {
id: string;
hta: HtaCenter;
showGrantNumber?: boolean;
}
Expand Down Expand Up @@ -62,20 +64,43 @@ const PrincipalInvestigators = (props: {
}
};

const Overview = (props: { description: string | string[] }) => {
const description = [...[props.description]].flat();
const Overview = (props: { hta: HtaCenter; id: string }) => {
const description = [...[props.hta.description]].flat();
const [hasOverviewImg, setHasOverviewImg] = useState<boolean>(false);
const imgSrc = `/${props.hta.phase}/${props.id}_overview.png`;

// overview image may not exist for all centers
// we need to hide the section in case no image found
useEffect(() => {
fetch(imgSrc)
.then((response) => {
if (response.status === 200) {
setHasOverviewImg(true);
}
})
.catch(() => setHasOverviewImg(false));
}, []);

return (
<>
<h2>Overview</h2>
{description.map((d, index) => (
<p key={index}>{d}</p>
))}
{hasOverviewImg && (
<div className="text-center">
<img
className={styles.overviewImg}
src={imgSrc}
alt={`${props.id}_overview`}
/>
</div>
)}
</>
);
};

const HtaCenterPage = ({ hta, showGrantNumber }: HtaCenterPageProps) => {
const HtaCenterPage = ({ id, hta, showGrantNumber }: HtaCenterPageProps) => {
if (!hta) {
return <div>Loading...</div>;
}
Expand All @@ -85,7 +110,7 @@ const HtaCenterPage = ({ hta, showGrantNumber }: HtaCenterPageProps) => {
<Row className={'contentWrapper'}>
<div className="col">
<h1>{hta.title}</h1>
<Overview description={hta.description} />
<Overview hta={hta} id={id} />
{showGrantNumber && hta.grantNumber && (
<p>
<b>Grant Number</b>: {hta.grantNumber}
Expand Down
2 changes: 1 addition & 1 deletion pages/center/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
getCenter(phase1Centers, params?.id) ||
getCenter(phase2Centers, params?.id);

return { props: { hta } };
return { props: { hta, id: params?.id } };
};

export default HTAPage;
Binary file removed public/HTA3_overview.webp
Binary file not shown.
Binary file removed public/HTA4_overview.webp
Binary file not shown.
Binary file removed public/HTA7_overview.webp
Binary file not shown.
File renamed without changes
Binary file added public/phase1/hta3_overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/phase1/hta4_overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/phase1/hta7_overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 31bec4f

Please sign in to comment.