From 57b098efd90b72c854582de9d7dafdc40506d5a9 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 9 Mar 2021 18:28:04 +0100 Subject: user page :tada: --- api/user/info.py | 8 +-- components/navbar.tsx | 5 +- pages/account.tsx | 112 ---------------------------------------- pages/search.tsx | 2 +- pages/user.tsx | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 147 insertions(+), 120 deletions(-) delete mode 100644 pages/account.tsx create mode 100644 pages/user.tsx diff --git a/api/user/info.py b/api/user/info.py index 3d4f4fb..954a989 100644 --- a/api/user/info.py +++ b/api/user/info.py @@ -30,12 +30,12 @@ def index(): not token: return "", 400 - if token: + if token and not (username or user_id): user_id = token_login(token) - elif username: + + if username and not user_id: temp_user_id = cursor.execute("select user_id from users where username = ?", [username]).fetchone() - if temp_user_id: - user_id = temp_user_id[0] + if len(temp_user_id) > 0: user_id = temp_user_id user = format_user(user_id) diff --git a/components/navbar.tsx b/components/navbar.tsx index 56d6b4b..ab348a1 100644 --- a/components/navbar.tsx +++ b/components/navbar.tsx @@ -1,5 +1,4 @@ import { CSSProperties, useEffect, useState } from "react"; -/* import axios from "axios"; */ import { LogoDark } from "../components/logo"; @@ -9,7 +8,7 @@ import ExtensionIcon from '@material-ui/icons/Extension'; import SearchIcon from '@material-ui/icons/Search'; import SettingsIcon from '@material-ui/icons/Settings'; import PersonIcon from '@material-ui/icons/Person'; -import {AccountAvatar} from "./account"; +import { AccountAvatar } from "./account"; var NavBarItemStyle: CSSProperties = { margin: 12, @@ -49,7 +48,7 @@ export function NavBar() { left: 0, backgroundColor: "var(--background)" }}> - + { loggedIn ? : diff --git a/pages/account.tsx b/pages/account.tsx deleted file mode 100644 index 82e21fa..0000000 --- a/pages/account.tsx +++ /dev/null @@ -1,112 +0,0 @@ -import { ReactNode, Children } from 'react'; -import Icon from '@mdi/react'; - -import { NavBar } from '../components/navbar'; -import { CenteredPage, PageTitle } from '../components/page'; -import { Vierkant, IconLabelButton } from '../components/ui'; -import { AccountAvatar } from '../components/account'; -import RecentGames from '../components/recentGames'; - -import PersonAddOutlinedIcon from '@material-ui/icons/PersonAddOutlined'; -import AssignmentIndOutlinedIcon from '@material-ui/icons/AssignmentIndOutlined'; -import ArrowDownwardOutlinedIcon from '@material-ui/icons/ArrowDownwardOutlined'; -import ArrowUpwardOutlinedIcon from '@material-ui/icons/ArrowUpwardOutlined'; -import PeopleOutlineOutlinedIcon from '@material-ui/icons/PeopleOutlineOutlined'; -import { - mdiAccountCancelOutline, - mdiEqual, - mdiCheckboxBlankCircle, - mdiClipboardTextOutline, - mdiGamepadSquareOutline, - mdiEarth } from '@mdi/js'; - -function InfoModule(props: { - label: string; - icon: ReactNode; -}) { - return
-
{props.icon}
-
- {props.label} -
-
-} - -function InfoSection(props: { children: ReactNode }) { - return -
- {props.children} -
-
-} - -export default function AccountPage() { - return
- - - Profiel - - -
-

Gebruikersnaam

-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et -

-
-
- } text="Vriendschapsverzoek"/> - } text="Blokkeren"/> -
-
- - } label="Online"/> - } label="Lid sinds 14 december 2020"/> - } label="2 vrienden"/> - } label="Nederland"/> - - - } label="4 keer gewonnen"/> - } label="2 keer gelijkspel"/> - } label="2 keer verloren"/> - } label="Score: 400"/> - } label="6 potjes"/> - - - - -
-
-} - diff --git a/pages/search.tsx b/pages/search.tsx index 52dfed5..963fcba 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -32,7 +32,7 @@ function SearchResults(props: { userList: Array }) { function SearchResult(props: { user: userInfo }) { return + }} fullwidth href={`/user?id=${props.user.id}`}>
+
{props.icon}
+
+ {props.label} +
+
+} + +function InfoSection(props: { children: ReactNode }) { + return +
+ {props.children} +
+
+} + +export default function AccountPage() { + var [gotData, setGotData] = useState(false); + var [user, setUser] = useState(); + + typeof window !== "undefined" && console.log(new URLSearchParams(window.location.search).get("id")) + useEffect(() => { + if (gotData) return; + if (typeof window === "undefined") return; + + var id = new URLSearchParams(window.location.search).get("id"); + var loggedIn = document.cookie.includes("token"); + + if (id || loggedIn) { + axios.request({ + method: id ? "post" : "get", + url: `/api/user/info`, + headers: {"content-type": "application/json"}, + data: id ? { id } : undefined + }) + .then(request => setUser(request.data)) + .catch(() => {}); + } else { + window.history.go(-1); + } + + setGotData(true); + }) + + return
+ + + Profiel + + +
+

{user?.username}

+

{user?.status}

+
+
+ } text="Vriendschapsverzoek"/> + } text="Blokkeren"/> +
+
+ + } label="Online"/> + } label="Lid sinds 14 december 2020"/> + } label="2 vrienden"/> + } label="Nederland"/> + + + } label="4 keer gewonnen"/> + } label="2 keer gelijkspel"/> + } label="2 keer verloren"/> + } label="Score: 400"/> + } label="6 potjes"/> + + + + +
+
+} + -- cgit v1.2.3