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