Skip to content

Commit

Permalink
fix: restaured Sortarticle file (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
LAU-MG committed Sep 2, 2024
1 parent 72ca64c commit 01f8351
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/functions/sortarticles.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
'use client';

export const sortArticles = (articles, exclude) => {
let datesList = [];
const mostRecentArticles = [];
type ArticleAttributes = {
updatedAt: string;
};

type Article = {
attributes: ArticleAttributes;
};

type Category = {
data: Article[];
};

export const sortArticles = (articles: Category[], exclude: number[]): ArticleAttributes[] => {
let datesList: string[] = [];
const mostRecentArticles: ArticleAttributes[] = [];

articles.forEach((category, index) => {
category.data.forEach((data) => {
if (exclude.indexOf(index) == -1) datesList.push(data.attributes.updatedAt);
if (!exclude.includes(index)) {
datesList.push(data.attributes.updatedAt);
}
});
});

datesList = datesList.sort((a, b) => new Date(b) - new Date(a));
datesList = datesList.sort((a, b) => new Date(b).getTime() - new Date(a).getTime());

for (let i = 0; i < datesList.length; i++) {
articles.forEach((category) => {
category.data.forEach((data) => {
if (data.attributes.updatedAt === datesList[i]) mostRecentArticles.push(data.attributes);
if (data.attributes.updatedAt === datesList[i]) {
mostRecentArticles.push(data.attributes);
}
});
});
}
Expand Down

0 comments on commit 01f8351

Please sign in to comment.