a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

sort posts by most recent

+31 -18
+31 -18
app/lish/[handle]/[publication]/page.tsx
··· 51 51 return ( 52 52 <ThemeProvider entityID={null}> 53 53 <div>publication index page </div> 54 - {publication.documents_in_publications.map((doc) => { 55 - if (!doc.documents) return null; 56 - let uri = new AtUri(doc.documents.uri); 57 - let record = doc.documents.data as PubLeafletDocument.Record; 58 - return ( 59 - <React.Fragment key={doc.documents?.uri}> 60 - <div className="flex w-full "> 61 - <Link 62 - href={`/lish/${params.handle}/${params.publication}/${uri.rkey}`} 63 - className="publishedPost grow flex flex-col gap-2 hover:!no-underline" 64 - > 65 - <h3 className="text-primary">{record.title}</h3> 66 - </Link> 67 - </div> 68 - <hr className="last:hidden border-border-light" /> 69 - </React.Fragment> 70 - ); 71 - })} 54 + {publication.documents_in_publications 55 + .filter((d) => !!d?.documents) 56 + .sort((a, b) => { 57 + let aRecord = a.documents?.data! as PubLeafletDocument.Record; 58 + let bRecord = a.documents?.data! as PubLeafletDocument.Record; 59 + const aDate = aRecord.publishedAt 60 + ? new Date(aRecord.publishedAt) 61 + : new Date(0); 62 + const bDate = bRecord.publishedAt 63 + ? new Date(bRecord.publishedAt) 64 + : new Date(0); 65 + return bDate.getTime() - aDate.getTime(); // Sort by most recent first 66 + }) 67 + .map((doc) => { 68 + if (!doc.documents) return null; 69 + let uri = new AtUri(doc.documents.uri); 70 + let record = doc.documents.data as PubLeafletDocument.Record; 71 + return ( 72 + <React.Fragment key={doc.documents?.uri}> 73 + <div className="flex w-full "> 74 + <Link 75 + href={`/lish/${params.handle}/${params.publication}/${uri.rkey}`} 76 + className="publishedPost grow flex flex-col gap-2 hover:!no-underline" 77 + > 78 + <h3 className="text-primary">{record.title}</h3> 79 + </Link> 80 + </div> 81 + <hr className="last:hidden border-border-light" /> 82 + </React.Fragment> 83 + ); 84 + })} 72 85 </ThemeProvider> 73 86 ); 74 87 } catch (e) {