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:
parent
8a10f9a9bf
commit
409de455f2
1 changed files with 15 additions and 4 deletions
|
@ -19,19 +19,30 @@ const DocumentCardWrapper = ({
|
||||||
return <DocumentCard doc={doc} href={href} />
|
return <DocumentCard doc={doc} href={href} />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getDocumentDate = (id: string) => {
|
||||||
|
const dates = documents[id].manifest.dates
|
||||||
|
return dates[dates.length - 1]
|
||||||
|
}
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
|
const sortedDocuments = Object.entries(documents).sort((a, b) => {
|
||||||
|
const docTimestampA = getDocumentDate(a[0])
|
||||||
|
const docTimestampB = getDocumentDate(b[0])
|
||||||
|
return docTimestampB - docTimestampA
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='p-6'>
|
<div className='p-6'>
|
||||||
<h1 className={`${zillaSlab.className} text-6xl text-center mb-10`}>
|
<h1 className={`${zillaSlab.className} text-6xl text-center mb-10`}>
|
||||||
Documents
|
Documents
|
||||||
</h1>
|
</h1>
|
||||||
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4'>
|
<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 (
|
return (
|
||||||
<Fragment key={documentShortName}>
|
<Fragment key={entry[0]}>
|
||||||
<DocumentCardWrapper
|
<DocumentCardWrapper
|
||||||
key={documentShortName}
|
key={entry[0]}
|
||||||
params={{ shortName: documentShortName }}
|
params={{ shortName: entry[0] }}
|
||||||
/>
|
/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue