Skip to content

Commit

Permalink
add campaign leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
starknetdev committed Jan 31, 2024
1 parent 7183685 commit 6c9ea55
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions ui/src/app/components/leaderboard/ScoreTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ const ScoreLeaderboardTable = ({
handleFetchProfileData,
adventurers,
}: ScoreLeaderboardTableProps) => {
const [showAllTime, setShowAllTime] = useState(false);
const [currentPage, setCurrentPage] = useState<number>(1);
const setScreen = useUIStore((state) => state.setScreen);
const setProfile = useUIStore((state) => state.setProfile);
const campaignAdventurers = adventurers.filter(
(score) => score.startBlock! > 942308
);

const displayScores = adventurers?.slice(
(currentPage - 1) * itemsPerPage,
currentPage * itemsPerPage
);

const campaignDisplayScores = campaignAdventurers?.slice(
(currentPage - 1) * itemsPerPage,
currentPage * itemsPerPage
);

const scoreIds = adventurers?.map((score) => score.id ?? 0);

const scoresData = useCustomQuery("topScoresQuery", getScoresInList, {
Expand All @@ -42,8 +52,22 @@ const ScoreLeaderboardTable = ({
};
});

const campaignMergedScores = campaignDisplayScores.map((item1) => {
const matchingItem2 = scoresData?.scores.find(
(item2: Score) => item2.adventurerId === item1.id
);

return {
...item1,
...matchingItem2,
};
});

const scoresWithLords = mergedScores;

const onMainnet = process.env.NEXT_PUBLIC_NETWORK === "mainnet";
const onSepolia = process.env.NEXT_PUBLIC_NETWORK === "sepolia";

const totalPages = Math.ceil(adventurers.length / itemsPerPage);

let previousXp = -1;
Expand Down Expand Up @@ -84,7 +108,15 @@ const ScoreLeaderboardTable = ({

return (
<div className="flex flex-col gap-5 sm:gap-0 sm:flex-row justify-between w-full">
<div className="flex flex-col w-full sm:mr-4 flex-grow-2 p-2 gap-2">
<div className="relative flex flex-col w-full sm:mr-4 flex-grow-2 p-2 gap-2">
{!onMainnet && !onSepolia && (
<Button
className="absolute top-0 right-0"
onClick={() => setShowAllTime(!showAllTime)}
>
{showAllTime ? "Campaign" : "All Time"}
</Button>
)}
{adventurers.length > 0 ? (
<>
<h4 className="text-2xl text-center sm:text-2xl m-0">
Expand All @@ -101,7 +133,10 @@ const ScoreLeaderboardTable = ({
</tr>
</thead>
<tbody>
{scoresWithLords.map((adventurer: any, index: number) => (
{(!onMainnet && !onSepolia && showAllTime
? scoresWithLords
: campaignMergedScores
).map((adventurer: any, index: number) => (
<ScoreRow
key={index}
adventurer={adventurer}
Expand Down

0 comments on commit 6c9ea55

Please sign in to comment.