From 11e3ee75fcab0ab54b2bc1713a402c5cc3070c2d Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 1 Dec 2023 17:59:30 +0100 Subject: refactor(pages): refine Topic pages * add useTopic and useTopicsList hooks to refresh data * add a table of contents * add Cypress tests --- src/components/organisms/posts-list/posts-list.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/components/organisms/posts-list/posts-list.tsx') diff --git a/src/components/organisms/posts-list/posts-list.tsx b/src/components/organisms/posts-list/posts-list.tsx index 783bc4e..c4c6fa1 100644 --- a/src/components/organisms/posts-list/posts-list.tsx +++ b/src/components/organisms/posts-list/posts-list.tsx @@ -40,10 +40,22 @@ export type PostData = Pick< Required>; }; +/** + * Method to sort PageLink objects by name. + * + * @param {PageLink} a - A PageLink object. + * @param {PageLink} b - Another PageLink object. + * @returns {1 | -1 | 0} + */ +export const sortPostsByDate = (a: PostData, b: PostData) => + new Date(b.meta.publicationDate).getTime() - + new Date(a.meta.publicationDate).getTime(); + const getPostsByYear = (posts: PostData[]) => { const yearCollection = new Map(); + const sortedPosts = [...posts].sort(sortPostsByDate); - for (const post of posts) { + for (const post of sortedPosts) { const currentPostYear = new Date(post.meta.publicationDate) .getFullYear() .toString(); -- cgit v1.2.3