import SwiftUI struct DepotList: View { @StateObject private var DATA = DataService() @State private var isDepotAddPresented = false var type: String var depots: [Depot] { DATA.depots.filter{ depot in return depot.type == type.lowercased() } } var date: Date { DATA.getMostCurrentDate(depots) } private func deleteData(indexSet: IndexSet) { let id = indexSet.map { self.depots[$0].id } let parameters: [String: Any] = ["id": id[0], "type": "depot"] //self.DATA.deleteData(parameters: parameters) } var body: some View { VStack { VStack { if depots.count > 0 { HStack { Spacer() if depots.count > 0 { Text("Daten per: "+DateFormat(datum: date).description) .font(.system(size: 12)) .padding(.trailing) } } .padding(.vertical) List { ForEach(depots) { depot in NavigationLink(destination: DepotDetails(depot_id: depot.id)) { DepotListRow(depot_id: depot.id) .padding(.vertical, 10) } .foregroundColor(.primary) } .onDelete(perform: deleteData) } .listStyle(.plain) } else { Spacer() Text("Keine Depots vorhanden") .font(.headline) .padding() NavigationLink(destination: EmptyView() /*DepotAdd(type: type)*/) { HStack { Image(systemName: "plus") Text("Depot hinzufügen") } } Spacer() } } //.padding(.horizontal) if depots.count > 0 { VStack { HStack(alignment: .firstTextBaseline) { Text("Totalbetrag") Spacer() CHFValue(betrag: DATA.getTotal(depots)) //.foregroundColor(Color.accentColor) } .font(.headline) .padding() .foregroundColor(Color.primary) } } } .navigationTitle(type) .navigationBarTitleDisplayMode(.inline) .task { do { try await DATA.readDepotAll() try await DATA.readDepotstandAll() } catch { print(error.localizedDescription) } } .toolbar { HStack { if depots.count > 0 { EditButton() Button { isDepotAddPresented.toggle() } label: { Image(systemName: "plus") } /*.sheet(isPresented: $isDepotAddPresented) { DepotAdd(type: type) }*/ .fullScreenCover(isPresented: $isDepotAddPresented) { NavigationView { //DepotAdd(type: type) } } } } } } }