Skip to content

Commit

Permalink
Merge pull request #176 from SquareTable/175-categoryviewpage-should-…
Browse files Browse the repository at this point in the history
…use-new-templeavecategory-api

CategoryViewPage now uses new temp/leavecategory API
  • Loading branch information
Sebastian-Webster authored Sep 9, 2023
2 parents 1dd043e + 8e4ae7f commit e9200e3
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions screens/CategoryViewPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -463,7 +446,7 @@ const CategoryViewPage = ({route, navigation}) => {
)}
</View>
)}
<TouchableOpacity style={{height: 30, width: '80%', backgroundColor: dark ? colors.darkLight : colors.borderColor, borderRadius: 10, justifyContent: 'center', alignItems: 'center', marginVertical: 5}} onPress={JoinCategory}>
<TouchableOpacity style={{height: 30, width: '80%', backgroundColor: dark ? colors.darkLight : colors.borderColor, borderRadius: 10, justifyContent: 'center', alignItems: 'center', marginVertical: 5}} onPress={JoinLeaveCategory}>
{typeof inCategory === "boolean" ?
<Text style={{fontSize: 20, color: colors.tertiary}}>{inCategory ? 'Leave' : 'Join'}</Text>
: inCategory === "Changing" || inCategory === "Finding" ?
Expand Down

0 comments on commit e9200e3

Please sign in to comment.