converted to navigationStack
This commit is contained in:
parent
aed9caabdb
commit
ab5593d773
@ -23,23 +23,19 @@ struct ContentView: View {
|
||||
//MARK: - Views
|
||||
public struct EmployeeDirectoryList: View {
|
||||
@State public var viewModel: EmployeesViewModel
|
||||
|
||||
@State public var path = NavigationPath()
|
||||
init(viewModel: EmployeesViewModel? = nil) {
|
||||
_viewModel = .init(wrappedValue: viewModel ?? .init(service: EmployeeService()))
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
NavigationStack {
|
||||
NavigationStack(path: $path) {
|
||||
List {
|
||||
ForEach(viewModel.employees, id: \.id) { employee in
|
||||
let employeeViewModel = EmployeeViewModel(employee: employee)
|
||||
NavigationLink(destination: EmployeeDetailView(viewModel: .init(employee: employee))) {
|
||||
HStack (spacing: 10) {
|
||||
|
||||
ProfileImageView(urlString: employeeViewModel.smallPhoto, size: 51)
|
||||
|
||||
VStack(alignment: .leading) {
|
||||
|
||||
Text(employeeViewModel.fullName)
|
||||
.font(.headline)
|
||||
|
||||
@ -60,10 +56,10 @@ public struct EmployeeDirectoryList: View {
|
||||
.font(.caption)
|
||||
}
|
||||
}
|
||||
}.onTapGesture {
|
||||
path.append(employee)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if viewModel.hasNextPage {
|
||||
ProgressView()
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
@ -73,6 +69,9 @@ public struct EmployeeDirectoryList: View {
|
||||
}
|
||||
}
|
||||
.navigationTitle("Employee Directory")
|
||||
.navigationDestination(for: Employee.self) { employee in
|
||||
EmployeeDetailView(viewModel: .init(employee: employee))
|
||||
}
|
||||
.listStyle(.insetGrouped)
|
||||
.task {
|
||||
if viewModel.employees.isEmpty {
|
||||
@ -112,7 +111,9 @@ public struct EmployeeDetailView: View {
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}.padding(.all)
|
||||
}
|
||||
.navigationTitle("Employee Details")
|
||||
.padding(.all)
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,7 +267,7 @@ public class NetworkService {
|
||||
}
|
||||
|
||||
//MARK: - Models
|
||||
public struct Employee: Codable, Identifiable, CustomStringConvertible {
|
||||
public struct Employee: Codable, Identifiable, CustomStringConvertible, Hashable {
|
||||
public var id: UUID { uuid }
|
||||
|
||||
/// The unique identifier for the employee. Represented as a UUID.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user