diff options
Diffstat (limited to 'Sora/Views/BookmarksView.swift')
| -rw-r--r-- | Sora/Views/BookmarksView.swift | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Sora/Views/BookmarksView.swift b/Sora/Views/BookmarksView.swift new file mode 100644 index 0000000..f98f949 --- /dev/null +++ b/Sora/Views/BookmarksView.swift @@ -0,0 +1,63 @@ +import SwiftUI + +struct BookmarksView: View { + @EnvironmentObject var settings: Settings + @EnvironmentObject var manager: MoebooruManager + @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 { + if settings.bookmarks.isEmpty { + VStack { + Spacer() + + Text("There are no bookmarks yet. Add a bookmark by tapping the bookmark button in the bottom left corner of a search page.") + .padding() + + Spacer() + } + } else { + List { + if filteredBookmarks.isEmpty { + Text("No bookmarks found.") + } + + ForEach(filteredBookmarks, id: \.self) { bookmark in + Button(action: { + manager.searchText = bookmark.tags.joined(separator: " ") + manager.performSearch() + selectedTab = 0 + }) { + HStack { + Text(bookmark.tags.joined(separator: ", ")) + + Text(bookmark.createdAt.formatted()) + .foregroundColor(.secondary) + .font(.caption) + } + } + } + .onDelete(perform: settings.removeBookmark) + } + } + } + .navigationTitle("Bookmarks") + .searchable(text: $bookmarksSearchText) + } +} + +#Preview { + BookmarksView(selectedTab: .constant(1)) + .environmentObject(Settings()) + .environmentObject(MoebooruManager()) +} |