diff options
| author | Fuwn <[email protected]> | 2025-07-08 06:05:10 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-07-08 06:21:44 -0700 |
| commit | f7ed210669cd0384438b45b8fa0894d3746b8399 (patch) | |
| tree | 1b0140d3ec2bfe8ae8d33aba079ce47f2561b203 /Sora/Views/BookmarkMenuButtonView.swift | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-f7ed210669cd0384438b45b8fa0894d3746b8399.tar.xz sora-testing-f7ed210669cd0384438b45b8fa0894d3746b8399.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Views/BookmarkMenuButtonView.swift')
| -rw-r--r-- | Sora/Views/BookmarkMenuButtonView.swift | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/Sora/Views/BookmarkMenuButtonView.swift b/Sora/Views/BookmarkMenuButtonView.swift new file mode 100644 index 0000000..287d7b7 --- /dev/null +++ b/Sora/Views/BookmarkMenuButtonView.swift @@ -0,0 +1,99 @@ +import SwiftUI + +struct BookmarkMenuButtonView: View { + @EnvironmentObject var settings: SettingsManager + let tags: [String] + let provider: BooruProvider + @State private var isNewCollectionAlertPresented = false + @State private var newCollectionName = "" + @State private var itemPendingCollectionAssignment: UUID? + @State private var isCollectionErrorAlertPresented = false + + var body: some View { + let isBookmarked = settings.bookmarks.contains { bookmark in + Set(bookmark.tags) == Set(tags) + } + + Menu { + Button(action: { + if isBookmarked { + settings.removeBookmark(withTags: tags) + } else { + settings.addBookmark(provider: provider, tags: tags) + } + }) { + if isBookmarked { + Label("Remove Bookmark\(tags.count == 1 ? "" : "s")", systemImage: "bookmark.fill") + } else { + Label("Bookmark Tag\(tags.count == 1 ? "" : "s")", systemImage: "bookmark") + } + } + + Menu { + ForEach(settings.folders.filter { $0.topLevelName == nil }, id: \.id) { folder in + Button(action: { + let newBookmark = SettingsBookmark(provider: provider, tags: tags, folder: folder.id) + + settings.bookmarks.append(newBookmark) + }) { + Label(folder.name, systemImage: "folder") + } + } + + let topLevelFolders = settings.folders + .reduce(into: [String: [SettingsFolder]]()) { result, folder in + guard let topLevelName = folder.topLevelName else { return } + + result[topLevelName, default: []].append(folder) + } + + ForEach(topLevelFolders.keys.sorted(), id: \.self) { topLevelName in + Menu { + ForEach(topLevelFolders[topLevelName] ?? [], id: \.id) { folder in + Button(action: { + let newBookmark = SettingsBookmark( + provider: provider, + tags: tags, + folder: folder.id + ) + + settings.bookmarks.append(newBookmark) + }) { + Text(folder.shortName) + } + } + } label: { + Text(topLevelName) + } + } + + Button(action: { + isNewCollectionAlertPresented = true + }) { + Label("New Collection", systemImage: "plus") + } + } label: { + Label("Bookmark to Collection", systemImage: "folder.badge.plus") + } + } label: { + if isBookmarked { + Label("Bookmarked", systemImage: "bookmark.fill") + } else { + Label("Bookmark", systemImage: "bookmark") + } + } + .collectionAlerts( + isNewCollectionAlertPresented: $isNewCollectionAlertPresented, + newCollectionName: $newCollectionName, + isCollectionErrorAlertPresented: $isCollectionErrorAlertPresented + ) { newCollectionName in + let newFolder = SettingsFolder(name: newCollectionName) + + settings.folders.append(newFolder) + + let newBookmark = SettingsBookmark(provider: provider, tags: tags, folder: newFolder.id) + + settings.bookmarks.append(newBookmark) + } + } +} |