Skip to content

Commit f8cbc60

Browse files
committed
sorted posts and limit to two
1 parent 34ccd0d commit f8cbc60

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/components/Announcements.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ async function AnnoucementPosts() {
2222

2323
const announcements = await PullForumData('https://forum.vatsim-scandinavia.org/api/discussions?filter[tag]=announcements');
2424

25+
announcements.sort((a: any, b:any) => {
26+
const dateA = new Date(a.attributes.createdAt);
27+
const dateB = new Date(b.attributes.createdAt);
28+
return dateB.getTime() - dateA.getTime();
29+
});
30+
2531
for (const post of await announcements) {
2632
const firstPost = await PullForumData('https://forum.vatsim-scandinavia.org/api/posts?filter[id]=' + post.relationships.firstPost.data.id);
2733
const firstPostContent = await firstPost[0].attributes.contentHtml;
@@ -41,7 +47,7 @@ const Annoucements = () => {
4147

4248
return (
4349
<>
44-
{data.map((post) => (
50+
{data.splice(0,2).map((post) => (
4551
<div className="p-2 mt-2 mb-4 hover:bg-white dark:hover:bg-black hover:brightness-[95%]" key={post.slug}>
4652
<a href={'https://forum.vatsim-scandinavia.org/d/'+post.slug} target="_blank">
4753
<div className="flex">

0 commit comments

Comments
 (0)