struct LanguagesView: View {
@State var activeSheet: ActiveSheet?
@State var toBeEdit: MeLanguage?
@State
var toBeEditbody: MeLanguage?some View {
NavigationView {
List {
ForEach(self.meLanguages, id: \.id) { lan in
HStack {
Text("\(lan.wrappedName)")
HStack {
.font(.headline) Text("\(lan.wrappedName)")
}.font(.headline)
}.swipeActions(allowsFullSwipe: false)
{
Button(
action: {
self.toBeEditactiveSheet = lan.editLanguage
self.activeSheettoBeEdit = .editLanguage lan
},
label: { Label("Edit", systemImage: "pencil") }
) .tint(.indigo)
}
}
.sheet(item: $activeSheet,
}
}
onDismiss: {
.sheet(item: $activeSheet,
self.toBeEdit = nil onDismiss: {
self.toBeEdit = nil
}
){
item in
switch item {
case .addLanguage:
AddLanguage()
case .sortLanguages:
SortLanguagesView()
case .editLanguage:
if self.toBeEdit != nil {
EditLanguageView( meLanguage: self.toBeEdit! )
}
else {
Text("self.toBeEdit is nil")
}
default:
Text("No such button on ContentView.")
}
}
.toolbar {
.toolbar {
ToolbarItemGroup {
HStack {
Text("\(self.meLanguages.count) Languages on Card").font(.headline)
self.barButtons
}
}
}
}
}
var barButtons: some View {
HStack {
Button(
action: {
self.activeSheet = .sortLanguages
},
label: {
Label("Sort Languages", systemImage: "arrow.up.arrow.down.circle")
}
).id("sortLanguages")
Button(
action: {
self.activeSheet = .addLanguage
},
label: { Label("Add Language",
systemImage: "plus")
.imageScale(.large)
}
)
}
}
}