summaryrefslogtreecommitdiff
path: root/Sora/Views/Bookmarks/BookmarksView.swift
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-02-21 01:53:31 -0800
committerFuwn <[email protected]>2025-02-21 01:53:35 -0800
commit617370e834db97c2c6ce5c5bbd3825fcad013b7f (patch)
tree8d20d45c0cb1169d8c08509e106d0d57b0d71c72 /Sora/Views/Bookmarks/BookmarksView.swift
parentfeat: Development commit (diff)
downloadsora-testing-617370e834db97c2c6ce5c5bbd3825fcad013b7f.tar.xz
sora-testing-617370e834db97c2c6ce5c5bbd3825fcad013b7f.zip
feat: Development commit
Diffstat (limited to 'Sora/Views/Bookmarks/BookmarksView.swift')
-rw-r--r--Sora/Views/Bookmarks/BookmarksView.swift69
1 files changed, 69 insertions, 0 deletions
diff --git a/Sora/Views/Bookmarks/BookmarksView.swift b/Sora/Views/Bookmarks/BookmarksView.swift
new file mode 100644
index 0000000..9a0ef75
--- /dev/null
+++ b/Sora/Views/Bookmarks/BookmarksView.swift
@@ -0,0 +1,69 @@
+import SwiftUI
+
+struct BookmarksView: View {
+ @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 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
+
+ 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
+ }
+ }
+ }
+ .navigationTitle("Bookmarks")
+ .searchable(text: $bookmarksSearchText)
+ }
+}
+
+#Preview {
+ BookmarksView(selectedTab: .constant(1))
+ .environmentObject(Settings())
+ .environmentObject(BooruManager(.yandere))
+}