Upgrade puzzle order & remove used import
This commit is contained in:
parent
44a8f9b5cf
commit
f9740813ef
1 changed files with 15 additions and 9 deletions
|
@ -5,13 +5,10 @@ import { useGroups } from '@/lib/hooks/use-groups';
|
||||||
import { usePuzzles } from '@/lib/hooks/use-puzzles';
|
import { usePuzzles } from '@/lib/hooks/use-puzzles';
|
||||||
import type { Chapter, Puzzle, Tag } from '@/lib/puzzles';
|
import type { Chapter, Puzzle, Tag } from '@/lib/puzzles';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { diffieHellman } from 'crypto';
|
|
||||||
import { Tangerine } from 'next/font/google';
|
|
||||||
import { useContext, useState } from 'react';
|
import { useContext, useState } from 'react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import AppLink from './AppLink';
|
import AppLink from './AppLink';
|
||||||
import Button from './Button';
|
import Button from './Button';
|
||||||
import DefaultTags from './DefaultTags';
|
|
||||||
import Dialog from './Dialog';
|
import Dialog from './Dialog';
|
||||||
import Icon from './Icon';
|
import Icon from './Icon';
|
||||||
import Input from './Input';
|
import Input from './Input';
|
||||||
|
@ -99,12 +96,21 @@ export default function Puzzles({ token }: { token: string }) {
|
||||||
chapter.puzzles.sort((p1, p2) => {
|
chapter.puzzles.sort((p1, p2) => {
|
||||||
if(p1.tags == undefined) return 1;
|
if(p1.tags == undefined) return 1;
|
||||||
if(p2.tags == undefined) return -1;
|
if(p2.tags == undefined) return -1;
|
||||||
if(p1.tags.findIndex(tag => tag.name === "easy") >= 0) return -1;
|
let e1 = p1.tags.findIndex(tag => tag.name === "easy") >= 0;
|
||||||
if(p2.tags.findIndex(tag => tag.name === "easy") >= 0) return 1;
|
let e2 = p2.tags.findIndex(tag => tag.name === "easy") >= 0;
|
||||||
if(p1.tags.findIndex(tag => tag.name === "medium") >= 0) return -1;
|
if(e1 && e2) return p1.tags.length-p2.tags.length;
|
||||||
if(p2.tags.findIndex(tag => tag.name === "medium") >= 0) return 1;
|
if(e1) return -1;
|
||||||
if(p1.tags.findIndex(tag => tag.name === "hard") >= 0) return -1;
|
if(e2) return 1;
|
||||||
if(p2.tags.findIndex(tag => tag.name === "hard") >= 0) 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;
|
return p1.tags.length-p2.tags.length;
|
||||||
}).map((puzzle) => (
|
}).map((puzzle) => (
|
||||||
<PuzzleProp key={puzzle.id} puzzle={puzzle} chapter={chapter} />
|
<PuzzleProp key={puzzle.id} puzzle={puzzle} chapter={chapter} />
|
||||||
|
|
Loading…
Add table
Reference in a new issue