Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

feat: sort challenge by user submission (#997)

Nicolas Beaussart58356513cb6d
diff --git a/apps/web/src/app/[locale]/explore/_components/explore-section.tsx b/apps/web/src/app/[locale]/explore/_components/explore-section.tsx
index 27d5f7c4..d6b7f0f6 100644
--- a/apps/web/src/app/[locale]/explore/_components/explore-section.tsx
+++ b/apps/web/src/app/[locale]/explore/_components/explore-section.tsx
@@ -65,11 +65,22 @@ export async function ExploreSection({ title, tag, redirectRoute }: SectionProps
<section className="relative flex w-full flex-col overflow-hidden rounded-[2.5rem]">
<Carousel>
{challenges
- .sort((a, b) =>
- difficultyToNumber[a.difficulty] !== difficultyToNumber[b.difficulty]
+ .sort((a, b) => {
+ const aHasSubmission = a?.submission?.length && a.submission.length > 0;
+ const bHasSubmission = b?.submission?.length && b.submission.length > 0;
+
+ if (aHasSubmission && !bHasSubmission) {
+ return -1;
+ }
+
+ if (!aHasSubmission && bHasSubmission) {
+ return 1;
+ }
+
+ return difficultyToNumber[a.difficulty] !== difficultyToNumber[b.difficulty]
? difficultyToNumber[a.difficulty] - difficultyToNumber[b.difficulty]
- : a.name.localeCompare(b.name),
- )
+ : a.name.localeCompare(b.name);
+ })
.map((challenge) => (
<Link
className="group snap-center focus:outline-none sm:w-[330px] xl:w-[333px]"