Skip to content

Commit 201bdbb

Browse files
committed
Reload button when opted in or out
1 parent 68a507f commit 201bdbb

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

ShiftDetailInteractor.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ class ShiftDetailInteractor {
2424
if let user = UserManager.currentUser {
2525
if shift.currentUserAssigned.boolValue {
2626
APIClient.optOut(user, shift: self.shift, success: { (json) in
27-
print("Opted out")
27+
self.shift.currentUserAssigned = false
28+
self.loadShift()
2829
}) { (message) in
2930
print("No good")
3031
}
3132
}
3233
else {
3334
APIClient.optIn(user, shift: self.shift, success: { (json) in
34-
print("Opted In")
35+
self.shift.currentUserAssigned = true
36+
self.loadShift()
3537
}) { (message) in
3638
print("No good")
3739
}

Where2Help/EventMapper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct Shift: JSONJoy {
1717
let volunteersNeeded: Int!
1818
let volunteersCount: Int!
1919
let createdAt: NSDate!
20-
let currentUserAssigned: Bool!
20+
var currentUserAssigned: Bool!
2121

2222
init(_ decoder: JSONDecoder) throws {
2323
ID = try decoder["id"].getInt()

Where2Help/ShiftDetailViewController.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ class ShiftDetailViewController: UIViewController, ShiftHandler {
3030
super.viewDidLoad()
3131
}
3232

33+
override func viewWillAppear(animated: Bool) {
34+
super.viewWillAppear(animated)
35+
interactor.setup(self, event: event, shift: shift)
36+
}
37+
3338
override func viewDidLayoutSubviews() {
3439
super.viewDidLayoutSubviews()
35-
interactor.setup(self, event: event, shift: shift)
36-
shift.currentUserAssigned.boolValue ? imInButton.optedIn() : imInButton.optedOut()
3740
}
3841

3942
// MARK: - ShiftHandler
@@ -72,6 +75,7 @@ class ShiftDetailViewController: UIViewController, ShiftHandler {
7275
timeLabel.text = shift.timespanLabelText()
7376
dateLabel.text = shift.dateString()
7477
volunteerCountLabel.text = "\(shift.volunteersOutOfLabelText()) Volunteers"
78+
shift.shift.currentUserAssigned.boolValue ? imInButton.optedIn() : imInButton.optedOut()
7579
}
7680

7781
///////////////////////////////////

0 commit comments

Comments
 (0)