Skip to content

Commit

Permalink
Fix(hall-of-fame): fix bug in dynamic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ThulinaWickramasinghe committed Aug 17, 2024
1 parent 88e269d commit 988e424
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
File renamed without changes.
4 changes: 1 addition & 3 deletions src/components/layout/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ const Header = ({ className }) => {
className="hidden xsm:flex gap-2"
>
<div className="group flex gap-1.5 items-center">
<span className="link ml-8 xl:ml-0">
{isHallOfFame ? "Leaderboard" : "Hall of Fame"}
</span>
<span className="link ml-8 xl:ml-0">{isHallOfFame ? "Leaderboard" : "Hall of Fame"}</span>
<LinkIcon className="transform -rotate-45 before:w-[1.2rem] xl:before:w-[0.6rem] before:group-hover:w-[1.45rem] xl:before:group-hover:w-[0.75rem] translate-y-[-0.1rem]" />
</div>
</Link>
Expand Down
22 changes: 22 additions & 0 deletions src/hooks/past-data.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect, useState } from "react";

const usePastData = ({ round, ghostLegion, year = 2023 }) => {
const [pastData, setPastData] = useState({});

useEffect(() => {
const fetchPastLeaderboadData = async () => {
let path = round == 1 ? "round1" : ghostLegion == true ? "ghost-legion" : "final";
const data = (await import(`../../data/annual-leaderboard/${year}/${path}.json`)).default;
// console.log('Before mapping', data);
const transformedData = data.map((item, index) => ({ ...item, place: index + 1 }));
// console.log('After mapping', data);
setPastData(transformedData);
};

fetchPastLeaderboadData();
}, [round, ghostLegion]);

return pastData;
};

export default usePastData;
18 changes: 5 additions & 13 deletions src/pages/hall-of-fame.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ScoreCardSkeleton } from "@/components";
import { ScoreCard } from "@/components/home";
import { filters as filterData, sorts as sortData } from "@/filters";
import { useTitle } from "@/hooks";
import { computePastLeaderboardDataPath } from "@/utils/compute-data-path";
import usePastData from "@/hooks/past-data";
import {
AnimatedSwitcher,
Filters,
Expand All @@ -22,20 +22,12 @@ const HallOfFame = () => {
const [page, setPage] = useState(1);
const [filters, setFilters] = useState(computeFilterQuery(filterData));
const [sorts, setSorts] = useState(computeSortQuery(sortData));
const [scores, setScores] = useState({});

const { rounds, round, roundKey, onRoundChange } = useRound();
const { ghostLegion, toggleGhostLegion } = useGhostLegion();
const dataPath = computePastLeaderboardDataPath({ page, filters, sorts, round, ghostLegion, year: 2023 });

useEffect(() => {
const fetchPastLeaderboadData = async () => {
const data = (await import(`../../data/annual-leaderboard/${dataPath}.json`)).default;
setScores(data);
};

fetchPastLeaderboadData();
}, [dataPath]);
const scores = usePastData({
round,
ghostLegion
});

useEffect(() => {
if (page !== 1) setPage(1);
Expand Down
5 changes: 0 additions & 5 deletions src/utils/compute-data-path.js

This file was deleted.

0 comments on commit 988e424

Please sign in to comment.