From 8cdc4ea5c3be79ad0b3640a3adf67326adce84ae Mon Sep 17 00:00:00 2001 From: "Max L." Date: Thu, 23 Nov 2023 20:57:33 +0100 Subject: [PATCH] Fix sorting in carousel --- script.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index 37a2d0c..af565e5 100644 --- a/script.js +++ b/script.js @@ -132,8 +132,6 @@ const displayPost = function(post) { const processPosts = function(posts) { posts = posts.filter((post) => secondsAgo(new Date(post.created_at)) < maxAge); - posts.sort((a, b) => new Date(a.created_at) - new Date(b.created_at)); - return posts; }; @@ -143,6 +141,8 @@ const updateWall = function(posts) { posts = processPosts(posts); + posts.sort((a, b) => new Date(a.created_at) - new Date(b.created_at)); + let ret = 0 posts.forEach(post => ret += displayPost(post)); $('.masonry-grid').masonry('layout'); @@ -155,7 +155,9 @@ const updateCarousel = function(slides, posts) { if (!posts || posts.length === 0) return; posts = processPosts(posts); - + + posts.sort((a, b) => new Date(b.created_at) - new Date(a.created_at)); + // remove slides in carousel slides.innerHTML = ""; var newHTML = ` `