Compare commits
No commits in common. "12ff7b0e8a2f7d0b1414831d3474daa95cea813e" and "6829e5db6cb3da5e57e4cc727e35f0bcfd5fad31" have entirely different histories.
12ff7b0e8a
...
6829e5db6c
@ -43,24 +43,4 @@ public class EmployeeService: EmployeeServiceProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Networkservice {
|
|
||||||
public static let shared = Networkservice()
|
|
||||||
|
|
||||||
public init(){}
|
|
||||||
|
|
||||||
public func fetch<T: Decodable>(endpoint: String, type: T.Type) async throws -> T {
|
|
||||||
guard let url = URL(string: endpoint) else {
|
|
||||||
throw URLError(.badURL)
|
|
||||||
}
|
|
||||||
|
|
||||||
let (data, response) = try await URLSession.shared.data(from: url)
|
|
||||||
|
|
||||||
guard let httpResponse = response as? HTTPURLResponse,
|
|
||||||
200..<300 ~= httpResponse.statusCode else {
|
|
||||||
throw URLError(.badServerResponse)
|
|
||||||
}
|
|
||||||
|
|
||||||
return try JSONDecoder().decode(T.self, from: data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@ -19,16 +19,12 @@ struct EmployeeListView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
List {
|
List {
|
||||||
//build out dynamic rows first
|
ForEach(viewModel.employees) { employee in
|
||||||
ForEach(viewModel.employees, id: \.id) { employee in
|
|
||||||
NavigationLink(destination: EmployeeDetailsView(viewModel: .init(employee: employee))) {
|
NavigationLink(destination: EmployeeDetailsView(viewModel: .init(employee: employee))) {
|
||||||
EmployeeRowView(viewModel: .init(employee: employee))
|
EmployeeRowView(viewModel: .init(employee: employee))
|
||||||
}
|
}
|
||||||
.listRowInsets(.none)
|
|
||||||
.listRowSeparator(.hidden)
|
.listRowSeparator(.hidden)
|
||||||
}
|
}
|
||||||
|
|
||||||
//add static row if there is a next page
|
|
||||||
if viewModel.hasNextPage {
|
if viewModel.hasNextPage {
|
||||||
ProgressView()
|
ProgressView()
|
||||||
.frame(maxWidth: .infinity, alignment: .center)
|
.frame(maxWidth: .infinity, alignment: .center)
|
||||||
@ -38,7 +34,7 @@ struct EmployeeListView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("Employees")
|
.navigationTitle("Employees")
|
||||||
.listStyle(.insetGrouped)
|
.listStyle(.plain)
|
||||||
}
|
}
|
||||||
.task {
|
.task {
|
||||||
if viewModel.employees.isEmpty {
|
if viewModel.employees.isEmpty {
|
||||||
|
|||||||
@ -37,6 +37,7 @@ struct EmployeeRowView: View {
|
|||||||
|
|
||||||
Spacer() // Pushes everything to the left
|
Spacer() // Pushes everything to the left
|
||||||
}
|
}
|
||||||
|
.padding(.vertical, 8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user