feat: replace new-list alert with inline TextField
This commit is contained in:
@@ -2,8 +2,8 @@ import SwiftUI
|
|||||||
|
|
||||||
struct ListsOverviewView: View {
|
struct ListsOverviewView: View {
|
||||||
@Environment(ListStore.self) private var store
|
@Environment(ListStore.self) private var store
|
||||||
@State private var showingAddList = false
|
|
||||||
@State private var newListName = ""
|
@State private var newListName = ""
|
||||||
|
@FocusState private var isFieldFocused: Bool
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
@@ -20,25 +20,24 @@ struct ListsOverviewView: View {
|
|||||||
}
|
}
|
||||||
.onDelete(perform: deleteLists)
|
.onDelete(perform: deleteLists)
|
||||||
|
|
||||||
Button(action: { showingAddList = true }) {
|
HStack {
|
||||||
Label("Neue Liste", systemImage: "plus")
|
Image(systemName: "plus")
|
||||||
.foregroundStyle(.blue)
|
.foregroundStyle(.blue)
|
||||||
|
TextField("Neue Liste", text: $newListName)
|
||||||
|
.focused($isFieldFocused)
|
||||||
|
.onSubmit(commitNewList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("MindDump")
|
.navigationTitle("MindDump")
|
||||||
.alert("Neue Liste", isPresented: $showingAddList) {
|
.onAppear { isFieldFocused = false }
|
||||||
TextField("Name", text: $newListName)
|
}
|
||||||
Button("Abbrechen", role: .cancel) {
|
|
||||||
newListName = ""
|
private func commitNewList() {
|
||||||
}
|
let name = newListName.trimmingCharacters(in: .whitespaces)
|
||||||
Button("Erstellen") {
|
if !name.isEmpty {
|
||||||
let name = newListName.trimmingCharacters(in: .whitespaces)
|
store.addList(name: name)
|
||||||
if !name.isEmpty {
|
|
||||||
store.addList(name: name)
|
|
||||||
}
|
|
||||||
newListName = ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
newListName = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private func deleteLists(at offsets: IndexSet) {
|
private func deleteLists(at offsets: IndexSet) {
|
||||||
|
|||||||
Reference in New Issue
Block a user