Puzzle order
This commit is contained in:
parent
4d929ddd96
commit
44a8f9b5cf
2 changed files with 711 additions and 665 deletions
1359
pnpm-lock.yaml
generated
1359
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
@ -3,12 +3,15 @@
|
|||
import { UserContext } from '@/context/user';
|
||||
import { useGroups } from '@/lib/hooks/use-groups';
|
||||
import { usePuzzles } from '@/lib/hooks/use-puzzles';
|
||||
import type { Chapter, Puzzle } from '@/lib/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';
|
||||
|
@ -93,7 +96,17 @@ export default function Puzzles({ token }: { token: string }) {
|
|||
{isInEventGroup(chapter) && (
|
||||
<ul className="flex flex-col space-y-4">
|
||||
{chapter.puzzles &&
|
||||
chapter.puzzles.map((puzzle) => (
|
||||
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;
|
||||
return p1.tags.length-p2.tags.length;
|
||||
}).map((puzzle) => (
|
||||
<PuzzleProp key={puzzle.id} puzzle={puzzle} chapter={chapter} />
|
||||
))}
|
||||
</ul>
|
||||
|
|
Loading…
Add table
Reference in a new issue