Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CategoryViewPage now uses new temp/leavecategory API #176

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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