blob: 5d27b6a29b10ddbbb806bdc5dbd5202396208597 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
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 {
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: {
settings.preferredBooru = bookmark.provider
manager.searchText = bookmark.tags.joined(separator: " ")
selectedTab = 0
}) {
let badgeView = Text(bookmark.provider.rawValue.capitalized)
HStack {
Text(bookmark.tags.joined(separator: ", "))
.foregroundStyle(.primary)
Text(bookmark.createdAt.formatted())
.foregroundColor(.secondary)
}
.badge(badgeView)
}
}
.onDelete(perform: settings.removeBookmark)
}
}
}
.navigationTitle("Bookmarks")
.searchable(text: $bookmarksSearchText)
}
}
#Preview {
BookmarksView(selectedTab: .constant(1))
.environmentObject(Settings())
.environmentObject(BooruManager(.yandere))
}
|