summaryrefslogtreecommitdiff
path: root/Sora/Views/BookmarksView.swift
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-02-28 03:33:21 -0800
committerFuwn <[email protected]>2025-02-28 03:33:21 -0800
commite084ee2714c76f9081d4c57d07dec7ddd21783c2 (patch)
treec0798a5d409bd320d89905952475298ee8bec79f /Sora/Views/BookmarksView.swift
parentfeat: Development commit (diff)
downloadsora-testing-e084ee2714c76f9081d4c57d07dec7ddd21783c2.tar.xz
sora-testing-e084ee2714c76f9081d4c57d07dec7ddd21783c2.zip
feat: Development commit
Diffstat (limited to 'Sora/Views/BookmarksView.swift')
-rw-r--r--Sora/Views/BookmarksView.swift76
1 files changed, 76 insertions, 0 deletions
diff --git a/Sora/Views/BookmarksView.swift b/Sora/Views/BookmarksView.swift
new file mode 100644
index 0000000..a84038d
--- /dev/null
+++ b/Sora/Views/BookmarksView.swift
@@ -0,0 +1,76 @@
+import SwiftUI
+
+struct BookmarksView: View {
+ @EnvironmentObject var settings: SettingsManager
+ @EnvironmentObject var manager: BooruManager
+ @Binding var selectedTab: Int
+ @State private var bookmarksSearchText: String = ""
+
+ var filteredBookmarks: [SettingsBookmark] {
+ guard !bookmarksSearchText.isEmpty else {
+ return settings.bookmarks
+ }
+
+ return settings.bookmarks
+ .filter { bookmark in
+ bookmark.tags.joined(separator: " ").lowercased().contains(bookmarksSearchText.lowercased())
+ }
+ }
+
+ var body: some View {
+ NavigationStack {
+ VStack {
+ if settings.bookmarks.isEmpty {
+ ContentUnavailableView(
+ "No Bookmarks",
+ systemImage: "bookmark",
+ description: Text("Tap the bookmark button on a search page to add a bookmark.")
+ )
+ } 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()
+ }
+ }) {
+ GenericItemView(
+ item: bookmark,
+ removeAction: settings.removeBookmark
+ )
+ }
+ #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(SettingsManager())
+ .environmentObject(BooruManager(.yandere))
+}