Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/journal styling #548

Merged
merged 7 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,22 @@ const PreviewContainer = styled.div`
`;

const DocumentHeading = styled.h1`
text-align: center;
margin: 0;
`;

const AuthorsSection = styled.div`
display: flex;
flex-direction: column;
align-items: center;
gap: 2rem;
`;
const AuthorsSectionHeader = styled.div`
text-align: center;
`;

const KeyPoint = styled.li`
list-style: disc;
`;

const SectionContainer = styled.section`
display: flex;
Expand Down Expand Up @@ -404,34 +411,56 @@ function JournalPdfPreview() {
.slice(0, 3);

const contacts = useMemo(() => {
return contacts_link?.reduce(
(acc, contact_link, i) => {
const { contact, affiliations } = contact_link;
// Get list of unique affiliations
let affiliations = new Set();
contacts_link?.forEach(({ affiliations: contactAffiliations }) => {
contactAffiliations?.forEach((affiliation) => {
affiliations.add(affiliation);
});
});

const hasAffiliation = affiliations && affiliations.length > 0;
if (hasAffiliation) {
acc.affiliations_list.push(affiliations);
}
// create contacts list component with superscripts
let contacts = [];
contacts_link?.forEach(
({ contact, affiliations: contactAffiliations }, i) => {
const hasAffiliation =
contactAffiliations && contactAffiliations.length > 0;

let contactEmail = contact.mechanisms.find(
(mechanism) => mechanism.mechanism_type === 'Email'
)?.mechanism_value;

const item = (
<span key={contact.id}>
<strong>{getContactName(contact, { full: true })}</strong>
{hasAffiliation && <sup>{acc.affiliations_list.length}</sup>}
{i < acc.maxIndex && <span>, </span>}
{i === acc.maxIndex - 1 && <span>and </span>}
<strong>
{getContactName(contact, { full: true })}
{contactEmail && ` (${contactEmail})`}
</strong>
{hasAffiliation &&
contactAffiliations.map((affiliation, j) => {
return (
<>
<sup>
{Array.from(affiliations).indexOf(affiliation) + 1}
</sup>
<sup>
{j < contactAffiliations.length - 1 && <span>, </span>}
</sup>
</>
);
})}
{i < contacts_link.length - 1 && <span>, </span>}
{i === contacts_link.length - 2 && <span>and </span>}
</span>
);

acc.items.push(item);

return acc;
},
{
affiliations_list: [],
items: [],
maxIndex: (contacts_link.length ?? 0) - 1
contacts.push(item);
}
);
return {
items: contacts,
affiliations_list: Array.from(affiliations),
maxIndex: (contacts_link?.length ?? 0) - 1
};
}, [contacts_link]);

const referencesUseIndex = useMemo(
Expand Down Expand Up @@ -542,38 +571,24 @@ function JournalPdfPreview() {
<PreviewContainer ref={contentRef}>
<DocumentHeading> {resolveTitle(atbd.title)} </DocumentHeading>
<AuthorsSection>
<div>{contacts?.items}</div>
<AuthorsSectionHeader>{contacts?.items}</AuthorsSectionHeader>
<div>
{contacts?.affiliations_list.map((affiliations, i) => (
{contacts?.affiliations_list.map((affiliation, i) => (
// eslint-disable-next-line react/no-array-index-key
<div key={i}>
<sup>{i + 1}</sup> {affiliations.join(', ')}
<sup>{i + 1}</sup> {affiliation}
</div>
))}
</div>
</AuthorsSection>
<Section id='key_points' title='Key Points:' skipNumbering>
<ul>
{threeKeyPoints?.map((keyPoint) => (
<li key={keyPoint}>{keyPoint}</li>
{threeKeyPoints.map((keyPoint) => (
<KeyPoint key={keyPoint}>{keyPoint}</KeyPoint>
))}
</ul>
</Section>
<div>
<DataList>
<dt>Version</dt>
<dd>{version}</dd>
</DataList>
<DataList>
<dt>Release Date</dt>
<dd>TBD</dd>
</DataList>
<DataList>
<dt>DOI</dt>
<dd>TBD</dd>
</DataList>
</div>
<Section id='abstract' title='Abstract' skipNumbering>
<Section id='abstract' title='Abstract' skipNumbering breakBeforePage>
<ContentView value={abstract} />
</Section>
<Section
Expand All @@ -584,7 +599,7 @@ function JournalPdfPreview() {
<ContentView value={plain_summary} />
{keywords && keywords.length > 0 && (
<DataList>
<dt>Keywords:</dt>
<dt>Keywords</dt>
<dd>{keywords.map(({ label }) => label).join(', ')}</dd>
</DataList>
)}
Expand Down
2 changes: 2 additions & 0 deletions app/assets/scripts/utils/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function formatAuthors(authors, type = 'reference') {
}

export function sortReferences(refA, refB) {
if (!refA || !refB) return 0;
const hasAuthorsA = 'authors' in refA && refA.authors.length > 0;
const hasAuthorsB = 'authors' in refB && refB.authors.length > 0;
const hasYearA = 'year' in refA;
Expand Down Expand Up @@ -232,6 +233,7 @@ export const formatReference = (reference, type = 'jsx') => {
};

export function formatCitation(reference) {
if (!reference) return '';
const { authors, year, title } = reference;
const authorsStr = formatAuthors(authors, 'citation') || title;
const yearStr = year || 'n.d.';
Expand Down
Loading