diff --git a/ui/Puzzles.tsx b/ui/Puzzles.tsx index a04bb2e..a373207 100644 --- a/ui/Puzzles.tsx +++ b/ui/Puzzles.tsx @@ -5,13 +5,10 @@ import { useGroups } from '@/lib/hooks/use-groups'; import { usePuzzles } from '@/lib/hooks/use-puzzles'; import type { Chapter, Puzzle, Tag } from '@/lib/puzzles'; import { cn } from '@/lib/utils'; -import { diffieHellman } from 'crypto'; -import { Tangerine } from 'next/font/google'; import { useContext, useState } from 'react'; import { useForm } from 'react-hook-form'; import AppLink from './AppLink'; import Button from './Button'; -import DefaultTags from './DefaultTags'; import Dialog from './Dialog'; import Icon from './Icon'; import Input from './Input'; @@ -99,12 +96,21 @@ export default function Puzzles({ token }: { token: string }) { chapter.puzzles.sort((p1, p2) => { if(p1.tags == undefined) return 1; if(p2.tags == undefined) return -1; - if(p1.tags.findIndex(tag => tag.name === "easy") >= 0) return -1; - if(p2.tags.findIndex(tag => tag.name === "easy") >= 0) return 1; - if(p1.tags.findIndex(tag => tag.name === "medium") >= 0) return -1; - if(p2.tags.findIndex(tag => tag.name === "medium") >= 0) return 1; - if(p1.tags.findIndex(tag => tag.name === "hard") >= 0) return -1; - if(p2.tags.findIndex(tag => tag.name === "hard") >= 0) return 1; + let e1 = p1.tags.findIndex(tag => tag.name === "easy") >= 0; + let e2 = p2.tags.findIndex(tag => tag.name === "easy") >= 0; + if(e1 && e2) return p1.tags.length-p2.tags.length; + if(e1) return -1; + if(e2) return 1; + let m1 = p1.tags.findIndex(tag => tag.name === "medium") >= 0; + let m2 = p2.tags.findIndex(tag => tag.name === "medium") >= 0; + if(m1 && m2) return p1.tags.length-p2.tags.length; + if(m1) return -1; + if(m2) return 1; + let h1 = p1.tags.findIndex(tag => tag.name === "hard") >= 0; + let h2 = p2.tags.findIndex(tag => tag.name === "hard") >= 0; + if(h1 && h2) return p1.tags.length-p2.tags.length; + if(h1) return -1; + if(h2) return 1; return p1.tags.length-p2.tags.length; }).map((puzzle) => (