feat: sort documents by latest date on the Page component (#22)

Co-authored-by: Team1280Programming <Team1280Programming@users.noreply.github.com>
This commit is contained in:
Team 1280 Programming Laptop 2024-02-19 13:50:37 -08:00 committed by GitHub
parent 8a10f9a9bf
commit 409de455f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,19 +19,30 @@ const DocumentCardWrapper = ({
return <DocumentCard doc={doc} href={href} />
}
const getDocumentDate = (id: string) => {
const dates = documents[id].manifest.dates
return dates[dates.length - 1]
}
const Page = () => {
const sortedDocuments = Object.entries(documents).sort((a, b) => {
const docTimestampA = getDocumentDate(a[0])
const docTimestampB = getDocumentDate(b[0])
return docTimestampB - docTimestampA
})
return (
<div className='p-6'>
<h1 className={`${zillaSlab.className} text-6xl text-center mb-10`}>
Documents
</h1>
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4'>
{Object.keys(documents).map((documentShortName) => {
{sortedDocuments.map((entry) => {
return (
<Fragment key={documentShortName}>
<Fragment key={entry[0]}>
<DocumentCardWrapper
key={documentShortName}
params={{ shortName: documentShortName }}
key={entry[0]}
params={{ shortName: entry[0] }}
/>
</Fragment>
)