Skip to content

Commit

Permalink
fix pool page issue
Browse files Browse the repository at this point in the history
  • Loading branch information
LucSPI committed May 22, 2023
1 parent 535084c commit d2e2204
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
19 changes: 15 additions & 4 deletions src/components/Pools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { Pagination } from '../UI/Table/TableSearchMode/Pagination';
import { Image } from '../UI';
import Clock from '~/assets/img/time.png';
import { Bullet, Blitz, Rapid, Standard } from '../UI/SVG_ICONS';
import { useAuth } from '~/providers/AuthProvider';
import { useNavigate } from 'react-router-dom';
import { appStore } from '~/store';
import { useEffect } from 'react';
type Category = 'Bullet' | 'Blitz' | 'Rapid';

interface Pool {
Expand Down Expand Up @@ -47,14 +50,22 @@ const columns: ColumnDefinitionType<Pool, keyof Pool>[] = [

const Pools: React.FC = () => {
const lobby = appStore.lobby.useTrackedStore();
const totalCount = appStore.lobby.use.totalCount();
const navigate = useNavigate();
const { isAuthenticated } = useAuth();
useEffect(() => {
if(!isAuthenticated()){
navigate('/');
}
}, [])
return (
<div className="my-auto mx-12 grid grid-cols-12">
<div className="flex flex-col justify-center border-[1px] py-6 h-fit col-span-8 border-[#B4C7D8] shadow-3xl rounded-xl">
<div className="flex justify-between mx-6 mb-6">
<div className="space-x-2">
<span className="text-lg font-medium">Active Pools</span>
<span className="bg-[#F9F5FF] rounded-xl px-2 py-1 text-xs text-purple-100 ">
125 Pools
{totalCount} Pools
</span>
</div>
<div>
Expand All @@ -80,15 +91,15 @@ const Pools: React.FC = () => {
<Bullet fill="#FFFFFF" />
</div>
) : lobby.rowData?.category === 'blitz' ? (
<div>
<div className="rounded-full bg-[#0151FF] w-[40px] h-[40px] flex items-center justify-center">
<Blitz fill="#FFFFFF" />
</div>
) : lobby.rowData?.category === 'rapid' ? (
<div>
<div className="rounded-full bg-[#0151FF] w-[40px] h-[40px] flex items-center justify-center">
<Rapid fill="#FFFFFF" />
</div>
) : lobby.rowData?.category === 'standard' ? (
<div>
<div className="rounded-full bg-[#0151FF] w-[40px] h-[40px] flex items-center justify-center">
<Standard fill="#FFFFFF" />
</div>
) : (
Expand Down
9 changes: 4 additions & 5 deletions src/components/UI/Table/TableSearchMode/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ import { Button } from '../..';
import { AiOutlineArrowLeft, AiOutlineArrowRight } from 'react-icons/ai';
import { usePagination } from './usePagination';
import { trpc } from '~/helpers/trpc';
import { useEffect, useState } from 'react';
import { useEffect } from 'react';
import { appActions, appStore } from '~/store';

export const Pagination: React.FC = () => {
const [totalCount, setTotalCount] = useState(0);
const pageSize = 10;
const pageSize = 8;
const siblingCount = 1;
const currentPage = appStore.lobby.use.currentPage();
const getData = async (currentPage: number) => {
const data: any = await trpc.query('lobby.pools', { currentPage, pageSize });
appActions.lobby.tableData(data.pools);
setTotalCount(data.totalCount);
appActions.lobby.totalCount(data.totalCount);
};
useEffect(() => {
getData(currentPage);
}, []);

const paginationRange = usePagination({
currentPage,
totalCount,
totalCount: appStore.lobby.use.totalCount(),
siblingCount,
pageSize,
});
Expand Down
2 changes: 2 additions & 0 deletions src/store/lobby.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface StateProps {
ticket: Ticket | null;
tableData: any[];
currentPage: number;
totalCount: number;
rowData: {
category: string;
betAmount: number;
Expand All @@ -26,6 +27,7 @@ const initialStateProps: StateProps = {
category: 'bullet',
tableData: [],
currentPage: 1,
totalCount: 0,
rowData: {
category: '',
betAmount: 0,
Expand Down

0 comments on commit d2e2204

Please sign in to comment.