import { ReactNode, Children, useState, useEffect, useContext } from 'react';
import Icon from '@mdi/react';
import axios from 'axios';
import { NavBar } from '../components/navbar';
import { CenteredPage, PageTitle } from '../components/page';
import { Vierkant, IconLabelButton } from '../components/ui';
import { AccountAvatar } from '../components/account';
import { userInfo, userGames } from '../api/api';
import RecentGames from '../components/recentGames';
import { ToastContext } from '../components/toast';
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 EditOutlinedIcon from '@material-ui/icons/EditOutlined';
import SettingsOutlinedIcon from '@material-ui/icons/SettingsOutlined';
import DoneOutlinedIcon from '@material-ui/icons/DoneOutlined';
import {
mdiAccountCancelOutline,
mdiEqual,
mdiCheckboxBlankCircle,
mdiClipboardTextOutline,
mdiGamepadSquareOutline,
mdiEarth,
mdiAccountMinusOutline } 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() {
var [gotData, setGotData] = useState(false);
var [user, setUser] = useState();
var [ownPage, setOwnPage] = useState(false);
var [gameInfo, setGameInfo] = useState();
var [loggedIn, setLoggedIn] = useState(false);
var [editingStatus, setEditingStatus] = useState(false);
var [isFriends, setIsFriends] = useState(false);
var [hasBlocked, setHasBlocked] = useState(false);
var { toast } = useContext(ToastContext);
useEffect(() => {(async() => {
if (gotData) return;
if (typeof window === "undefined") return;
var id = new URLSearchParams(window.location.search).get("id");
var loggedIn = document.cookie.includes("token");
setLoggedIn(loggedIn);
if (id || loggedIn) {
var self_id = "";
if (loggedIn && !self_id) {
var selfReq = await axios.request({
method: "get",
url: `/api/user/info`,
headers: {"content-type": "application/json"}
});
self_id = selfReq?.data.id;
}
if (id == self_id || !id) setOwnPage(true);
if (!user) {
var userReq = await axios.request({
method: "post",
url: `/api/user/info`,
headers: {"content-type": "application/json"},
data: { "id": id || self_id }
});
setUser(userReq.data);
}
if (!gameInfo) {
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);
}
setGotData(true);
})()});
return
Profiel
{user?.username}
{user?.status}
{ loggedIn &&
{
ownPage ?
} href="/settings" text="Instellingen"/>
{
!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 }
});
}}/>
}
:
{ hasBlocked ?
} text="Deblokkeren" onclick={() => {
/* axios.request({ */
/* method: "post", */
/* url: `/api/social/block`, */
/* headers: {"content-type": "application/json"}, */
/* data: { "id": user?.id } */
/* }) */
/* .then(() => { */
/* toast(`${user.username} geblokkeerd`, */
/* "confirmation", */
/* ); */
/* setHasBlocked(true); */
/* }); */
}}/> :
} text="Blokkeren" onclick={() => {
axios.request({
method: "post",
url: `/api/social/block`,
headers: {"content-type": "application/json"},
data: { "id": user?.id }
})
.then(() => {
toast(`${user.username} geblokkeerd`,
"confirmation",
);
setHasBlocked(true);
setIsFriends(false);
});
}}/>
}
{ isFriends ?
} text="Vriend verwijderen" onclick={() => {
/* axios.request({ */
/* method: "post", */
/* url: `/api/social/request`, */
/* headers: {"content-type": "application/json"}, */
/* data: { "id": user?.id } */
/* }) */
/* .then(() => { */
/* toast("Vriendschapsverzoek gestuurd", */
/* "confirmation", */
/* ); */
/* setIsFriends(true); */
/* }); */
}}/> :
} text="Vriendschapsverzoek" onclick={() => {
axios.request({
method: "post",
url: `/api/social/request`,
headers: {"content-type": "application/json"},
data: { "id": user?.id }
})
.then(() => {
toast("Vriendschapsverzoek gestuurd",
"confirmation",
);
setIsFriends(true);
setHasBlocked(false);
});
}}/>
}
}
}
} label="Online"/>
} label={ (() => {
var memberSince = "Lid sinds";
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;
return memberSince;
})() }/>
} label="2 vrienden"/>
} label="Nederland"/>
} label={ gameInfo?.totals.win + " keer gewonnen" }/>
} label={ gameInfo?.totals.draw + " keer gelijkspel" }/>
} label={ gameInfo?.totals.lose + " keer verloren" }/>
} label="Score: 400"/>
} label={ gameInfo?.totals.games + " potjes" }/>
}