Skip to content

Commit

Permalink
Dismiss the edit datapoint dialog after making a change (#445)
Browse files Browse the repository at this point in the history
Previously after updating or deleting a data point the dialog would just
stay on the screen, until the user manually dismissed it. This was in
part because otherwise after dismissing it would look like the user's
change hadn't applied. The situation is better now because we show the
lemniscate while there are pending goal updates.

Update the behavior to refresh goals after making a change, and then
after the initial request (though likely with queuing) we will dismiss
the dialog.

Testing:
Updated a data point and observed the goal refreshed and the dialog hid
Same for deleting a data point
  • Loading branch information
theospears authored Feb 22, 2024
1 parent 3211c21 commit 730cdaf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
44 changes: 24 additions & 20 deletions BeeSwift/EditDatapointViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class EditDatapointViewController: UIViewController, UITextFieldDelegate {
private let margin = 10

var datapoint : ExistingDataPoint
var goalSlug : String
var goal : Goal!
fileprivate var datePicker = InlineDatePicker()
fileprivate var valueField = UITextField()
fileprivate var commentField = UITextField()

init(goalSlug: String, datapoint: ExistingDataPoint) {
self.goalSlug = goalSlug
init(goal: Goal, datapoint: ExistingDataPoint) {
self.goal = goal
self.datapoint = datapoint
super.init(nibName: nil, bundle: nil)
}
Expand Down Expand Up @@ -212,14 +212,18 @@ class EditDatapointViewController: UIViewController, UITextFieldDelegate {
let params = [
"urtext": self.urtext()
]
let _ = try await ServiceLocator.requestManager.put(url: "api/v1/users/\(ServiceLocator.currentUserManager.username!)/goals/\(self.goalSlug)/datapoints/\(self.datapoint.id).json", parameters: params)
let hud = MBProgressHUD.forView(self.view)
hud?.mode = .customView
hud?.customView = UIImageView(image: UIImage(named: "BasicCheckmark"))
hud?.hide(animated: true, afterDelay: 2)
let _ = try await ServiceLocator.requestManager.put(url: "api/v1/users/\(ServiceLocator.currentUserManager.username!)/goals/\(self.goal.slug)/datapoints/\(self.datapoint.id).json", parameters: params)
try await ServiceLocator.goalManager.refreshGoal(self.goal)

hud.mode = .customView
hud.customView = UIImageView(image: UIImage(named: "BasicCheckmark"))
hud.hide(animated: true, afterDelay: 0.5)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.navigationController?.dismiss(animated: true)
}
} catch {
logger.error("Error updating datapoint for goal \(self.goalSlug): \(error)")
let _ = MBProgressHUD.hide(for: self.view, animated: true)
logger.error("Error updating datapoint for goal \(self.goal.slug): \(error)")
hud.hide(animated: false)
}
}
}
Expand All @@ -230,18 +234,18 @@ class EditDatapointViewController: UIViewController, UITextFieldDelegate {
hud.mode = .indeterminate

do {
let _ = try await ServiceLocator.requestManager.delete(url: "api/v1/users/\(ServiceLocator.currentUserManager.username!)/goals/\(self.goalSlug)/datapoints/\(self.datapoint.id).json", parameters: nil)

let hud = MBProgressHUD.forView(self.view)
hud?.mode = .customView
hud?.customView = UIImageView(image: UIImage(named: "BasicCheckmark"))
hud?.hide(animated: true, afterDelay: 2)
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
self.navigationController?.popViewController(animated: true)
let _ = try await ServiceLocator.requestManager.delete(url: "api/v1/users/\(ServiceLocator.currentUserManager.username!)/goals/\(self.goal.slug)/datapoints/\(self.datapoint.id).json", parameters: nil)
try await ServiceLocator.goalManager.refreshGoal(self.goal)

hud.mode = .customView
hud.customView = UIImageView(image: UIImage(named: "BasicCheckmark"))
hud.hide(animated: true, afterDelay: 0.5)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.navigationController?.dismiss(animated: true)
}
} catch {
logger.error("Error deleting datapoint for goal \(self.goalSlug): \(error)")

logger.error("Error deleting datapoint for goal \(self.goal.slug): \(error)")
hud.hide(animated: false)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion BeeSwift/GoalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl
guard !self.goal.hideDataEntry() else { return }
guard let existingDatapoint = datapoint as? ExistingDataPoint else { return }

let editDatapointViewController = EditDatapointViewController(goalSlug: goal.slug, datapoint: existingDatapoint)
let editDatapointViewController = EditDatapointViewController(goal: goal, datapoint: existingDatapoint)
let navigationController = UINavigationController(rootViewController: editDatapointViewController)
navigationController.modalPresentationStyle = .formSheet
self.present(navigationController, animated: true, completion: nil)
Expand Down

0 comments on commit 730cdaf

Please sign in to comment.