From 1ffc8af70e4f64ecaeb2cb9b94274d2da3e94377 Mon Sep 17 00:00:00 2001 From: Web Dev Cody Date: Fri, 2 Feb 2024 01:14:34 -0500 Subject: [PATCH] sort by votes --- src/app/thumbnails/[thumbnailId]/page.tsx | 142 ++++++++++++++++------ 1 file changed, 104 insertions(+), 38 deletions(-) diff --git a/src/app/thumbnails/[thumbnailId]/page.tsx b/src/app/thumbnails/[thumbnailId]/page.tsx index edef84a..4fddca7 100644 --- a/src/app/thumbnails/[thumbnailId]/page.tsx +++ b/src/app/thumbnails/[thumbnailId]/page.tsx @@ -136,6 +136,14 @@ export default function ThumbnailPage() { : thumbnail.voteIds.includes(user._id)) ); + const sortedImages = thumbnail.images + .map((image) => image) + .sort((a, b) => { + const aVotes = getVotesFor(thumbnail, a); + const bVotes = getVotesFor(thumbnail, b); + return bVotes - aVotes; + }); + return (
@@ -152,47 +160,105 @@ export default function ThumbnailPage() {
-
- - -
- - -
- {currentImageIndex + 1} of {thumbnail.images.length} + {!hasVoted && ( +
+ + +
+ + +
+ {currentImageIndex + 1} of {thumbnail.images.length} +
+ +
+
+ )} + + {hasVoted && ( +
+ {sortedImages.map((imageId) => ( +
+
+ image test a + +
+ + + + CN + + +
+
+ {thumbnail.title} +
+
+ {thumbnail.name} +
+
+
152K Views
+ + {formatDistance( + new Date(thumbnail._creationTime), + new Date(), + { + addSuffix: true, + } + )} +
+
+
+
- +
+ +
+ {getVotesFor(thumbnail, imageId)} votes +
+
+
+ ))}
-
+ )}