fixed issues in refresh
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
67b2163134
commit
4e59fa6f6a
@ -139,12 +139,13 @@ class EmployeesViewController: UIViewController {
|
||||
viewModel.$isLoading
|
||||
.receive(on: RunLoop.main)
|
||||
.sink { [weak self] isLoading in
|
||||
guard let self, let refreshControl = self.tableView.refreshControl else { return }
|
||||
if isLoading {
|
||||
self?.activityIndicator.startAnimating()
|
||||
activityIndicator.startAnimating()
|
||||
} else {
|
||||
self?.activityIndicator.stopAnimating()
|
||||
self?.tableView.refreshControl?.endRefreshing()
|
||||
self?.updateFooter()
|
||||
activityIndicator.stopAnimating()
|
||||
refreshControl.endRefreshing()
|
||||
updateFooter()
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
@ -182,7 +183,7 @@ class EmployeesViewController: UIViewController {
|
||||
var footerMessage: String?
|
||||
|
||||
// Check for error messages or empty state first
|
||||
if let message = viewModel.errorMessage ?? (viewModel.employees.isEmpty && !viewModel.isLoading ? "No employees found, please try to refresh." : nil) {
|
||||
if let message = viewModel.errorMessage ?? (viewModel.employees.isEmpty && viewModel.isLoading == false ? "No employees found, please try to refresh." : nil) {
|
||||
footerMessage = message
|
||||
|
||||
}
|
||||
|
||||
@ -46,10 +46,11 @@ public class EmployeesViewModel: ObservableObject {
|
||||
|
||||
/// Fetch employees for the given page
|
||||
public func fetchEmployees(page: Int = 1) {
|
||||
|
||||
// Prevent duplicate calls
|
||||
guard !isLoading else { return }
|
||||
errorMessage = nil
|
||||
isLoading = true
|
||||
|
||||
Task {
|
||||
do {
|
||||
// Fetch employees using the paginated API
|
||||
@ -68,6 +69,7 @@ public class EmployeesViewModel: ObservableObject {
|
||||
} else {
|
||||
employees.append(contentsOf: wrapper.employees) // Append for subsequent pages
|
||||
}
|
||||
|
||||
} catch {
|
||||
// Handle errors
|
||||
errorMessage = "An unexpected error occurred, please try to refresh."
|
||||
|
||||
Loading…
Reference in New Issue
Block a user