Skip to content

Commit

Permalink
feat(ranking)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonassimoen committed Dec 3, 2023
1 parent 480570f commit 775d8ab
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 17 deletions.
20 changes: 17 additions & 3 deletions src/components/PlayerList/PlayerListStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,30 @@ export const tablePagination = `
`;

export const TableStyle = styled(Table)`
.ant-table-container table>thead>tr:first-child {
>*:first-child {
border-start-start-radius: 0px;
}
>*:last-child {
border-start-end-radius: 0px;
}
}
.ant-table {
color: #000;
}
.ant-table-thead {
th {
>tr>th {
padding-top: 10px;
padding-bottom: 10px;
background: ${props => props.theme.primaryContrast};
color: ${props => props.theme.primaryColor};
background: ${theme.primaryContrast};
color: ${theme.primaryColor};
padding: 5px;
&::before {
display: none;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/components/PlayerStatsList/PlayerStatsListStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ export const TableStyle = styled(Table)`
>tr>th {
background-color: ${theme.primaryContrast};
color: ${theme.primaryColor};
padding-top: 10px;
padding-bottom: 10px;
border-radius: 0px !important;
padding: 7.5px;
white-space: nowrap;
Expand Down
12 changes: 10 additions & 2 deletions src/locales/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@
"valueColumn": "Waarde"
},
"goalsColumnForAllPlayersTable": "Doelpunten",
"assistsColumnForAllPlayersTable": "Assists"
"assistsColumnForAllPlayersTable": "Assists",
"shotsAccuracyColumnForAllPlayersTable": "Shoten accuraatheid",
"passAccuracyColumnForAllPlayersTable": "Pass accuraatheid"
},
"team": {
"saveTeam": "Team opslaan",
Expand Down Expand Up @@ -193,5 +195,11 @@
"statsBlockTitle": "Statistieken",
"overviewBlockTitle": "Overzicht"
},
"pageTitle": "Pagina"
"pageTitle": "Pagina",
"rankingsPage": {
"rankingsTableTeamColumnName": "Team",
"rankingsTablePointsColumnName": "Punten",
"rankingsTitle": "Rangschikking",
"rankingsNotAvailableYet": "Ranking niet beschikbaar"
}
}
73 changes: 73 additions & 0 deletions src/pages/Rankings/Rankings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ContainerStyle, TableStyle } from "@/components/PlayerList/PlayerListStyle";
import { Row } from "@/components/UI/Grid/Grid";
import { useGetTeamRankingsQuery } from "@/services/teamsApi";
import { Col } from "antd";
import Title from "antd/lib/typography/Title";
import React from "react";
import { useTranslation } from "react-i18next";

type RankingsProps = {
q?: null
}

export const Rankings = (props: RankingsProps) => {
const [t] = useTranslation();
const { data, isLoading } = useGetTeamRankingsQuery();

const columns = [
{
title: "#",
key: "rank",
dataIndex: "team",
width: "10%",
render: (team: Team) => {
return <b>{team.rank ? team.rank : "-"}</b>;
}
},
{
title: t("rankingsPage.rankingsTableTeamColumnName"),
key: "team",
dataIndex: "team",
width: "60%",
render: (team: Team, record: any) =>
<React.Fragment>
<b>{team.name}</b>
<span style={{ display: "block", fontSize: "11px" }}>
{`${record.user.firstName} ${record.user.lastName}`}
</span>
</React.Fragment>
},
{
title: t("rankingsPage.rankingsTablePointsColumnName"),
key: "points",
dataIndex: "team",
width: "20%",
align: "right",
render: (team: Team) =>
<span>{team.points || 0}</span>
}
];

return (
<React.Fragment>
<Row style={{ paddingBottom: "20px" }}>
<Col md={24} sm={24} xs={24}>
<Title level={2}>{t("rankingsPage.rankingsTitle")}</Title>
</Col>
<Col md={24} sm={24} xs={24} style={{ marginTop: "10px" }}>
<ContainerStyle>
<TableStyle
columns={columns}
dataSource={data}
showHeader={true}
loading={isLoading}
locale={{ emptyText: t("rankingsPage.rankingsNotAvailableYet") }}
rowKey={(rec: any, idx: number) => `record-${idx + 1}`}
rowClassName={(rec: any, idx: number) => idx % 2 ? "ant-table-row--odd" : "ant-table-row--even"}
/>
</ContainerStyle>
</Col>
</Row>
</React.Fragment>
);
};
19 changes: 10 additions & 9 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { PointsPage } from "./pages/Points/Points";
import { MatchContainer } from "./pages/Match/Match";
import { Welcome } from "./pages/Welcome/Welcome";
import { PageManagement } from "./pages/PageManagement/PageManagement";
import { Rankings } from "./pages/Rankings/Rankings";

const Layout = ({ children }: any) => {
return (
Expand Down Expand Up @@ -51,7 +52,7 @@ export const router = createBrowserRouter([
element: <ProtectedRoute access={true} redirectPath="/home"><NewTeam /></ProtectedRoute>
},
{
path: "/points/:id", //todo
path: "/points/:id",
element: <ProtectedRoute access={true} redirectPath="/home"><PointsPage /></ProtectedRoute>
},
{
Expand All @@ -63,12 +64,12 @@ export const router = createBrowserRouter([
element: <ProtectedRoute access={true} redirectPath="/home"><TeamPage /></ProtectedRoute>
},
{
path: "/transfers/:id", //todo
path: "/transfers/:id",
element: <ProtectedRoute access={true} redirectPath="/home"><TransfersPage /></ProtectedRoute>
},
{
path: "/edit/:id", //todo
element: <ProtectedRoute access={true} redirectPath="/home"><Home /></ProtectedRoute>
path: "/edit/:id",
element: <ProtectedRoute access={true} redirectPath="/home"><TransfersPage /></ProtectedRoute>
},
{
path: "/profile",
Expand All @@ -79,19 +80,19 @@ export const router = createBrowserRouter([
element: <ProtectedRoute access={true} redirectPath="/home"><Deadlines /></ProtectedRoute>
},
{
path: "/stats", //todo
path: "/stats",
element: <ProtectedRoute access={true} redirectPath="/home"><Stats /></ProtectedRoute>
},
{
path: "/match/:id", //todo
path: "/match/:id",
element: <ProtectedRoute access={true} redirectPath="/home"><MatchContainer /></ProtectedRoute>
},
{
path: "/rankings", //todo
element: <ProtectedRoute access={true} redirectPath="/home"><Home /></ProtectedRoute>
path: "/rankings",
element: <ProtectedRoute access={true} redirectPath="/home"><Rankings /></ProtectedRoute>
},
{
path: "/rules", //todo
path: "/rules",
element: <ProtectedRoute access={true} redirectPath="/home"><Rules /></ProtectedRoute>
},
{
Expand Down
14 changes: 13 additions & 1 deletion src/services/teamsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export const teamsApi = createApi({
providesTags: ["userTeamPoints"],
}),

getTeamRankings: builder.query<{team: Team, user: User}, void>({
query: () => "/rankings"
})

// updatePlayer: builder.mutation<Player, Partial<Player> & Pick<Player, 'id'>>({
// query: ({ id, ...put }) => ({
// url: `${id}`,
Expand All @@ -57,4 +61,12 @@ export const teamsApi = createApi({
})
});

export const { useGetTeamQuery, useLazyGetTeamQuery, useAddTeamMutation, useUpdateTeamSelectionMutation, useLazyGetPointsQuery, useSubmitTransfersMutation } = teamsApi;
export const {
useGetTeamQuery,
useLazyGetTeamQuery,
useAddTeamMutation,
useUpdateTeamSelectionMutation,
useLazyGetPointsQuery,
useSubmitTransfersMutation,
useGetTeamRankingsQuery
} = teamsApi;
2 changes: 2 additions & 0 deletions src/types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ type Team = {
bank: number
tripleCaptain: number
wildCard: number
rank: number
points: number
}

type Boosters = {
Expand Down

0 comments on commit 775d8ab

Please sign in to comment.