Skip to content

Commit

Permalink
feat: add refresh button on Select Device page (#31)
Browse files Browse the repository at this point in the history
change title from "Select Panel" to "Select Device"
  • Loading branch information
yingtao-butterflymx committed Nov 30, 2021
1 parent 3c43c77 commit 7dfb0e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,35 @@

import UIKit
import BMXCore
import SVProgressHUD

class DoorsTableViewController: UITableViewController {
var devices: [DeviceModel]?
var tenant: TenantModel?

override func viewDidLoad() {
super.viewDidLoad()
title = "Select Panel"
title = "Select Device"
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .refresh, target: self, action: #selector(reloadData))
}

@objc func reloadData() {
guard let tenant = tenant else {
return
}
SVProgressHUD.show()
BMXCoreKit.shared.reloadUserData { result in
SVProgressHUD.dismiss()
switch result {
case .success:
if let tenant = try? BMXUser.shared.getTenants().first(where: {tenant.id == $0.id}) {
self.devices = BMXUser.shared.getDevices(from: tenant)
self.tableView.reloadData()
}
case .failure(let error):
BMXCoreKit.shared.log(message: "Failed to reload data: \(error.localizedDescription)")
}
}
}

static func initViewController() -> DoorsTableViewController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class UnitsViewController: UITableViewController {
tableView.dataSource = self
tableView.delegate = self
tableView.rowHeight = 44
tenants = BMXUser.shared.getTenants()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tenants = BMXUser.shared.getTenants()
tableView.reloadData()
}
}
Expand Down

0 comments on commit 7dfb0e0

Please sign in to comment.