From decb742136440a43ad35ac20908c72b44108f3fa Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 12 Mar 2021 19:45:51 +0100 Subject: friend request buttons do the api things --- pages/user.tsx | 78 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 11 deletions(-) (limited to 'pages') diff --git a/pages/user.tsx b/pages/user.tsx index c7a78e6..2003696 100644 --- a/pages/user.tsx +++ b/pages/user.tsx @@ -24,7 +24,8 @@ import { mdiCheckboxBlankCircle, mdiClipboardTextOutline, mdiGamepadSquareOutline, - mdiEarth } from '@mdi/js'; + mdiEarth, + mdiAccountMinusOutline } from '@mdi/js'; function InfoModule(props: { label: string; @@ -77,6 +78,9 @@ export default function AccountPage() { var [editingStatus, setEditingStatus] = useState(false); + var [isFriends, setIsFriends] = useState(false); + var [hasBlocked, setHasBlocked] = useState(false); + var { toast } = useContext(ToastContext); useEffect(() => {(async() => { @@ -175,16 +179,68 @@ export default function AccountPage() { } :
- } text="Blokkeren" onclick={() => { - toast(`${user.username} geblokkeerd`, - "confirmation", - ) - }}/> - } text="Vriendschapsverzoek" onclick={() => { - toast("Vriendschapsverzoek gestuurd", - "confirmation", - ) - }}/> + { 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); + }); + }}/> + }
}} -- cgit v1.2.3