Skip to content

Commit

Permalink
leave group stuff and change to group size based on backend's request (
Browse files Browse the repository at this point in the history
  • Loading branch information
huangshawn1 authored Feb 15, 2021
1 parent 0f7f10d commit c4b1342
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
5 changes: 3 additions & 2 deletions berkeley-mobile/StudyPact/API/Schema/ClassPreference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ struct AddPreferenceParams: Encodable {

init?(email: String, cryptohash: String, prefs: StudyPactPreference) {
guard let className = prefs.className,
let size = prefs.numberOfPeople,
let numberOfPeople = prefs.numberOfPeople,
let isVirtual = prefs.isVirtual else {
return nil
}
self.email = email
self.cryptohash = cryptohash
self.className = className
self.size = size
// backend wants us to send the preferred total people (including self)
self.size = numberOfPeople + 1
self.env = isVirtual ? "virtual" : "in-person"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ class StudyGroupDetailsViewController: UIViewController {
}

@objc func leaveGroup() {
StudyPact.shared.leaveGroup(group: _studyGroup) { success in
if success {
self.presentSuccessAlert(title: "Successfully left group")
} else {
self.presentFailureAlert(title: "Failed to leave group", message: "There was an error. Please try again later.")
let alertController = UIAlertController(title: "Leave Study Group", message: "Would you like to leave your study group for \(_studyGroup.className)?", preferredStyle: .alert)
alertController.addAction(UIAlertAction.init(title: "Cancel", style: .cancel))
alertController.addAction(UIAlertAction.init(title: "Yes", style: .default, handler: { _ in
StudyPact.shared.leaveGroup(group: self._studyGroup) { success in
if success {
self.dismiss(animated: true, completion: nil)
} else {
self.presentFailureAlert(title: "Failed to Leave Group", message: "There was an error. Please try again later.")
}
}
}
}))
self.present(alertController, animated: true, completion: nil)
}

let card: CardView = {
Expand Down
5 changes: 1 addition & 4 deletions berkeley-mobile/StudyPact/StudyPact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ extension StudyPact {
}
}

// MARK: LeaveGroup

// MARK: GetGroups

public func getGroups(completion: @escaping ([StudyGroup]) -> Void) {
Expand All @@ -241,8 +239,7 @@ extension StudyPact {
}
}

/// MARK: LeaveGroup
// backend hasn't implemented this yet, may need to modify
// MARK: LeaveGroup
public func leaveGroup(group: StudyGroup, completion: @escaping (Bool) -> Void) {
guard let cryptoHash = self.cryptoHash,
let email = self.email,
Expand Down

0 comments on commit c4b1342

Please sign in to comment.