updated with new logic for dealing with employee changes

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2025-01-21 13:25:51 -06:00
parent fa5f782968
commit 3238defe84
2 changed files with 6 additions and 11 deletions

View File

@ -108,15 +108,13 @@ class EmployeesViewController: UIViewController {
/// Using the ViewModel setup combine handlers
private func bindViewModel() {
viewModel.$employees
.scan(([], [])) { previous, current in
(previous.1, current) // (oldValue, newValue)
}
.receive(on: RunLoop.main)
.sink { [weak self] newEmployees in
guard let self = self else { return }
let oldEmployees = self.viewModel.oldEmployees // Keep track of the previous state
self.animateEmployeeChanges(from: oldEmployees, to: newEmployees)
// Update footer and other UI elements as needed
self.updateFooter()
.sink { [weak self] oldValue, newValue in
self?.animateEmployeeChanges(from: oldValue, to: newValue)
self?.updateFooter()
}
.store(in: &cancellables)

View File

@ -15,8 +15,6 @@ public class EmployeesViewModel: ObservableObject {
private var serviceMode: EmployeeServiceMode = .production
private var employeeService: EmployeeServiceProtocol = MockEmployeeService.shared
@Published public private(set) var employees: [Employee] = []
public private(set) var oldEmployees: [Employee] = []
@Published public private(set) var errorMessage: String? = nil
@Published public private(set) var isLoading: Bool = false
@Published public private(set) var hasMorePages: Bool = true
@ -92,7 +90,6 @@ public class EmployeesViewModel: ObservableObject {
/// Resets the current employee list and fetches data from page 1
private func resetAndFetchEmployees() {
currentPage = 1
oldEmployees = employees
employees = []
hasMorePages = true
fetchEmployees(page: 1)