diff --git a/src/app/author/[author]/AuthorDisplay.tsx b/src/app/author/[author]/AuthorDisplay.tsx index 6a6acf8..a95aeef 100644 --- a/src/app/author/[author]/AuthorDisplay.tsx +++ b/src/app/author/[author]/AuthorDisplay.tsx @@ -3,6 +3,9 @@ import { Fragment } from 'react' import { affiliations, nationalities, authors } from '../../db/data' import { Zilla_Slab } from 'next/font/google' import { notFound } from 'next/navigation' +import DocumentCard from '@/app/components/DocumentCard' +import findDocumentsByAuthor from './findDocumentsByAuthor' +import { redirect } from 'next/navigation' // for server side const zillaSlab = Zilla_Slab({ subsets: ['latin'], weight: ['500'] }) @@ -16,6 +19,8 @@ export default function AuthorDisplay({ const { name, affiliation, image, nationality, formerAffiliations } = data + const authorsDocuments = findDocumentsByAuthor(author) + const MainPosition = () => { const mainAffiliationShort = affiliation[0].split('@')[1] const mainPosition = affiliation[0].split('@')[0] @@ -55,7 +60,7 @@ export default function AuthorDisplay({ return ( <>

- Other Positions: + Other Positions

{affiliation.slice(1).map((a: string, i: number) => { const position = a.split('@')[0] @@ -80,7 +85,7 @@ export default function AuthorDisplay({ return ( <>

- Former Positions: + Former Positions

{formerAffiliations?.map((a: string, i: number) => { const position = a.split('@')[0] @@ -159,7 +164,7 @@ export default function AuthorDisplay({

- Ethnicity and Nationality: + Ethnicity and Nationality

{nationality.map((n: string) => ( @@ -169,6 +174,16 @@ export default function AuthorDisplay({ ))}
+ {authorsDocuments.length > 0 && ( + <> +

+ Published documents +

+ {authorsDocuments.map((d) => ( + + ))} + + )} ) diff --git a/src/app/author/[author]/findDocumentsByAuthor.ts b/src/app/author/[author]/findDocumentsByAuthor.ts new file mode 100644 index 0000000..de7454b --- /dev/null +++ b/src/app/author/[author]/findDocumentsByAuthor.ts @@ -0,0 +1,28 @@ +import { Document, documents } from '@/app/db/data' + +// Assuming the types Document, DocumentStatus, and reviewer are defined as provided in your question + +// Interface for the return output +interface DocumentWithSlug { + slug: string + doc: Document +} + +export default function findDocumentsByAuthor( + authorId: string +): DocumentWithSlug[] { + // Initialize an empty array to store the results + const result: DocumentWithSlug[] = [] + + // Iterate over the documents object entries + for (const [slug, doc] of Object.entries(documents)) { + // Check if the authorId is present in the document's authors array + if (doc.manifest.authors.includes(authorId)) { + // If present, push the document along with its slug to the results array + result.push({ slug, doc }) + } + } + + // Return the results array + return result +} diff --git a/src/app/components/AuthorDocuments.tsx b/src/app/components/AuthorDocuments.tsx new file mode 100644 index 0000000..96df11c --- /dev/null +++ b/src/app/components/AuthorDocuments.tsx @@ -0,0 +1,8 @@ +/* this component is likely extremely inefficient so it should only be used in +server side static components */ + +export default function AuthorDocuments({ + authorId, +}: Readonly<{ authorId: string }>) { + return
{authorId}
+} diff --git a/src/app/components/DocumentCard.tsx b/src/app/components/DocumentCard.tsx new file mode 100644 index 0000000..f3fa0d0 --- /dev/null +++ b/src/app/components/DocumentCard.tsx @@ -0,0 +1,41 @@ +import { Document } from '@/app/db/data' +import { Zilla_Slab } from 'next/font/google' +import { Authors, Topics } from './DataDisplay' +import { ItemBadge, Status } from './Badges' +import { epoch2datestring } from '@/app/utils/epoch2datestring' +import Link from 'next/link' + +const zillaSlab = Zilla_Slab({ subsets: ['latin'], weight: ['500'] }) + +const DocumentCard = ({ doc, href }: { doc: Document; href: string }) => { + const { manifest, abstract } = doc + const { title, authors, topics, dates, status, type } = manifest + return ( + +
+

{title}

+

+ +

+

+ Last updated on {epoch2datestring(dates[dates.length - 1])} +

+

+ +

+
+ +
+

Abstract

+

+ {abstract.substring(0, 500) + (abstract.length > 500 ? '...' : '')} +

+
+ + ) +} + +export default DocumentCard diff --git a/src/app/utils/actions.ts b/src/app/utils/actions.ts new file mode 100644 index 0000000..7045715 --- /dev/null +++ b/src/app/utils/actions.ts @@ -0,0 +1,7 @@ +'use server' + +import { redirect } from 'next/navigation' + +export async function navigate(data: FormData) { + redirect(`/posts/${data.get('id')}`) +}