From 29436b8bdcba28d0c6362a2c6a68268411be7293 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 19 Apr 2021 14:36:28 +0200 Subject: user page without inline css :tada: --- pages/_app.tsx | 1 + pages/user.tsx | 456 ++++++++++++++++++++++++++------------------------------- 2 files changed, 206 insertions(+), 251 deletions(-) (limited to 'pages') diff --git a/pages/_app.tsx b/pages/_app.tsx index 7cdb8e3..db62fa8 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -16,6 +16,7 @@ import '../styles/index.css'; import '../styles/loginregister.css'; import '../styles/search.css'; import '../styles/settings.css'; +import '../styles/user.css'; export default function VierOpEenRijWebsite({ Component, pageProps }) { return
diff --git a/pages/user.tsx b/pages/user.tsx index 4f7331c..e1c3674 100644 --- a/pages/user.tsx +++ b/pages/user.tsx @@ -1,6 +1,6 @@ import Icon from '@mdi/react'; import axios from 'axios'; -import { Children, ReactNode, useContext, useEffect, useState } from 'react'; +import { ReactNode, useContext, useEffect, useState } from 'react'; import { userGames, userInfo } from '../api/api'; import { AccountAvatar } from '../components/account'; @@ -35,60 +35,18 @@ function InfoModule(props: { label: string; icon: ReactNode; }) { - return
-
+ return
+
{props.icon}
-
- +
+ {props.label}
; } -function InfoSection(props: { children: ReactNode; }) { - return -
- {props.children} -
-
; -} - export default function AccountPage() { var server = typeof window === 'undefined'; var loggedIn = !server && document.cookie.includes('token'); @@ -167,226 +125,222 @@ export default function AccountPage() { Profiel - - -
-

{user?.username}

-

- {user?.status} -

-
-
- {loggedIn &&
- {ownPage - ?
- } href='/settings' text='Instellingen' /> - {!editingStatus - ? } - text='Status bewerken' - onclick={() => setEditingStatus(true)} + +
+ +
+

{user?.username}

+

+ {user?.status} +

+
+
+ {loggedIn &&
+ {ownPage + ?
+ } + href='/settings' + text='Instellingen' /> - : } - text='Status opslaan' - onclick={() => { - setEditingStatus(false); - axios.request({ - method: 'post', - url: `/api/user/status`, - headers: { 'content-type': 'application/json' }, - data: { 'status': document.getElementById('status').innerText }, - }); - }} - />} -
- :
- {(() => { - var icon = { - 'blocked': , - }[relation] || ; + {!editingStatus + ? } + text='Status bewerken' + onclick={() => setEditingStatus(true)} + /> + : } + text='Status opslaan' + onclick={() => { + setEditingStatus(false); + axios.request({ + method: 'post', + url: `/api/user/status`, + headers: { 'content-type': 'application/json' }, + data: { 'status': document.getElementById('status').innerText }, + }); + }} + />} +
+ :
+ {(() => { + var icon = { + 'blocked': , + }[relation] || ; - var text = { - 'blocked': 'Deblokkeren', - }[relation] || 'Blokkeren'; + var text = { + 'blocked': 'Deblokkeren', + }[relation] || 'Blokkeren'; - return { - var nextRelation = { - 'blocked': { - 'endpoint': '/api/social/unblock', - 'action': `${user.username} gedeblokkeerd`, - 'relation': 'none', + return { + var nextRelation = { + 'blocked': { + 'endpoint': '/api/social/unblock', + 'action': `${user.username} gedeblokkeerd`, + 'relation': 'none', + 'icon': , + }, + }[relation] || { + 'endpoint': '/api/social/block', + 'action': `${user.username} geblokkeerd`, + 'relation': 'blocked', 'icon': , - }, - }[relation] || { - 'endpoint': '/api/social/block', - 'action': `${user.username} geblokkeerd`, - 'relation': 'blocked', - 'icon': , - }; + }; - axios.request({ - method: 'post', - url: nextRelation.endpoint, - headers: { 'content-type': 'application/json' }, - data: { 'id': user?.id }, - }) - .then(() => { - toast({ - message: nextRelation.action, - type: 'confirmation', - icon: nextRelation.icon, + axios.request({ + method: 'post', + url: nextRelation.endpoint, + headers: { 'content-type': 'application/json' }, + data: { 'id': user?.id }, + }) + .then(() => { + toast({ + message: nextRelation.action, + type: 'confirmation', + icon: nextRelation.icon, + }); + setRelation(nextRelation.relation); }); - setRelation(nextRelation.relation); - }); - }} - />; - })()} - {(() => { - var icon = { - 'friends': , - 'outgoing': , - 'incoming': , - }[relation] || ; + }} + />; + })()} + {(() => { + var icon = { + 'friends': , + 'outgoing': , + 'incoming': , + }[relation] || ; - var text = { - 'friends': 'Vriend verwijderen', - 'outgoing': 'Vriendschapsverzoek annuleren', - 'incoming': 'Vriendschapsverzoek accepteren', - }[relation] || 'Vriendschapsverzoek sturen'; + var text = { + 'friends': 'Vriend verwijderen', + 'outgoing': 'Vriendschapsverzoek annuleren', + 'incoming': 'Vriendschapsverzoek accepteren', + }[relation] || 'Vriendschapsverzoek sturen'; - return { - var nextRelation = { - 'friends': { - 'endpoint': '/api/social/remove', - 'action': `${user.username} succesvol verwijderd als vriend`, - 'relation': 'none', - 'icon': , - }, - 'outgoing': { - 'endpoint': '/api/social/remove', - 'action': `Vriendschapsverzoek naar ${user.username} geannuleerd`, - 'relation': 'none', - 'icon': , - }, - 'incoming': { - 'endpoint': '/api/social/accept', - 'action': `Vriendschapsverzoek van ${user.username} geaccepteerd`, - 'relation': 'friends', + return { + var nextRelation = { + 'friends': { + 'endpoint': '/api/social/remove', + 'action': `${user.username} succesvol verwijderd als vriend`, + 'relation': 'none', + 'icon': , + }, + 'outgoing': { + 'endpoint': '/api/social/remove', + 'action': + `Vriendschapsverzoek naar ${user.username} geannuleerd`, + 'relation': 'none', + 'icon': , + }, + 'incoming': { + 'endpoint': '/api/social/accept', + 'action': + `Vriendschapsverzoek van ${user.username} geaccepteerd`, + 'relation': 'friends', + 'icon': , + }, + }[relation] || { + 'endpoint': '/api/social/request', + 'action': `Vriendschapsverzoek gestuurd naar ${user.username}`, + 'relation': 'outgoing', 'icon': , - }, - }[relation] || { - 'endpoint': '/api/social/request', - 'action': `Vriendschapsverzoek gestuurd naar ${user.username}`, - 'relation': 'outgoing', - 'icon': , - }; + }; - axios.request({ - method: 'post', - url: nextRelation.endpoint, - headers: { 'content-type': 'application/json' }, - data: { 'id': user?.id }, - }) - .then(() => { - toast({ - message: nextRelation.action, - type: 'confirmation', - icon: nextRelation.icon, + axios.request({ + method: 'post', + url: nextRelation.endpoint, + headers: { 'content-type': 'application/json' }, + data: { 'id': user?.id }, + }) + .then(() => { + toast({ + message: nextRelation.action, + type: 'confirmation', + icon: nextRelation.icon, + }); + setRelation(nextRelation.relation); }); - setRelation(nextRelation.relation); - }); - }} - />; - })()} -
} -
} + }} + />; + })()} +
} +
} +
- - } - label='Online' - /> - } - label={(() => { - var memberSince = 'Lid sinds'; + +
+ } + label='Online' + /> + } + label={(() => { + var memberSince = 'Lid sinds'; - var registered = new Date(user?.registered); - memberSince += ' ' + registered.toLocaleString('nl-nl', { month: 'long', day: 'numeric' }); + var registered = new Date(user?.registered); + memberSince += ' ' + registered.toLocaleString('nl-nl', { month: 'long', day: 'numeric' }); - var currentYear = new Date().getFullYear(); - var memberYear = registered.getFullYear(); - if (currentYear != memberYear) memberSince += ' ' + memberYear; + var currentYear = new Date().getFullYear(); + var memberYear = registered.getFullYear(); + if (currentYear != memberYear) memberSince += ' ' + memberYear; - return memberSince; - })()} - /> - } - label={(() => { - var label = user?.friends.toString() + ' '; - label += user?.friends == 1 ? 'vriend' : 'vrienden'; - return label; - })()} - /> - } label='Nederland' /> - - - } - label={gameInfo?.totals.win + ' keer gewonnen'} - /> - } - label={gameInfo?.totals.draw + ' keer gelijkspel'} - /> - } - label={gameInfo?.totals.lose + ' keer verloren'} - /> - } label={'Score: ' + user?.rating} /> - } - label={(() => { - var label = gameInfo?.totals.games.toString() + ' '; - label += gameInfo?.totals.games == 1 ? 'potje' : 'potjes'; - return label; - })()} - /> - - + return memberSince; + })()} + /> + } + label={(() => { + var label = user?.friends.toString() + ' '; + label += user?.friends == 1 ? 'vriend' : 'vrienden'; + return label; + })()} + /> + } label='Nederland' /> +
+
+ +
+ } + label={gameInfo?.totals.win + ' keer gewonnen'} + /> + } + label={gameInfo?.totals.draw + ' keer gelijkspel'} + /> + } + label={gameInfo?.totals.lose + ' keer verloren'} + /> + } + label={'Score: ' + user?.rating} + /> + } + label={(() => { + var label = gameInfo?.totals.games.toString() + ' '; + label += gameInfo?.totals.games == 1 ? 'potje' : 'potjes'; + return label; + })()} + /> +
+
+ -- cgit v1.2.3