Skip to content

Commit

Permalink
Archive leaderboards data & use hard coded
Browse files Browse the repository at this point in the history
  • Loading branch information
NiftyAndy committed Jun 20, 2024
1 parent c236fbf commit dea61f0
Show file tree
Hide file tree
Showing 13 changed files with 80,054 additions and 65 deletions.
2 changes: 1 addition & 1 deletion apps/app/src/app/(public-routes)/leaderboards/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const LeaderboardPage = () => {
return (
<>
<Typography mb={4} variant="h2">
Leaderboards
Leaderboards (Archived)
</Typography>
<LeaderBoards />
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use client';

import { useEffect, useState } from 'react';
import dynamic from 'next/dynamic';
import Image from 'next/image';
import { useTheme } from '@nl/theme';
import { Box, CircularProgress, Typography } from '@mui/material';
import { GOOGLE_ANALYTICS } from '@/constants/google-analytics';
import { getLeaderboardRankAnalyticsEventName } from '@/constants/leaderboard';
import { getLeaderboardRankAnalyticsEventName } from '@/constants/leaderboards';
import useAuth from '@/hooks/useAuth';
import usePlayerProfile from '@/hooks/usePlayerProfile';
import { ResponsiveTable } from '@nl/ui/mui';
Expand All @@ -32,22 +33,27 @@ export default function EnhancedTable({
selectedTable,
selectedTimeFilter,
}: TableProps): JSX.Element | null {
const [page, setPage] = useState(0);
const [count, setCount] = useState(0);
const [rowsPerPage] = useState(10);
const [paginationModel, setPaginationModel] = useState({
pageSize: 50,
page: 0,
});
const [rows, setData] = useState<DataType[] | null>();
const [myRank, setMyRank] = useState<number>();
const { isLoggedIn } = useAuth();
const { palette } = useTheme();
const { profile } = usePlayerProfile();

const fetchTopData = async () => {
setPage(0);
setPaginationModel(model => ({
pageSize: model.pageSize,
page: 0,
}));
const returnValue: ReturnDataType = await fetchScores(
selectedGame,
selectedTable.key,
selectedTimeFilter,
rowsPerPage,
paginationModel.pageSize,
0,
);
const leaderBoardValue: any = [];
Expand All @@ -66,13 +72,13 @@ export default function EnhancedTable({
}, [selectedGame, selectedTable.key, selectedTimeFilter]);

const handleChangePage = async (newPage: number) => {
if (rows && (newPage + 1) * rowsPerPage > rows?.length && rows?.length < count) {
if (rows && (newPage + 1) * paginationModel.pageSize > rows?.length && rows?.length < count) {
const returnValue: ReturnDataType = await fetchScores(
selectedGame,
selectedTable.key,
selectedTimeFilter,
rowsPerPage,
newPage * rowsPerPage,
paginationModel.pageSize,
newPage * paginationModel.pageSize,
);
const leaderBoardValue: any = [];
returnValue.data.forEach((value: any) => {
Expand All @@ -81,9 +87,15 @@ export default function EnhancedTable({
setData([...rows, ...leaderBoardValue]);
setCount(returnValue.count);
}
setPage(newPage);
};

useEffect(() => {
if (paginationModel.page !== 0) {
handleChangePage(paginationModel.page);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [paginationModel.page]);

const handleCheckYourRank = async () => {
const eventName = getLeaderboardRankAnalyticsEventName(selectedGame);
if (eventName) {
Expand Down Expand Up @@ -204,11 +216,10 @@ export default function EnhancedTable({
</Typography>
)}
<ResponsiveTable
page={page}
rowsPerPage={10}
paginationModel={paginationModel}
onPaginationModelChange={setPaginationModel}
columns={getColumns()}
showPagination={true}
onChangePage={handleChangePage}
data={rows}
count={count}
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/components/leaderboards/TopModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Box } from '@mui/system';
import { styled } from '@nl/theme';
import { fetchScores } from '@/utils/leaderboard';
import type { DataType, ReturnDataType } from '@/types/leaderboard';
import { LEADERBOARD_GAME_LIST } from '@/constants/leaderboard';
import { LEADERBOARD_GAME_LIST } from '@/constants/leaderboards';
import CustomModal from './CustomModal';
import './modal-table.css';

Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/components/leaderboards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
LEADERBOARD_GAME_LIST,
LEADERBOARD_TIME_FILTERS,
NiftySmashersTables,
} from '@/constants/leaderboard';
} from '@/constants/leaderboards';
import EnhancedTable from '@/components/leaderboards/EnhancedTable/EnhancedTable';
// import { EmojiEvents, Paid, CrisisAlert } from '@mui/icons-material';
// const TopModal = dynamic(() => import('../TopModal'), { ssr: false });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { GOOGLE_ANALYTICS } from './google-analytics';
import { GOOGLE_ANALYTICS } from '../google-analytics';
import type { TableType, LeaderboardGame } from '@/types/leaderboard';
import { Game, TimeFilter } from '@/types/leaderboard';

import { SMASHERS_LEADERBOARDS } from './leaderboard-smashers';
import { WEN_GAME_LEADERBOARDS } from './leaderboard-wen-game';
import { CRYPTO_WINTER_LEADERBOARDS } from './leaderboard-crypto-winter';
import { MT_GAWX_LEADERBOARDS } from './leaderboard-mt-gawx';

export const NiftySmashersTables: TableType[] = [
{
key: 'win_rate',
Expand Down Expand Up @@ -126,3 +131,12 @@ export const getLeaderboardRankAnalyticsEventName = (selectedGame: string) => {
}
return eventName;
};

// Leaderboard Data

export const LEADERBOARDS = {
crypto_winter: CRYPTO_WINTER_LEADERBOARDS,
nftl_burner: MT_GAWX_LEADERBOARDS,
nifty_smashers: SMASHERS_LEADERBOARDS,
wen_game: WEN_GAME_LEADERBOARDS,
};
Loading

0 comments on commit dea61f0

Please sign in to comment.