diff options
Diffstat (limited to 'Sora/Views/Bookmarks')
| -rw-r--r-- | Sora/Views/Bookmarks/BookmarkListItemView.swift | 56 | ||||
| -rw-r--r-- | Sora/Views/Bookmarks/BookmarksView.swift | 107 |
2 files changed, 83 insertions, 80 deletions
diff --git a/Sora/Views/Bookmarks/BookmarkListItemView.swift b/Sora/Views/Bookmarks/BookmarkListItemView.swift index 6d62893..6c46416 100644 --- a/Sora/Views/Bookmarks/BookmarkListItemView.swift +++ b/Sora/Views/Bookmarks/BookmarkListItemView.swift @@ -1,39 +1,39 @@ import SwiftUI struct BookmarkListItemView: View { - @EnvironmentObject var settings: Settings - var bookmark: Bookmark + @EnvironmentObject var settings: Settings + var bookmark: Bookmark - var body: some View { - VStack(alignment: .leading) { - HStack { - Text(bookmark.tags.joined(separator: ", ")) + var body: some View { + VStack(alignment: .leading) { + HStack { + Text(bookmark.tags.joined(separator: ", ")) - #if os(macOS) - Spacer() + #if os(macOS) + Spacer() - Button { - settings.removeBookmark(withID: bookmark.id) - } label: { - Image(systemName: "trash") - } - #endif - } + Button { + settings.removeBookmark(withID: bookmark.id) + } label: { + Image(systemName: "trash") + } + #endif + } - HStack { - Text(bookmark.createdAt, style: .date) - .font(.caption) - .foregroundStyle(Color.secondary) + HStack { + Text(bookmark.createdAt, style: .date) + .font(.caption) + .foregroundStyle(Color.secondary) - Spacer() + Spacer() - Text(bookmark.provider.formatted()) - .font(.caption) - .foregroundStyle(Color.secondary) - } - } - #if os(macOS) - .padding() - #endif + Text(bookmark.provider.formatted()) + .font(.caption) + .foregroundStyle(Color.secondary) + } } + #if os(macOS) + .padding() + #endif + } } diff --git a/Sora/Views/Bookmarks/BookmarksView.swift b/Sora/Views/Bookmarks/BookmarksView.swift index 83eda0e..b36ee45 100644 --- a/Sora/Views/Bookmarks/BookmarksView.swift +++ b/Sora/Views/Bookmarks/BookmarksView.swift @@ -1,69 +1,72 @@ import SwiftUI struct BookmarksView: View { - @EnvironmentObject var settings: Settings - @EnvironmentObject var manager: BooruManager - @Binding var selectedTab: Int - @State private var bookmarksSearchText: String = "" + @EnvironmentObject var settings: Settings + @EnvironmentObject var manager: BooruManager + @Binding var selectedTab: Int + @State private var bookmarksSearchText: String = "" - var filteredBookmarks: [Bookmark] { - guard !bookmarksSearchText.isEmpty else { - return settings.bookmarks - } - - return settings.bookmarks - .filter { $0.tags.joined(separator: " ").lowercased().contains(bookmarksSearchText.lowercased()) } + var filteredBookmarks: [Bookmark] { + guard !bookmarksSearchText.isEmpty else { + return settings.bookmarks } - var body: some View { - NavigationStack { - VStack { - if settings.bookmarks.isEmpty { - ContentUnavailableView("No Bookmarks", - systemImage: "bookmark", - description: Text("Add a bookmark by tapping the bookmark button on a search page.")) - } else { - List { - if filteredBookmarks.isEmpty, !bookmarksSearchText.isEmpty { - Text("No bookmarks match your search") - } + return settings.bookmarks + .filter { + $0.tags.joined(separator: " ").lowercased().contains(bookmarksSearchText.lowercased()) + } + } + + var body: some View { + NavigationStack { + VStack { + if settings.bookmarks.isEmpty { + ContentUnavailableView( + "No Bookmarks", + systemImage: "bookmark", + description: Text("Add a bookmark by tapping the bookmark button on a search page.")) + } else { + List { + if filteredBookmarks.isEmpty, !bookmarksSearchText.isEmpty { + Text("No bookmarks match your search") + } - ForEach( - filteredBookmarks, - id: \.self - ) { bookmark in - Button(action: { - let previousProvider = settings.preferredBooru + ForEach( + filteredBookmarks, + id: \.self + ) { bookmark in + Button(action: { + let previousProvider = settings.preferredBooru - settings.preferredBooru = bookmark.provider - manager.searchText = bookmark.tags.joined(separator: " ") - selectedTab = 0 + settings.preferredBooru = bookmark.provider + manager.searchText = bookmark.tags.joined(separator: " ") + selectedTab = 0 - if previousProvider == settings.preferredBooru { - manager.performSearch() - } - }) { - BookmarkListItemView(bookmark: bookmark) - } - #if os(macOS) - .buttonStyle(.plain) - #endif - } - .onDelete(perform: settings.removeBookmark) - } - #if os(macOS) - .listStyle(.plain) - #endif + if previousProvider == settings.preferredBooru { + manager.performSearch() } + }) { + BookmarkListItemView(bookmark: bookmark) + } + #if os(macOS) + .buttonStyle(.plain) + #endif } + .onDelete(perform: settings.removeBookmark) + } + #if os(macOS) + .listStyle(.plain) + #endif } - .navigationTitle("Bookmarks") - .searchable(text: $bookmarksSearchText) + } } + .navigationTitle("Bookmarks") + .searchable(text: $bookmarksSearchText) + } } #Preview { - BookmarksView(selectedTab: .constant(1)) - .environmentObject(Settings()) - .environmentObject(BooruManager(.yandere)) + BookmarksView(selectedTab: .constant(1)) + .environmentObject(Settings()) + .environmentObject(BooruManager(.yandere)) } |