From d91b95b89bc61228f623effd82810e29d27b1c0c Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 13 Mar 2021 12:37:59 +0100 Subject: blocked button working fabulously --- pages/user.tsx | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'pages') diff --git a/pages/user.tsx b/pages/user.tsx index e5b2083..a33f58b 100644 --- a/pages/user.tsx +++ b/pages/user.tsx @@ -179,36 +179,44 @@ export default function AccountPage() { } :
- { relation == "blocked" ? - } 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={() => { + {(() => { + var icon = { + "blocked": + }[relation] || + + var text = { + "blocked": "Deblokkeren" + }[relation] || "Blokkeren" + + 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": , + } + axios.request({ method: "post", - url: `/api/social/block`, + url: nextRelation.endpoint, headers: {"content-type": "application/json"}, data: { "id": user?.id } }) .then(() => { - toast(`${user.username} geblokkeerd`, + toast(nextRelation.action, "confirmation", - ); - setRelation("blocked"); + nextRelation.icon); + setRelation(nextRelation.relation); }); }}/> - } + })()} { relation == "friends" ? } text="Vriend verwijderen" onclick={() => { /* axios.request({ */ -- cgit v1.2.3