Skip to content

Commit

Permalink
pools page
Browse files Browse the repository at this point in the history
  • Loading branch information
LucSPI committed May 18, 2023
1 parent 4c6b9ce commit 054ef6d
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 65 deletions.
Binary file added src/assets/img/time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/components/Modal/Auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { LoginSocialGoogle, IResolveParams } from 'reactjs-social-login';
import { Button, Image, Input } from '~/components/UI/index.ts';
import { useAuth } from '~/providers/AuthProvider';
import { useAppState } from '~/providers/StateProvider/StateProvider';
import { FaGoogle, FaTwitter } from 'react-icons/fa';
import { FaTwitter } from 'react-icons/fa';
import { FcGoogle } from 'react-icons/fc'
import { yupResolver } from '@hookform/resolvers/yup';
import { useForm } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';
Expand Down Expand Up @@ -113,7 +114,7 @@ export const LoginModal: React.FC = () => {
>
<Button
text="Continue with Google"
icon={<FaGoogle fill="grey" />}
icon={<FcGoogle />}
height="h-12"
bg_color="bg-white-100"
border="border"
Expand Down
99 changes: 49 additions & 50 deletions src/components/Pools/index.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,21 @@
import { useEffect } from "react";
import { Table } from "../UI";
import { Button, Table } from "../UI";
import { ColumnDefinitionType } from "../UI";
import { SortButton } from "../UI/Table/TableSearchMode/SortButton";
import { Pagination } from "../UI/Table/TableSearchMode/Pagination";
import { useAppState } from "~/providers/StateProvider/StateProvider";
import { Image } from "../UI";
import Bullet from "~/assets/icons/3.svg"
import Clock from '~/assets/img/time.png'
type Category = 'Bullet' | 'Blitz' | 'Rapid';

interface Pool {
category: Category;
time: number;
betamount: number;
bet_amount: number;
participants: number ;
status: boolean;
queue: number
}
const data: Pool[] = [
{
category: 'Bullet' ,
time: 5,
betamount: 5,
participants: 1000,
status: true,
queue: 12
},
{
category: 'Blitz',
time: 2,
betamount: 10,
participants: 1000,
status: true,
queue: 12
},
{
category: 'Bullet',
time: 3,
betamount: 23,
participants: 1000,
status: true,
queue: 12
},
{
category: 'Rapid',
time: 4,
betamount: 4,
participants: 1000,
status: true,
queue: 12
},

];

const columns: ColumnDefinitionType<Pool, keyof Pool>[] = [
{
Expand All @@ -60,7 +28,7 @@ const columns: ColumnDefinitionType<Pool, keyof Pool>[] = [
header: 'Time',
},
{
key: 'betamount',
key: 'bet_amount',
header: 'Bet Amount'
},
{
Expand All @@ -78,25 +46,56 @@ const columns: ColumnDefinitionType<Pool, keyof Pool>[] = [
]

const Pools: React.FC = () => {
const { state: {tableData}, actions: {setTableData} } = useAppState();
useEffect(() => {
setTableData(data);
}, []);
const { state } = useAppState();

return (
<div className="flex flex-col justify-center my-auto">
<div>
<div className="flex justify-between mx-6">
<div className="my-auto mx-12 grid grid-cols-12">
<div className="flex flex-col justify-center border-[1px] py-6 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</span>
</div>
<div>
<SortButton columns={columns} data={data}/>
<SortButton columns={columns} data={state.tableData}/>
</div>
</div>
<div className="max-h-[600px] block overflow-y-auto">
<Table
columns={columns}
data = {state.tableData}
headClass="bg-[#F9FAFB]"
tableClass="table-fixed"
selectable
/>
</div>
<p className="bg-[#E4E7EC] h-[1px] w-full mb-4"></p>
<Pagination/>
</div>
<div className="col-span-1"></div>
<div className="col-span-2 flex flex-col justify-center items-center border-[1px] rounded-lg h-fit px-2 py-6 gap-2 w-[380px]">
<Image source={Bullet}/>
<p className="text-[#0151FF]">Bullet</p>
<div className="flex items-center gap-2">
<Image source={Clock}/>
<p className="font-bold">10 MIN</p>
</div>
<div className="border-[0.41844px] shadow-4xl rounded-3xl px-2 border-[#b4c7d880]">
<p className="text-[64px] font-bold text-[#0151FF]">${state.betAmount}</p>
</div>
<div className="flex justify-between items-center w-full px-1">
<div>
<span className="text-xs">Player queue:</span>
<span className="font-bold text-gray-300"> 100</span>
</div>
<div >
<span className="text-xs">Participants in pool:</span>
<span className="font-bold text-gray-300"> 2049</span>
</div>
</div>
<Table
columns={columns}
data = {tableData}
<Button
text="Confirm"
className="w-full bg-[#12B76A] text-white-100 "
/>
</div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion src/components/UI/Button.ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ButtonProps extends HTMLProps<HTMLButtonElement> {
px?: string;
py?: string;
icon?: React.ReactNode;
icon_direction? : string;
bg_color?: string;
text_color?: string;
className?: string;
Expand All @@ -13,6 +14,7 @@ export interface ButtonProps extends HTMLProps<HTMLButtonElement> {
width?: string;
height?: string;
onClick?: () => void;
disabled? : boolean;
}
export const Button: React.FC<ButtonProps> = ({
text,
Expand All @@ -26,15 +28,19 @@ export const Button: React.FC<ButtonProps> = ({
text_color = "text-black",
rounded = "rounded-md",
className = "",
icon_direction = 'left',
onClick,
disabled,
}: ButtonProps) => {
return (
<button
className={`${px} ${py} ${rounded} ${border} ${className} ${bg_color} ${text_color} ${width} ${height} text-center`}
onClick={onClick}
disabled = {disabled}
>
{icon && <div className="px-1">{icon}</div>}
{icon_direction === 'left' && icon && <div className="px-1">{icon}</div>}
{text}
{icon_direction === 'right' && icon && <div className="px-1">{icon}</div>}
</button>
);
};
2 changes: 1 addition & 1 deletion src/components/UI/Table/TableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const TableCell = <T, K extends keyof T>({ data, column }: TableCellProps
return(
<p>{data[column.key] as any} min</p>
)
case 'betamount':
case 'bet_amount':
return(
<p>$ {data[column.key] as any}</p>
)
Expand Down
5 changes: 3 additions & 2 deletions src/components/UI/Table/TableHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ColumnDefinitionType } from '.';
export type TableHeaderProps<T, K extends keyof T> = {
columns: Array<ColumnDefinitionType<T, K>>;
headClass?: string;
};

const TableHeader = <T, K extends keyof T>({ columns }: TableHeaderProps<T, K>): JSX.Element => {
const TableHeader = <T, K extends keyof T>({ columns, headClass }: TableHeaderProps<T, K>): JSX.Element => {
const headers = columns.map((column, index) => {
return (
<th key={`headCell-${index}`} className={`${index === 0 ? 'pl-4' : ''}`}>
Expand All @@ -13,7 +14,7 @@ const TableHeader = <T, K extends keyof T>({ columns }: TableHeaderProps<T, K>):
});

return (
<thead className="w-full">
<thead className={`w-full sticky ${headClass}`}>
<tr className="h-[44px] text-left text-xs font-medium">{headers}</tr>
</thead>
);
Expand Down
15 changes: 12 additions & 3 deletions src/components/UI/Table/TableRows.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { ColumnDefinitionType } from '.';
import { TableCell } from './TableCell';
import { useAppState } from '~/providers/StateProvider/StateProvider';
type TableRowsProps<T, K extends keyof T> = {
data: Array<T>;
columns: Array<ColumnDefinitionType<T, K>>;
bodyClass?: string;
selectable?: boolean;
};

const TableRows = <T, K extends keyof T>({ data, columns }: TableRowsProps<T, K>): JSX.Element => {
const TableRows = <T, K extends keyof T>({ data, columns, bodyClass, selectable }: TableRowsProps<T, K>): JSX.Element => {
const {actions} = useAppState();
const getRow = (row: any, selectable: boolean | undefined) => {
if(selectable){
actions.setBetAmount(row.bet_amount)
}
}
const rows = data.map((row, index) => {
return (
<tr key={`row-${index}`} className={`h-16 ${index % 2 === 0 ? 'bg-gray-100' : ''}`}>
<tr key={`row-${index}`} onClick={() => getRow(row, selectable)} className={`h-16 ${index % 2 === 0 ? 'bg-gray-100' : ''} ${selectable === true? "hover:bg-[#50A3FF]" : ""}`}>
{columns.map((column, index2) => {
return (
<td key={`cell-${index2}`} className={`${index2 === 0 ? 'pl-4' : ''}`}>
Expand All @@ -20,7 +29,7 @@ const TableRows = <T, K extends keyof T>({ data, columns }: TableRowsProps<T, K>
);
});

return <tbody className="w-full">{rows}</tbody>;
return <tbody className={`w-full ${bodyClass}`}>{rows}</tbody>;
};

export default TableRows;
83 changes: 83 additions & 0 deletions src/components/UI/Table/TableSearchMode/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// import { useMemo } from "react";
import { Button } from "../.."
import { AiOutlineArrowLeft, AiOutlineArrowRight } from 'react-icons/ai';
import { useAppState } from "~/providers/StateProvider/StateProvider";
import { usePagination } from "./usePagination";
import { trpc } from "~/helpers/trpc";
import { useState } from "react";
// type Lobby = {
// pools: Array<any>,
// totalCount: number,
// }
export const Pagination: React.FC = () => {
const [totalCount, setTotalCount] = useState(0)
const pageSize = 10;
const siblingCount = 1;
const {
state: {currentPage},
actions: {setCurrentPage, setTableData}
} = useAppState();
const getData = async (currentPage: number) => {
const data: any = await trpc.query("lobby.pools", {currentPage, pageSize})
setTableData(data.pools);
setTotalCount(data.totalCount);
}
getData(currentPage)

const paginationRange = usePagination({
currentPage,
totalCount,
siblingCount,
pageSize
});
const pageActivite = (index: number) => {
setCurrentPage(index);
getData(index);
}
const onNext = () => {
pageActivite(currentPage + 1);
};

const onPrevious = () => {
pageActivite(currentPage - 1);
};
const lastPage = paginationRange && paginationRange[paginationRange.length - 1]
return (
<div className="flex justify-between mx-6">
<Button
icon={<AiOutlineArrowLeft />}
text="Previous"
className={`flex justify-between items-center border-2 w-[114px] h-[36px] ${currentPage === 1 ? 'disabled:opacity-75' : ''}`}
disabled = {currentPage=== 1? true : false}
onClick={onPrevious}
/>
<div className="flex gap-1">
{
paginationRange?.map((pageNumber, index) => {
if (pageNumber === 'DOTS') {
return <div key={index}>&#8230;</div>;
}
return (
<button
key={index}
onClick={() => pageActivite(pageNumber as number)}
className={`${currentPage === pageNumber ? 'border-2 bg-[#D2EEFF]' : ''} flex justify-center items-center rounded-md w-[36px] h-[36px]`}
>
{pageNumber}
</button>
);
})
}

</div>
<Button
icon={<AiOutlineArrowRight />}
icon_direction="right"
text="Next"
className="flex justify-between items-center border-2 w-[88px] h-[36px]"
disabled = {currentPage=== lastPage? true : false}
onClick={onNext}
/>
</div>
)
}
Loading

0 comments on commit 054ef6d

Please sign in to comment.