158 lines
4.6 KiB
Swift
158 lines
4.6 KiB
Swift
//import SwiftData
|
|
//import SwiftUI
|
|
//
|
|
//struct UnicycleView2: View {
|
|
// var body: some View {
|
|
// Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
|
// }
|
|
//}
|
|
//
|
|
//struct UnicycleView: View {
|
|
// @Environment(\.modelContext) private var modelContext
|
|
// @Query private var unis: [Unicycle]
|
|
//
|
|
// var body: some View {
|
|
// Button("Add unicycle") {
|
|
// modelContext.insert(Unicycle(createdAt: Date()))
|
|
// }
|
|
// List{
|
|
// ForEach(unis) { uni in
|
|
// Text("Einrad von \(uni.createdAt.description)")
|
|
// }.onDelete {
|
|
// for index in $0 {
|
|
// modelContext.delete(unis[index])
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//struct UniListView: View {
|
|
// @Environment(\.modelContext) private var modelContext
|
|
// @Query private var unis: [Unicycle]
|
|
//
|
|
// init(filter: String, sort: SortDescriptor<Unicycle>) {
|
|
// _unis = Query(filter: #Predicate<Unicycle> {
|
|
// filter.isEmpty || $0.name.contains(filter)
|
|
// }, sort: [sort])
|
|
// }
|
|
//
|
|
// var body: some View {
|
|
// List {
|
|
// ForEach(unis) { u in
|
|
// NavigationLink {
|
|
// UniDetailView(uni: u)
|
|
// } label: {
|
|
// HStack {
|
|
// VStack(alignment: .leading) {
|
|
// Text(u.name)
|
|
// Text(u.createdAt.description)
|
|
// .font(.caption)
|
|
// }
|
|
// Spacer()
|
|
// ColorPicker("", selection: .constant(u.color))
|
|
// .disabled(true)
|
|
// }
|
|
// }
|
|
// }
|
|
// .onDelete {
|
|
// for index in $0 { // [2, 3]
|
|
// modelContext.delete(unis[index])
|
|
// }
|
|
// }
|
|
// }
|
|
// .navigationTitle("\(unis.count) Unicycles")
|
|
// }
|
|
//}
|
|
//
|
|
//struct UnicycleView3: View {
|
|
// @Environment(\.modelContext) private var modelContext
|
|
//
|
|
// @State private var isPresented = false
|
|
// @State private var sortOrder = SortDescriptor(\Unicycle.name)
|
|
// @State private var search = ""
|
|
//
|
|
// var body: some View {
|
|
// NavigationStack {
|
|
// UniListView(filter: search, sort: sortOrder)
|
|
// .searchable(text: $search)
|
|
// .toolbar {
|
|
// ToolbarItem(placement: .topBarLeading) {
|
|
// EditButton()
|
|
// }
|
|
// ToolbarItem(placement: .topBarTrailing) {
|
|
// HStack {
|
|
// Button("Add", systemImage: "plus") { isPresented = true }
|
|
// picker
|
|
// }
|
|
// }
|
|
// }
|
|
// .sheet(isPresented: $isPresented) {
|
|
// UniDetailView(uni: Unicycle())
|
|
// }
|
|
// Button("Save") {
|
|
// try? modelContext.save()
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// var picker: some View {
|
|
// Menu("Sort", systemImage: "arrow.up.arrow.down") {
|
|
// Picker("Sort", selection: $sortOrder) {
|
|
// Text("Name")
|
|
// .tag(SortDescriptor(\Unicycle.name))
|
|
// Text("Date")
|
|
// .tag(SortDescriptor(\Unicycle.createdAt, order: .reverse))
|
|
// }
|
|
// .pickerStyle(.inline)
|
|
// }
|
|
// }
|
|
//}
|
|
//
|
|
//struct UniDetailView2: View {
|
|
// @Environment(\.modelContext) private var modelContext
|
|
// @Bindable var uni: Unicycle
|
|
// @Environment(\.dismiss) private var dismiss
|
|
//
|
|
// var body: some View {
|
|
// Form {
|
|
// DefaultTextField("Enter a name", $uni.name)
|
|
// ColorPicker("Color", selection: $uni.color)
|
|
// Button("Save") {
|
|
// modelContext.insert(uni)
|
|
// dismiss()
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
//
|
|
//struct DefaultTextField: View {
|
|
// @FocusState private var isFocused: Bool
|
|
// private var placeholder: String
|
|
// private var text: Binding<String>
|
|
//
|
|
// init(_ placeholder: String = "", _ text: Binding<String>) {
|
|
// self.placeholder = placeholder
|
|
// self.text = text
|
|
// }
|
|
//
|
|
// var body: some View {
|
|
// TextField(placeholder, text: text)
|
|
// .focused($isFocused)
|
|
// .onAppear { isFocused = true }
|
|
// }
|
|
//}
|
|
//
|
|
//#Preview {
|
|
// UnicycleView()
|
|
// .modelContainer(for: Unicycle.self)
|
|
//}
|
|
//
|
|
//
|
|
//
|
|
//#Preview {
|
|
// UnicycleView()
|
|
//}
|