From 5d02095526c95676ad3f5a6d6763f247bf9e6951 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 13 Mar 2021 13:48:09 +0100 Subject: friend request delete :tada: --- pages/user.tsx | 69 +++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 22 deletions(-) (limited to 'pages') diff --git a/pages/user.tsx b/pages/user.tsx index a33f58b..8d4fb8d 100644 --- a/pages/user.tsx +++ b/pages/user.tsx @@ -25,7 +25,8 @@ import { mdiClipboardTextOutline, mdiGamepadSquareOutline, mdiEarth, - mdiAccountMinusOutline } from '@mdi/js'; + mdiAccountMinusOutline, + mdiAccountRemoveOutline } from '@mdi/js'; function InfoModule(props: { label: string; @@ -217,36 +218,60 @@ export default function AccountPage() { }); }}/> })()} - { relation == "friends" ? - } 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={() => { + {(() => { + var icon = { + "friends": , + "outgoing": , + "incoming": + }[relation] || + + 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", + "icon": , + }, + }[relation] || { + "endpoint": "/api/social/request", + "action": `Vriendschapsverzoek gestuurd naar ${user.username}`, + "relation": "outgoing", + "icon": , + } + axios.request({ method: "post", - url: `/api/social/request`, + url: nextRelation.endpoint, headers: {"content-type": "application/json"}, data: { "id": user?.id } }) .then(() => { - toast("Vriendschapsverzoek gestuurd", + toast(nextRelation.action, "confirmation", - ); - setRelation("outgoing"); + nextRelation.icon); + setRelation(nextRelation.relation); }); }}/> - } + })()} }} -- cgit v1.2.3