From 1b8e3e479fb1fcea333571aaa3dd090ec78e346b Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 10 Mar 2021 14:37:12 +0100 Subject: /user page use /user/games api --- pages/user.tsx | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'pages') diff --git a/pages/user.tsx b/pages/user.tsx index 42cfb17..a8cc9c5 100644 --- a/pages/user.tsx +++ b/pages/user.tsx @@ -1,13 +1,12 @@ import { ReactNode, Children, useState, useEffect } from 'react'; import Icon from '@mdi/react'; import axios from 'axios'; -import useSWR from 'swr'; import { NavBar } from '../components/navbar'; import { CenteredPage, PageTitle } from '../components/page'; import { Vierkant, IconLabelButton } from '../components/ui'; import { AccountAvatar } from '../components/account'; -import { userInfo } from '../api/api'; +import { userInfo, userGames } from '../api/api'; import RecentGames from '../components/recentGames'; import PersonAddOutlinedIcon from '@material-ui/icons/PersonAddOutlined'; @@ -71,6 +70,7 @@ export default function AccountPage() { var [gotData, setGotData] = useState(false); var [user, setUser] = useState(); var [ownPage, setOwnPage] = useState(false); + var [gameInfo, setGameInfo] = useState(); useEffect(() => {(async() => { if (gotData) return; @@ -101,6 +101,15 @@ export default function AccountPage() { }); setUser(userReq.data); + + var userGamesReq = await axios.request({ + method: "post", + url: `/api/user/games`, + headers: {"content-type": "application/json"}, + data: { "id": id || self_id } + }); + + setGameInfo(userGamesReq.data); } else { window.history.go(-1); } @@ -160,11 +169,11 @@ export default function AccountPage() { } label="Nederland"/> - } label="4 keer gewonnen"/> - } label="2 keer gelijkspel"/> - } label="2 keer verloren"/> + } label={ gameInfo?.totals.win + " keer gewonnen" }/> + } label={ gameInfo?.totals.draw + " keer gelijkspel" }/> + } label={ gameInfo?.totals.lose + " keer verloren" }/> } label="Score: 400"/> - } label="6 potjes"/> + } label={ gameInfo?.totals.games + " potjes" }/> -- cgit v1.2.3