diff --git a/EmployeeDirectory/Views/EmployeeListView.swift b/EmployeeDirectory/Views/EmployeeListView.swift index 17260a3..6524c42 100644 --- a/EmployeeDirectory/Views/EmployeeListView.swift +++ b/EmployeeDirectory/Views/EmployeeListView.swift @@ -10,6 +10,7 @@ import SwiftUI @MainActor struct EmployeeListView: View { @StateObject public var viewModel: EmployeesViewModel + @State private var path = NavigationPath() // Dependency injection via the initializer. init(viewModel: EmployeesViewModel? = nil) { @@ -17,15 +18,16 @@ struct EmployeeListView: View { } var body: some View { - NavigationView { + NavigationStack(path: $path) { List { //build out dynamic rows first ForEach(viewModel.employees, id: \.id) { employee in - NavigationLink(destination: EmployeeDetailsView(viewModel: .init(employee: employee))) { - EmployeeRowView(viewModel: .init(employee: employee)) - } - .listRowInsets(.none) - .listRowSeparator(.hidden) + EmployeeRowView(viewModel: .init(employee: employee)) + .onTapGesture { + path.append(employee) + } + .listRowInsets(.none) + .listRowSeparator(.hidden) } //add static row if there is a next page @@ -38,6 +40,9 @@ struct EmployeeListView: View { } } .navigationTitle("Employees") + .navigationDestination(for: Employee.self, destination: { employee in + EmployeeDetailsView(viewModel: .init(employee: employee)) + }) .listStyle(.insetGrouped) } .task {