From 8e4ae7fc2127e6fd0f7aad90a75ea189774ad922 Mon Sep 17 00:00:00 2001 From: Sebastian Webster Date: Sat, 9 Sep 2023 16:09:15 +1200 Subject: [PATCH] CategoryViewPage now uses new temp/leavecategory API --- screens/CategoryViewPage.js | 43 +++++++++++-------------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/screens/CategoryViewPage.js b/screens/CategoryViewPage.js index ed378ed..7aec6cf 100644 --- a/screens/CategoryViewPage.js +++ b/screens/CategoryViewPage.js @@ -234,37 +234,20 @@ const CategoryViewPage = ({route, navigation}) => { setGetCategoryItems(true) } - const JoinCategory = () => { + const JoinLeaveCategory = () => { if (storedCredentials) { - if (inCategory !== "Finding") { - const url = serverUrl + "/tempRoute/joincategory"; - - var toSend = {categoryId} - const beforeChange = inCategory - setInCategory("Changing") - console.log(toSend) - - axios.post(url, toSend).then((response) => { - const result = response.data; - const {message, status, data} = result; - - if (status !== 'SUCCESS') { - handleMessage(message, status); - setInCategory(beforeChange) - } else { - handleMessage(message, status); - if (message == "Joined Category") { - setInCategory(true) - } else { - setInCategory(false) - } - //loadAndGetValues() - //persistLogin({...data[0]}, message, status); - } + if (typeof inCategory === 'boolean') { + const previousInCategory = inCategory; + setInCategory('Changing') + + const url = serverUrl + "/tempRoute/" + (inCategory ? 'leavecategory' : 'joincategory') + const toSend = {categoryId} + + axios.post(url, toSend).then(() => { + setInCategory(!previousInCategory) }).catch(error => { - console.log(error); - setInCategory(beforeChange) - handleMessage(ParseErrorMessage(error), 'FAILED'); + setInCategory(previousInCategory) + handleMessage(ParseErrorMessage(error), 'FAILED') }) } } else { @@ -463,7 +446,7 @@ const CategoryViewPage = ({route, navigation}) => { )} )} - + {typeof inCategory === "boolean" ? {inCategory ? 'Leave' : 'Join'} : inCategory === "Changing" || inCategory === "Finding" ?