diff --git a/lefthook.yml b/lefthook.yml index 7f5a84c..f0cad28 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -3,10 +3,10 @@ pre-commit: commands: format: glob: "*.{js,ts,jsx}" - run: npm run format && git add . + run: npm run format {staged_files} && git add {staged_files} lint: glob: "*.{js,ts,jsx}" - run: npm run lint && git add . + run: npm run lint {staged_files} && git add {staged_files} commit-msg: commands: diff --git a/src/components/home/score-board/index.jsx b/src/components/home/score-board/index.jsx new file mode 100644 index 0000000..aa6b33c --- /dev/null +++ b/src/components/home/score-board/index.jsx @@ -0,0 +1,101 @@ +import { useEffect, useState } from "react"; +import { twMerge } from "tailwind-merge"; +import { ScoreCardSkeleton } from "@/components"; +import { ScoreCard } from "@/components/home"; +import { filters as filterData, sorts as sortData } from "@/filters"; +import { useTitle } from "@/hooks"; +import { + AnimatedSwitcher, + Filters, + NoRecords, + Pagination, + Sorts, + TwinSwitch +} from "@sliit-foss/bashaway-ui/components"; +import { useGhostLegion, useRound } from "@sliit-foss/bashaway-ui/hooks"; +import { Ghost } from "@sliit-foss/bashaway-ui/icons"; +import { Footnote, Title } from "@sliit-foss/bashaway-ui/typography"; +import { computeFilterQuery, computeSortQuery } from "@sliit-foss/bashaway-ui/utils"; + +const ScoreBoard = ({ pageTitle, title, subTitle, useFetchData }) => { + const [page, setPage] = useState(1); + const [filters, setFilters] = useState(computeFilterQuery(filterData)); + const [sorts, setSorts] = useState(computeSortQuery(sortData)); + + const { rounds, round, roundKey, onRoundChange } = useRound(); + const { ghostLegion, toggleGhostLegion } = useGhostLegion(); + const { data: scores, isFetching } = useFetchData({ page, filters, sorts, round, ghostLegion }); + + useEffect(() => { + if (page !== 1) setPage(1); + }, [filters, sorts, round, ghostLegion]); + + useTitle(pageTitle); + + return ( + <> +
+
+ {title} + + {subTitle} + + +
+
+ +
+
+ + Ghost Legion + + +
+ +
+
+ } + alternateComponent={ + scores?.data?.docs?.length ? ( + <> + {scores.data.docs.map((item, index) => ( + + ))} + + ) : ( +
+ +
+ ) + } + /> +
+ setPage(newPage)} + totalPages={scores?.data?.totalPages} + /> +
+
+ + ); +}; + +export default ScoreBoard; diff --git a/src/components/layout/header.jsx b/src/components/layout/header.jsx index 055c2e6..f6c1bb0 100644 --- a/src/components/layout/header.jsx +++ b/src/components/layout/header.jsx @@ -1,8 +1,10 @@ import { useState } from "react"; import { RxCross1, RxHamburgerMenu } from "react-icons/rx"; import { Link } from "react-router-dom"; +import { useLocation } from "react-router-dom"; import { twMerge } from "tailwind-merge"; import { portalURL } from "@/constants"; +import { HALL_OF_FAME } from "@/constants/routes"; import { useBreakpoint } from "@/hooks"; import { BashawayLeaderboard } from "@/icons"; import { AnimatedSwitcher, Button } from "@sliit-foss/bashaway-ui/components"; @@ -18,6 +20,10 @@ const Header = ({ className }) => { const breakpoints = useBreakpoint(); + const { pathname } = useLocation(); + + const isHallOfFame = pathname === HALL_OF_FAME; + return (
{ : "opacity-0 pointer-events-none xl:opacity-100 xl:pointer-events-auto" )} > + window.scrollTo({ top: 0, behavior: "smooth" })} + aria-label="Home" + className="ml-[-1.6125rem] gap-2" + > +
+ {isHallOfFame ? "Leaderboard" : "Hall of Fame"} +
+
- The competition + The Competition
diff --git a/src/constants/annual-leaderboard/2023/final.json b/src/constants/annual-leaderboard/2023/final.json new file mode 100644 index 0000000..b521023 --- /dev/null +++ b/src/constants/annual-leaderboard/2023/final.json @@ -0,0 +1,74 @@ +{ + "data": [ + { + "name": "TrackTech", + "email": "radith.20@cse.mrt.ac.lk", + "university": "University of Moratuwa", + "eliminated": false, + "score": 700 + }, + { + "name": "HereForTheBytes", + "email": "hereforthebytes@gmail.com", + "university": "UCSC", + "eliminated": false, + "score": 475 + }, + { + "name": "' OR 1=1 --", + "email": "nisaldasunpriya@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 425 + }, + { + "name": "REISUB", + "email": "nirmalsavinda29@gmail.com", + "university": "UCSC", + "eliminated": false, + "score": 300 + }, + { + "name": "The BroCode", + "email": "sasikasankalana321@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 275 + }, + { + "name": "iCoders", + "email": "sandaruwanwgma@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 250 + }, + { + "name": "4bit", + "email": "patalee2001@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 250 + }, + { + "name": "MegaMinds", + "email": "kavindudamsith9@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 225 + }, + { + "name": "5H4D0W\\ G4RD3N", + "email": "qjoyal@gmail.com", + "university": "SLIIT", + "eliminated": false, + "score": 150 + }, + { + "name": "WeDoNotSow", + "email": "baqirhabeeb@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 50 + } + ] +} diff --git a/src/constants/annual-leaderboard/2023/ghost-legion.json b/src/constants/annual-leaderboard/2023/ghost-legion.json new file mode 100644 index 0000000..48f8054 --- /dev/null +++ b/src/constants/annual-leaderboard/2023/ghost-legion.json @@ -0,0 +1,788 @@ +{ + "data": [ + { + "name": "TrackTech", + "email": "radith.20@cse.mrt.ac.lk", + "university": "University of Moratuwa", + "eliminated": false, + "score": 700 + }, + { + "name": "HereForTheBytes", + "email": "hereforthebytes@gmail.com", + "university": "UCSC", + "eliminated": false, + "score": 475 + }, + { + "name": "' OR 1=1 --", + "email": "nisaldasunpriya@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 425 + }, + { + "name": "REISUB", + "email": "nirmalsavinda29@gmail.com", + "university": "UCSC", + "eliminated": false, + "score": 300 + }, + { + "name": "The BroCode", + "email": "sasikasankalana321@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 275 + }, + { + "name": "iCoders", + "email": "sandaruwanwgma@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 250 + }, + { + "name": "4bit", + "email": "patalee2001@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 250 + }, + { + "name": "MegaMinds", + "email": "kavindudamsith9@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 225 + }, + { + "name": "5H4D0W\\ G4RD3N", + "email": "qjoyal@gmail.com", + "university": "SLIIT", + "eliminated": false, + "score": 150 + }, + { + "name": "WeDoNotSow", + "email": "baqirhabeeb@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 50 + }, + { + "name": "Runtime Terror", + "email": "lightspeed.runtime@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Team PhoeniXdeV", + "email": "sanuuthaya02@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "hackOne", + "email": "tekshanmadhawa324@gmail.com", + "university": "University of Jaffna", + "eliminated": true, + "score": 0 + }, + { + "name": "Access_denied", + "email": "maniltenuka@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 0 + }, + { + "name": "HARIS", + "email": "isuruvihan@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 0 + }, + { + "name": "Error By Night", + "email": "it21206450@my.sliit.lk", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "A.A", + "email": "atheefofficial6@gmail.com", + "university": "SLTC", + "eliminated": true, + "score": 0 + }, + { + "name": "Debug Entity", + "email": "prasadnirmal2021@gmail.com", + "university": "SLTC", + "eliminated": true, + "score": 0 + }, + { + "name": "What_the_Hack", + "email": "whatthehack.sltc@gmail.com", + "university": "SLTC", + "eliminated": true, + "score": 0 + }, + { + "name": "Strikers", + "email": "sakithrandeev@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Code Geeks", + "email": "yasodalasiru@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Tech Titans", + "email": "techtitans444@gmail.com", + "university": "University of Vavuniya", + "eliminated": true, + "score": 0 + }, + { + "name": "OneZero", + "email": "ravinduhapuarachchi@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "I am Atomic", + "email": "chirathpansilu@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "tERROR ", + "email": "kavirangot@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Cyber Creepers", + "email": "glenperera2002@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Lambda Baryons", + "email": "baryonslambda@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Coding Owls", + "email": "chamodiindrejith14@gmail.com", + "university": "University of Vavuniya", + "eliminated": true, + "score": 0 + }, + { + "name": "PySquardCoders", + "email": "thasvithu7@gmail.com", + "university": "University of Vavuniya", + "eliminated": true, + "score": 0 + }, + { + "name": "shiganshina :)", + "email": "wasath.vt@gmail.com", + "university": "NSBM", + "eliminated": true, + "score": 0 + }, + { + "name": "Ruhuna 1.0", + "email": "nevaasahanmath@gmail.com", + "university": "University of Ruhuna", + "eliminated": true, + "score": 0 + }, + { + "name": "SoloRider", + "email": "chirathb14@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Marcopolo", + "email": "yashrashh05@gmail.com", + "university": "NSBM", + "eliminated": true, + "score": 0 + }, + { + "name": "FullBash/.", + "email": "wdilantha66@gmail.com", + "university": "NSBM", + "eliminated": true, + "score": 0 + }, + { + "name": "One2Seven", + "email": "udayanga.aj@outlook.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Kamino", + "email": "cst20004@std.uwu.ac.lk", + "university": "Uva Wellassa University", + "eliminated": true, + "score": 0 + }, + { + "name": "Meta Killers", + "email": "maleeshasparrow@gmail.com", + "university": "EUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "Bytes_Coders", + "email": "sonacode44@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Code-Crafters", + "email": "navodyanethmi3@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Code Wizards", + "email": "codewizards123@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "CodeQuest", + "email": "lumini.20221981@iit.ac.lk", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "ByteSpark", + "email": "mithilathilochanaj@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Scripters", + "email": "kanishkaekanayaka1004@outlook.com", + "university": "KDU", + "eliminated": true, + "score": 0 + }, + { + "name": "8 bit shrooms", + "email": "yasithasanjula2018@gmail.com", + "university": "EUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "Astronauts", + "email": "risithanadimal531@gmail.com", + "university": "EUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "404 Not Found", + "email": "pasinduravimal@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 0 + }, + { + "name": "Code Smokers", + "email": "madhawalakshan718@gmail.com", + "university": "EUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "Binary Blitz", + "email": "binaryblitz50@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Scorpions", + "email": "contact.scorpions.info@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Head Hunters", + "email": "ranushmithila45@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "PowerInfinity#1", + "email": "powerinfinitypow@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "PowerTech", + "email": "powertechpow@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Blazers", + "email": "ryanpussadeniya@gmail.com", + "university": "USJ", + "eliminated": true, + "score": 0 + }, + { + "name": "Solo Scripting Sorcerer", + "email": "senadhee1999@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "OneManArmy", + "email": "abdul.qadirv98@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 0 + }, + { + "name": "Rubber Ducky", + "email": "shathurshmanoharan@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Hugs 4 Bugs", + "email": "lasindumvp2001@gmail.com", + "university": "SUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "Dracode", + "email": "dracode0.0@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Automation", + "email": "sashinsirichandra@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Romio", + "email": "someshchandih@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Last Chance", + "email": "onaliy21@gmail.com", + "university": "NSBM", + "eliminated": true, + "score": 0 + }, + { + "name": "Meraki", + "email": "chamudisiriwardena@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 0 + }, + { + "name": "Satan Slaves", + "email": "dilax.18@cse.mrt.ac.lk", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "BinaryX", + "email": "dilshankavinda371@gmail.com", + "university": "University of Ruhuna", + "eliminated": true, + "score": 0 + }, + { + "name": "mCoders", + "email": "arwijesuriya.7@gmail.com", + "university": "University of Vavuniya", + "eliminated": true, + "score": 0 + }, + { + "name": "White Hats", + "email": "dinukaekanayaka18@gmail.com", + "university": "University of Kelaniya", + "eliminated": true, + "score": 0 + }, + { + "name": "InitialX", + "email": "minetheducation@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "mercode", + "email": "pathirana.sithmal@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Tech Titanians", + "email": "techtitans2323@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Nova", + "email": "sanjulagathsara@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "v3nom", + "email": "it23195752@my.sliit.lk", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Team 404", + "email": "weareteam404@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "hyperX", + "email": "koshala19299@gmail.com", + "university": "University of Ruhuna", + "eliminated": true, + "score": 0 + }, + { + "name": "Zyndicate", + "email": "nimeshshamika@gmail.com", + "university": "University of Kelaniya", + "eliminated": true, + "score": 0 + }, + { + "name": "The X Order", + "email": "ashani.sansala16@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "AnonymousHat", + "email": "4n0nym0ush4t@gmail.com", + "university": "University of Kelaniya", + "eliminated": true, + "score": 0 + }, + { + "name": "BASH Picca", + "email": "banula.19@cse.mrt.ac.lk", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "codeDRINKERS", + "email": "dulankabewardhana123@gmail.com", + "university": "University of Ruhuna", + "eliminated": true, + "score": 0 + }, + { + "name": "Team consoleLog", + "email": "veerasaravanan.20220157@iit.ac.lk", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Janitha Prabodha", + "email": "janitha.20220212@iit.ac.lk", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "CodeCraft Samurai", + "email": "hashan_madusanka@outlook.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Vangaurd", + "email": "cst21050@std.uwu.ac.lk", + "university": "Uva Wellassa University", + "eliminated": true, + "score": 0 + }, + { + "name": "Epic byte", + "email": "mnethmi27@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "LEO", + "email": "leodassma@gmail.com", + "university": "University of Peradeniya", + "eliminated": true, + "score": 0 + }, + { + "name": "11double0", + "email": "vidushsanidu07@gmail.com", + "university": "University of Peradeniya", + "eliminated": true, + "score": 0 + }, + { + "name": "Redshifts", + "email": "lakindu.21@cse.mrt.ac.lk", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Code Conjurers", + "email": "supung.20@cse.mrt.ac.lk", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "DevXcreW", + "email": "sahanchandrasena462@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 0 + }, + { + "name": "Script_Kiddies", + "email": "himasharandil@gmail.com", + "university": "KDU", + "eliminated": true, + "score": 0 + }, + { + "name": "Hash_Coders", + "email": "anuththaradias27@gmail.com", + "university": "SUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "Coding Blinders", + "email": "codingblinders@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 0 + }, + { + "name": "Team WEBMates", + "email": "thevendranvithursan@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "PixelPioneers", + "email": "shanika010712@gmail.com", + "university": "SUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "one-ticket-please", + "email": "adeeshamanthila@outlook.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Nasty_Owls", + "email": "yugantha1468@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "$cript_R0b0ts", + "email": "yasela2014@gmail.com", + "university": "University of Peradeniya", + "eliminated": true, + "score": 0 + }, + { + "name": "Mugiwara", + "email": "shrikarsan@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Shell Warriors", + "email": "hirunaofficial@gmail.com", + "university": "ICBT", + "eliminated": true, + "score": 0 + }, + { + "name": "Team Cygnus", + "email": "chamikasandaru01@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "URAQT", + "email": "gokulabisheak12@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "BinaryBrilliance", + "email": "s19410@sci.pdn.ac.lk", + "university": "University of Peradeniya", + "eliminated": true, + "score": 0 + }, + { + "name": "NoCode", + "email": "rajivapitiwaduge@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Night Wings", + "email": "gihangajanayaka08@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "LuciferArchangel", + "email": "luminde9958@gmail.com", + "university": "University of Vavuniya", + "eliminated": true, + "score": 0 + }, + { + "name": "ALHAM", + "email": "alham@duck.com", + "university": "-", + "eliminated": true, + "score": 0 + }, + { + "name": "Team36T", + "email": "ramesharukshan3@gmail.com", + "university": "NIBM", + "eliminated": true, + "score": 0 + }, + { + "name": "CATS", + "email": "samithkarunathilake@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "HackSquad", + "email": "nipunsandeepakck@gmail.com", + "university": "University of Peradeniya", + "eliminated": true, + "score": 0 + }, + { + "name": "A random team", + "email": "proushothkoushal@gmail.com", + "university": "NIBM", + "eliminated": true, + "score": 0 + }, + { + "name": "ByteBlaze", + "email": "pehandassanayaka@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Hackhive", + "email": "hmsvhettiarachchi@std.foc.sab.ac.lk", + "university": "SUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "The Council", + "email": "theogcouncillors@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + } + ] +} diff --git a/src/constants/annual-leaderboard/2023/round1.json b/src/constants/annual-leaderboard/2023/round1.json new file mode 100644 index 0000000..6ed986b --- /dev/null +++ b/src/constants/annual-leaderboard/2023/round1.json @@ -0,0 +1,788 @@ +{ + "data": [ + { + "name": "TrackTech", + "email": "radith.20@cse.mrt.ac.lk", + "university": "University of Moratuwa", + "eliminated": false, + "score": 550 + }, + { + "name": "HereForTheBytes", + "email": "hereforthebytes@gmail.com", + "university": "UCSC", + "eliminated": false, + "score": 525 + }, + { + "name": "' OR 1=1 --", + "email": "nisaldasunpriya@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 525 + }, + { + "name": "REISUB", + "email": "nirmalsavinda29@gmail.com", + "university": "UCSC", + "eliminated": false, + "score": 350 + }, + { + "name": "5H4D0W\\ G4RD3N", + "email": "qjoyal@gmail.com", + "university": "SLIIT", + "eliminated": false, + "score": 300 + }, + { + "name": "WeDoNotSow", + "email": "baqirhabeeb@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 225 + }, + { + "name": "The BroCode", + "email": "sasikasankalana321@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 200 + }, + { + "name": "MegaMinds", + "email": "kavindudamsith9@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 200 + }, + { + "name": "4bit", + "email": "patalee2001@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 150 + }, + { + "name": "iCoders", + "email": "sandaruwanwgma@gmail.com", + "university": "University of Moratuwa", + "eliminated": false, + "score": 150 + }, + { + "name": "FullBash/.", + "email": "wdilantha66@gmail.com", + "university": "NSBM", + "eliminated": true, + "score": 150 + }, + { + "name": "OneZero", + "email": "ravinduhapuarachchi@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 150 + }, + { + "name": "HackSquad", + "email": "nipunsandeepakck@gmail.com", + "university": "University of Peradeniya", + "eliminated": true, + "score": 150 + }, + { + "name": "Nasty_Owls", + "email": "yugantha1468@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 125 + }, + { + "name": "The X Order", + "email": "ashani.sansala16@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 125 + }, + { + "name": "Shell Warriors", + "email": "hirunaofficial@gmail.com", + "university": "ICBT", + "eliminated": true, + "score": 125 + }, + { + "name": "$cript_R0b0ts", + "email": "yasela2014@gmail.com", + "university": "University of Peradeniya", + "eliminated": true, + "score": 125 + }, + { + "name": "shiganshina :)", + "email": "wasath.vt@gmail.com", + "university": "NSBM", + "eliminated": true, + "score": 125 + }, + { + "name": "OneManArmy", + "email": "abdul.qadirv98@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 100 + }, + { + "name": "Marcopolo", + "email": "yashrashh05@gmail.com", + "university": "NSBM", + "eliminated": true, + "score": 100 + }, + { + "name": "11double0", + "email": "vidushsanidu07@gmail.com", + "university": "University of Peradeniya", + "eliminated": true, + "score": 100 + }, + { + "name": "BinaryBrilliance", + "email": "s19410@sci.pdn.ac.lk", + "university": "University of Peradeniya", + "eliminated": true, + "score": 100 + }, + { + "name": "mercode", + "email": "pathirana.sithmal@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 100 + }, + { + "name": "CATS", + "email": "samithkarunathilake@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 75 + }, + { + "name": "one-ticket-please", + "email": "adeeshamanthila@outlook.com", + "university": "IIT", + "eliminated": true, + "score": 75 + }, + { + "name": "Team 404", + "email": "weareteam404@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 75 + }, + { + "name": "Mugiwara", + "email": "shrikarsan@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 75 + }, + { + "name": "Code Conjurers", + "email": "supung.20@cse.mrt.ac.lk", + "university": "University of Moratuwa", + "eliminated": true, + "score": 50 + }, + { + "name": "Hackhive", + "email": "hmsvhettiarachchi@std.foc.sab.ac.lk", + "university": "SUSL", + "eliminated": true, + "score": 50 + }, + { + "name": "Bytes_Coders", + "email": "sonacode44@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 50 + }, + { + "name": "Coding Blinders", + "email": "codingblinders@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 25 + }, + { + "name": "ByteSpark", + "email": "mithilathilochanaj@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 25 + }, + { + "name": "Ruhuna 1.0", + "email": "nevaasahanmath@gmail.com", + "university": "University of Ruhuna", + "eliminated": true, + "score": 25 + }, + { + "name": "Runtime Terror", + "email": "lightspeed.runtime@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Team PhoeniXdeV", + "email": "sanuuthaya02@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "hackOne", + "email": "tekshanmadhawa324@gmail.com", + "university": "University of Jaffna", + "eliminated": true, + "score": 0 + }, + { + "name": "Access_denied", + "email": "maniltenuka@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 0 + }, + { + "name": "HARIS", + "email": "isuruvihan@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 0 + }, + { + "name": "Error By Night", + "email": "it21206450@my.sliit.lk", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "A.A", + "email": "atheefofficial6@gmail.com", + "university": "SLTC", + "eliminated": true, + "score": 0 + }, + { + "name": "Debug Entity", + "email": "prasadnirmal2021@gmail.com", + "university": "SLTC", + "eliminated": true, + "score": 0 + }, + { + "name": "What_the_Hack", + "email": "whatthehack.sltc@gmail.com", + "university": "SLTC", + "eliminated": true, + "score": 0 + }, + { + "name": "Strikers", + "email": "sakithrandeev@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Code Geeks", + "email": "yasodalasiru@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Tech Titans", + "email": "techtitans444@gmail.com", + "university": "University of Vavuniya", + "eliminated": true, + "score": 0 + }, + { + "name": "I am Atomic", + "email": "chirathpansilu@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "tERROR ", + "email": "kavirangot@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Cyber Creepers", + "email": "glenperera2002@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Lambda Baryons", + "email": "baryonslambda@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Coding Owls", + "email": "chamodiindrejith14@gmail.com", + "university": "University of Vavuniya", + "eliminated": true, + "score": 0 + }, + { + "name": "PySquardCoders", + "email": "thasvithu7@gmail.com", + "university": "University of Vavuniya", + "eliminated": true, + "score": 0 + }, + { + "name": "SoloRider", + "email": "chirathb14@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "One2Seven", + "email": "udayanga.aj@outlook.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Kamino", + "email": "cst20004@std.uwu.ac.lk", + "university": "Uva Wellassa University", + "eliminated": true, + "score": 0 + }, + { + "name": "Meta Killers", + "email": "maleeshasparrow@gmail.com", + "university": "EUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "Code-Crafters", + "email": "navodyanethmi3@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Code Wizards", + "email": "codewizards123@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "CodeQuest", + "email": "lumini.20221981@iit.ac.lk", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Scripters", + "email": "kanishkaekanayaka1004@outlook.com", + "university": "KDU", + "eliminated": true, + "score": 0 + }, + { + "name": "8 bit shrooms", + "email": "yasithasanjula2018@gmail.com", + "university": "EUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "Astronauts", + "email": "risithanadimal531@gmail.com", + "university": "EUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "404 Not Found", + "email": "pasinduravimal@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 0 + }, + { + "name": "Code Smokers", + "email": "madhawalakshan718@gmail.com", + "university": "EUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "Binary Blitz", + "email": "binaryblitz50@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Scorpions", + "email": "contact.scorpions.info@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Head Hunters", + "email": "ranushmithila45@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "PowerInfinity#1", + "email": "powerinfinitypow@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "PowerTech", + "email": "powertechpow@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Blazers", + "email": "ryanpussadeniya@gmail.com", + "university": "USJ", + "eliminated": true, + "score": 0 + }, + { + "name": "Solo Scripting Sorcerer", + "email": "senadhee1999@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Rubber Ducky", + "email": "shathurshmanoharan@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Hugs 4 Bugs", + "email": "lasindumvp2001@gmail.com", + "university": "SUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "Dracode", + "email": "dracode0.0@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Automation", + "email": "sashinsirichandra@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Romio", + "email": "someshchandih@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Last Chance", + "email": "onaliy21@gmail.com", + "university": "NSBM", + "eliminated": true, + "score": 0 + }, + { + "name": "Meraki", + "email": "chamudisiriwardena@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 0 + }, + { + "name": "Satan Slaves", + "email": "dilax.18@cse.mrt.ac.lk", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "BinaryX", + "email": "dilshankavinda371@gmail.com", + "university": "University of Ruhuna", + "eliminated": true, + "score": 0 + }, + { + "name": "mCoders", + "email": "arwijesuriya.7@gmail.com", + "university": "University of Vavuniya", + "eliminated": true, + "score": 0 + }, + { + "name": "White Hats", + "email": "dinukaekanayaka18@gmail.com", + "university": "University of Kelaniya", + "eliminated": true, + "score": 0 + }, + { + "name": "InitialX", + "email": "minetheducation@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Tech Titanians", + "email": "techtitans2323@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Nova", + "email": "sanjulagathsara@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "v3nom", + "email": "it23195752@my.sliit.lk", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "hyperX", + "email": "koshala19299@gmail.com", + "university": "University of Ruhuna", + "eliminated": true, + "score": 0 + }, + { + "name": "Zyndicate", + "email": "nimeshshamika@gmail.com", + "university": "University of Kelaniya", + "eliminated": true, + "score": 0 + }, + { + "name": "AnonymousHat", + "email": "4n0nym0ush4t@gmail.com", + "university": "University of Kelaniya", + "eliminated": true, + "score": 0 + }, + { + "name": "BASH Picca", + "email": "banula.19@cse.mrt.ac.lk", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "codeDRINKERS", + "email": "dulankabewardhana123@gmail.com", + "university": "University of Ruhuna", + "eliminated": true, + "score": 0 + }, + { + "name": "Team consoleLog", + "email": "veerasaravanan.20220157@iit.ac.lk", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Janitha Prabodha", + "email": "janitha.20220212@iit.ac.lk", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "CodeCraft Samurai", + "email": "hashan_madusanka@outlook.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "Vangaurd", + "email": "cst21050@std.uwu.ac.lk", + "university": "Uva Wellassa University", + "eliminated": true, + "score": 0 + }, + { + "name": "Epic byte", + "email": "mnethmi27@gmail.com", + "university": "IIT", + "eliminated": true, + "score": 0 + }, + { + "name": "LEO", + "email": "leodassma@gmail.com", + "university": "University of Peradeniya", + "eliminated": true, + "score": 0 + }, + { + "name": "Redshifts", + "email": "lakindu.21@cse.mrt.ac.lk", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "DevXcreW", + "email": "sahanchandrasena462@gmail.com", + "university": "UCSC", + "eliminated": true, + "score": 0 + }, + { + "name": "Script_Kiddies", + "email": "himasharandil@gmail.com", + "university": "KDU", + "eliminated": true, + "score": 0 + }, + { + "name": "Hash_Coders", + "email": "anuththaradias27@gmail.com", + "university": "SUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "Team WEBMates", + "email": "thevendranvithursan@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "PixelPioneers", + "email": "shanika010712@gmail.com", + "university": "SUSL", + "eliminated": true, + "score": 0 + }, + { + "name": "Team Cygnus", + "email": "chamikasandaru01@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "URAQT", + "email": "gokulabisheak12@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "NoCode", + "email": "rajivapitiwaduge@gmail.com", + "university": "University of Moratuwa", + "eliminated": true, + "score": 0 + }, + { + "name": "Night Wings", + "email": "gihangajanayaka08@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "LuciferArchangel", + "email": "luminde9958@gmail.com", + "university": "University of Vavuniya", + "eliminated": true, + "score": 0 + }, + { + "name": "ALHAM", + "email": "alham@duck.com", + "university": "-", + "eliminated": true, + "score": 0 + }, + { + "name": "Team36T", + "email": "ramesharukshan3@gmail.com", + "university": "NIBM", + "eliminated": true, + "score": 0 + }, + { + "name": "A random team", + "email": "proushothkoushal@gmail.com", + "university": "NIBM", + "eliminated": true, + "score": 0 + }, + { + "name": "ByteBlaze", + "email": "pehandassanayaka@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + }, + { + "name": "The Council", + "email": "theogcouncillors@gmail.com", + "university": "SLIIT", + "eliminated": true, + "score": 0 + } + ] +} diff --git a/src/constants/index.js b/src/constants/index.js index e6425b4..7110900 100644 --- a/src/constants/index.js +++ b/src/constants/index.js @@ -1,2 +1,3 @@ export * from "./hyperlinks"; export * from "./socials"; +export * from "./routes"; diff --git a/src/constants/routes.js b/src/constants/routes.js new file mode 100644 index 0000000..546dc22 --- /dev/null +++ b/src/constants/routes.js @@ -0,0 +1,2 @@ +export const HOME = "/"; +export const HALL_OF_FAME = "/hall-of-fame"; diff --git a/src/pages/hall-of-fame.jsx b/src/pages/hall-of-fame.jsx new file mode 100644 index 0000000..d396655 --- /dev/null +++ b/src/pages/hall-of-fame.jsx @@ -0,0 +1,15 @@ +import ScoreBoard from "@/components/home/score-board"; +import { useFetchPastLeaderboardsQuery } from "@/store/api"; + +const HallOfFame = () => { + return ( + + ); +}; + +export default HallOfFame; diff --git a/src/pages/home.jsx b/src/pages/home.jsx index abf61f7..47540bf 100644 --- a/src/pages/home.jsx +++ b/src/pages/home.jsx @@ -1,103 +1,14 @@ -import { useEffect, useState } from "react"; -import { twMerge } from "tailwind-merge"; -import { ScoreCardSkeleton } from "@/components"; -import { ScoreCard } from "@/components/home"; -import { filters as filterData, sorts as sortData } from "@/filters"; -import { useTitle } from "@/hooks"; +import ScoreBoard from "@/components/home/score-board"; import { useFetchLeaderboardQuery } from "@/store/api"; -import { - AnimatedSwitcher, - Filters, - NoRecords, - Pagination, - Sorts, - TwinSwitch -} from "@sliit-foss/bashaway-ui/components"; -import { useGhostLegion, useRound } from "@sliit-foss/bashaway-ui/hooks"; -import { Ghost } from "@sliit-foss/bashaway-ui/icons"; -import { Footnote, Title } from "@sliit-foss/bashaway-ui/typography"; -import { computeFilterQuery, computeSortQuery } from "@sliit-foss/bashaway-ui/utils"; const Home = () => { - const [page, setPage] = useState(1); - const [filters, setFilters] = useState(computeFilterQuery(filterData)); - const [sorts, setSorts] = useState(computeSortQuery(sortData)); - - const { rounds, round, roundKey, onRoundChange } = useRound(); - - const { ghostLegion, toggleGhostLegion } = useGhostLegion(); - - const { data: scores, isFetching } = useFetchLeaderboardQuery({ page, filters, sorts, round, ghostLegion }); - - useEffect(() => { - if (page !== 1) setPage(1); - }, [filters, sorts, round, ghostLegion]); - - useTitle("Leaderboard | Bashaway"); - return ( - <> -
-
- The Leaderboard - - A place where your true colors show off despite all the differences - - -
-
- -
-
- - Ghost Legion - - -
- -
-
- } - alternateComponent={ - scores?.data?.docs?.length ? ( - <> - {scores.data.docs.map((item, index) => ( - - ))} - - ) : ( -
- -
- ) - } - /> -
- setPage(newPage)} - totalPages={scores?.data?.totalPages} - /> -
-
- + ); }; diff --git a/src/pages/index.jsx b/src/pages/index.jsx index c9918f0..6b339ed 100644 --- a/src/pages/index.jsx +++ b/src/pages/index.jsx @@ -1,2 +1,3 @@ export { default as NotFound } from "./404"; export { default as Home } from "./home"; +export { default as HallOfFame } from "./hall-of-fame"; diff --git a/src/routes/index.jsx b/src/routes/index.jsx index afa52a3..6ce4d14 100644 --- a/src/routes/index.jsx +++ b/src/routes/index.jsx @@ -1,13 +1,15 @@ import { Route, Routes, useLocation } from "react-router-dom"; import { AnimatePresence } from "framer-motion"; -import { Home, NotFound } from "@/pages"; +import { HALL_OF_FAME, HOME } from "@/constants"; +import { HallOfFame, Home, NotFound } from "@/pages"; const AnimatedRoutes = () => { const location = useLocation(); return ( - } /> + } /> + } /> } /> diff --git a/src/store/api/leaderboard.js b/src/store/api/leaderboard.js deleted file mode 100644 index 50ef0fc..0000000 --- a/src/store/api/leaderboard.js +++ /dev/null @@ -1,49 +0,0 @@ -import { createApi } from "@reduxjs/toolkit/query/react"; -import { orderBy } from "lodash"; -import { isRegex } from "@/utils"; -import baseQuery from "./base"; - -export const leaderboardApi = createApi({ - reducerPath: "leaderboardApi", - baseQuery, - endpoints: (builder) => ({ - fetchLeaderboard: builder.query({ - query: ({ round, ghostLegion }) => `/api/leaderboard?round=${round}&ghost_legion=${ghostLegion}`, - transformResponse: (response, _, arg) => { - const { page, filters, sorts } = arg; - response.data = response.data.map((item, index) => ({ ...item, place: index + 1 })); - filters?.split("&").forEach((filter) => { - let [key, value] = filter.split("="); - key = key.replace("filter[", "").replace("]", ""); - response.data = response.data.filter((item) => - isRegex(value) ? item[key].match(new RegExp(value.slice(1, -1), "i")) : item[key] === value - ); - }); - if (sorts) { - const [keys, values] = sorts.split("&").reduce( - (acc, sort) => { - let [key, value] = sort.split("="); - key = key.replace("sort[", "").replace("]", ""); - acc[0].push(key); - acc[1].push(value === "1" ? "asc" : "desc"); - return acc; - }, - [[], []] - ); - response.data = orderBy(response.data, keys, values); - } - const totalPages = Math.ceil(response.data.length / 10); - response.data = response.data.slice((page - 1) * 10, page * 10); - return { - data: { - docs: response.data, - totalPages - }, - message: response.message - }; - } - }) - }) -}); - -export const { useFetchLeaderboardQuery, useLazyFetchLeaderboardQuery } = leaderboardApi; diff --git a/src/store/api/leaderboard/index.js b/src/store/api/leaderboard/index.js new file mode 100644 index 0000000..96f15a3 --- /dev/null +++ b/src/store/api/leaderboard/index.js @@ -0,0 +1,34 @@ +import { createApi } from "@reduxjs/toolkit/query/react"; +import baseQuery from "../base"; +import transformLeaderboardData from "./transformer"; + +export const leaderboardApi = createApi({ + reducerPath: "leaderboardApi", + baseQuery, + endpoints: (builder) => ({ + fetchLeaderboard: builder.query({ + query: ({ round, ghostLegion }) => `/api/leaderboard?round=${round}&ghost_legion=${ghostLegion}`, + transformResponse: transformLeaderboardData + }), + fetchPastLeaderboards: builder.query({ + queryFn: async ({ year = 2023, round, ghostLegion, page, filters, sorts }) => { + let path = round === 1 ? "round1" : ghostLegion === true ? "ghost-legion" : "final"; + + try { + const data = await import(`../../../constants/annual-leaderboard/${year}/${path}.json`); + const transformedData = transformLeaderboardData({ ...data.default }, undefined, { page, filters, sorts }); + return { data: transformedData }; + } catch (error) { + console.error("Failed to fetch data dynamically"); + } + } + }) + }) +}); + +export const { + useFetchLeaderboardQuery, + useLazyFetchLeaderboardQuery, + useFetchPastLeaderboardsQuery, + useLazyFetchPastLeaderboardsQuery +} = leaderboardApi; diff --git a/src/store/api/leaderboard/transformer.js b/src/store/api/leaderboard/transformer.js new file mode 100644 index 0000000..7693483 --- /dev/null +++ b/src/store/api/leaderboard/transformer.js @@ -0,0 +1,45 @@ +import { default as orderBy } from "lodash"; +import { isRegex } from "@/utils"; + +const transformLeaderboardData = (response, _, arg) => { + const { page, filters, sorts } = arg; + + response.data = response.data.map((item, index) => ({ ...item, place: index + 1 })); + + filters?.split("&").forEach((filter) => { + let [key, value] = filter.split("="); + key = key.replace("filter[", "").replace("]", ""); + + response.data = response.data.filter((item) => + isRegex(value) ? item[key].match(new RegExp(value.slice(1, -1), "i")) : item[key] === value + ); + }); + + if (sorts) { + const [keys, values] = sorts.split("&").reduce( + (acc, sort) => { + let [key, value] = sort.split("="); + key = key.replace("sort[", "").replace("]", ""); + acc[0].push(key); + acc[1].push(value === "1" ? "asc" : "desc"); + return acc; + }, + [[], []] + ); + + response.data = orderBy(response.data, keys, values); + } + + const totalPages = Math.ceil(response.data.length / 10); + response.data = response.data.slice((page - 1) * 10, page * 10); + + return { + data: { + docs: response.data, + totalPages + }, + message: response.message + }; +}; + +export default transformLeaderboardData;