blob: f98f9497c8c703788441d7e63eff000cb5d1977c (
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
|
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())
}
|