Order news country-chronologically

This commit is contained in:
DrMint 2022-03-28 16:26:12 +02:00
parent 575e81019a
commit 282c2ee561
1 changed files with 12 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import { getPostsPreview } from "graphql/operations";
import { GetPostsPreviewQuery } from "graphql/operations-types"; import { GetPostsPreviewQuery } from "graphql/operations-types";
import { GetStaticPropsContext } from "next"; import { GetStaticPropsContext } from "next";
import { AppStaticProps, getAppStaticProps } from "queries/getAppStaticProps"; import { AppStaticProps, getAppStaticProps } from "queries/getAppStaticProps";
import { prettyDate } from "queries/helpers";
interface NewsProps extends AppStaticProps { interface NewsProps extends AppStaticProps {
posts: GetPostsPreviewQuery["posts"]["data"]; posts: GetPostsPreviewQuery["posts"]["data"];
@ -16,6 +17,17 @@ interface NewsProps extends AppStaticProps {
export default function News(props: NewsProps): JSX.Element { export default function News(props: NewsProps): JSX.Element {
const { langui, posts } = props; const { langui, posts } = props;
posts
.sort((a, b) => {
const dateA =
a.attributes.date === null ? "9999" : prettyDate(a.attributes.date);
const dateB =
b.attributes.date === null ? "9999" : prettyDate(b.attributes.date);
return dateA.localeCompare(dateB);
})
.reverse();
const subPanel = ( const subPanel = (
<SubPanel> <SubPanel>
<PanelHeader <PanelHeader