diff options
Diffstat (limited to 'Sora')
| -rw-r--r-- | Sora/Views/Generic/GenericListView.swift | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/Sora/Views/Generic/GenericListView.swift b/Sora/Views/Generic/GenericListView.swift index 1d44e15..93b141b 100644 --- a/Sora/Views/Generic/GenericListView.swift +++ b/Sora/Views/Generic/GenericListView.swift @@ -9,6 +9,8 @@ struct GenericListView<T: Identifiable & Hashable & GenericItem>: View { @Binding var isPresented: Bool @State private var isNewCollectionAlertPresented = false @State private var newCollectionName = "" + @State private var itemPendingCollectionAssignment: UUID? + @State private var isCollectionErrorAlertPresented = false let allowBookmarking: Bool let title: String let emptyMessage: String @@ -91,11 +93,31 @@ struct GenericListView<T: Identifiable & Hashable & GenericItem>: View { } Button("Create") { - settings.folders.append(SettingsFolder(name: newCollectionName)) + if newCollectionName.isEmpty { + isCollectionErrorAlertPresented = true + } else { + let newFolder = SettingsFolder(name: newCollectionName) - isNewCollectionAlertPresented = false + settings.folders.append(newFolder) + + if let id = itemPendingCollectionAssignment { + settings.updateBookmarkFolder(withID: id, folder: newFolder) + } + + itemPendingCollectionAssignment = nil + newCollectionName = "" + isNewCollectionAlertPresented = false + } } } + .alert( + "Error", + isPresented: $isCollectionErrorAlertPresented, + ) { + Button("OK", role: .cancel) { () } + } message: { + Text("Collection name cannot be empty.") + } } func itemButtonContent(item: T) -> some View { @@ -140,6 +162,7 @@ struct GenericListView<T: Identifiable & Hashable & GenericItem>: View { } Button(action: { + itemPendingCollectionAssignment = item.id isNewCollectionAlertPresented = true }) { Label("New Collection", systemImage: "plus") |