Change sort base on scoreMax
This commit is contained in:
parent
228c980ffb
commit
f654936e45
1 changed files with 1 additions and 20 deletions
|
@ -151,26 +151,7 @@ export default function Puzzles({ token }: { token: string }) {
|
||||||
<ul className="mt-4 flex flex-col space-y-4">
|
<ul className="mt-4 flex flex-col space-y-4">
|
||||||
{filteredData &&
|
{filteredData &&
|
||||||
filteredData
|
filteredData
|
||||||
.sort((p1, p2) => {
|
.sort((a, b) => a.scoreMax - b.scoreMax)
|
||||||
const p1Tags = p1.tags || [];
|
|
||||||
const p2Tags = p2.tags || [];
|
|
||||||
const p1Easy = p1Tags.some((tag) => tag.name === 'easy');
|
|
||||||
const p2Easy = p2Tags.some((tag) => tag.name === 'easy');
|
|
||||||
if (p1Easy !== p2Easy) {
|
|
||||||
return p1Easy ? -1 : 1;
|
|
||||||
}
|
|
||||||
const p1Medium = p1Tags.some((tag) => tag.name === 'medium');
|
|
||||||
const p2Medium = p2Tags.some((tag) => tag.name === 'medium');
|
|
||||||
if (p1Medium !== p2Medium) {
|
|
||||||
return p1Medium ? -1 : 1;
|
|
||||||
}
|
|
||||||
const p1Hard = p1Tags.some((tag) => tag.name === 'hard');
|
|
||||||
const p2Hard = p2Tags.some((tag) => tag.name === 'hard');
|
|
||||||
if (p1Hard !== p2Hard) {
|
|
||||||
return p1Hard ? -1 : 1;
|
|
||||||
}
|
|
||||||
return p1Tags.length - p2Tags.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