63 lines
2.3 KiB
Swift
63 lines
2.3 KiB
Swift
import SwiftUI
|
|
|
|
struct ListView: TabContent {
|
|
static var title = "List"
|
|
static var image = "list.bullet"
|
|
static var id = UUID()
|
|
|
|
@State var bikes = Bike.all
|
|
@State private var search: String = ""
|
|
@FocusState var focusedField: UUID? // 1
|
|
|
|
|
|
var body: some View {
|
|
|
|
// let filterdBikes = {$bikes.filter { $0.name.contains(search ?? "") }}
|
|
|
|
|
|
if bikes.isEmpty {
|
|
ContentUnavailableView("No bikes found", systemImage: "bike")
|
|
} else {
|
|
NavigationStack {
|
|
|
|
|
|
List {
|
|
Section {
|
|
|
|
|
|
ForEach($bikes) { $bike in
|
|
// HStack {
|
|
// TextField("New Bike", text: $bike.name)
|
|
// .focused($focusedField, equals: bike.id)
|
|
// .textFieldStyle(.roundedBorder)
|
|
// Spacer()
|
|
// Text("\(bike.price, specifier: "%.2f€")")
|
|
// ColorPicker("", selection: $bike.color)
|
|
// }
|
|
|
|
HStack {
|
|
BikeView(bike: bike)
|
|
Spacer()
|
|
ColorPicker("", selection: $bike.color)
|
|
|
|
}
|
|
}
|
|
.onDelete { bikes.remove(atOffsets: $0) }
|
|
}
|
|
footer: {
|
|
Button("Add a new Bike") {
|
|
let bike = Bike(name: "", color: .white)
|
|
bikes.append(bike)
|
|
// focusedField = bike.id
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
}
|
|
}.searchable(text: $search)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
ListView()
|
|
}
|