diff options
Diffstat (limited to 'Sora/Views/Generic/GenericListView.swift')
| -rw-r--r-- | Sora/Views/Generic/GenericListView.swift | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Sora/Views/Generic/GenericListView.swift b/Sora/Views/Generic/GenericListView.swift index 0207048..9a1ec10 100644 --- a/Sora/Views/Generic/GenericListView.swift +++ b/Sora/Views/Generic/GenericListView.swift @@ -7,6 +7,8 @@ struct GenericListView<T: Identifiable & Hashable & GenericItem>: View { @State private var searchText: String = "" @State private var isShowingRemoveAllConfirmation = false @Binding var isPresented: Bool + @State private var isNewCollectionAlertPresented = false + @State private var newCollectionName = "" let allowBookmarking: Bool let title: String let emptyMessage: String @@ -77,6 +79,22 @@ struct GenericListView<T: Identifiable & Hashable & GenericItem>: View { removeAllAction() } } + .alert( + "New Collection", + isPresented: $isNewCollectionAlertPresented + ) { + TextField("Collection Name", text: $newCollectionName) + + Button("Cancel") { + isNewCollectionAlertPresented = false + } + + Button("Create") { + settings.folders.append(SettingsFolder(name: newCollectionName)) + + isNewCollectionAlertPresented = false + } + } } func itemButtonContent(item: T) -> some View { @@ -109,6 +127,32 @@ struct GenericListView<T: Identifiable & Hashable & GenericItem>: View { Label("Add to Search", systemImage: "plus") } + Menu("\(item.folder != nil ? "Move" : "Add") to Collection") { + ForEach(settings.folders, id: \.id) { folder in + if item.folder?.id != folder.id { + Button(action: { + settings.updateBookmarkFolder(withID: item.id, folder: folder) + }) { + Label(folder.name, systemImage: "folder") + } + } + } + + Button(action: { + isNewCollectionAlertPresented = true + }) { + Label("New Collection", systemImage: "plus") + } + } + + if item.folder != nil { + Button(action: { + settings.updateBookmarkFolder(withID: item.id, folder: nil) + }) { + Label("Remove from Collection", systemImage: "folder.badge.minus") + } + } + if allowBookmarking { let isBookmarked = settings.bookmarks.contains { $0.tags == item.tags } |