blob: ccef3f160470a31429db9c596a05bc100234b1bf (
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
import SwiftUI
struct BookmarksView: View {
@EnvironmentObject var settings: SettingsManager
@EnvironmentObject var manager: BooruManager
@Binding var selectedTab: Int
@State private var bookmarksSearchText: String = ""
@State private var isShowingRemoveAllConfirmation = false
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.sorted { $0.date > $1.date },
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(settings: settings)
}
}) {
GenericItemView(
item: bookmark,
removeAction: settings.removeBookmark
)
}
#if os(macOS)
.buttonStyle(.plain)
#endif
}
.onDelete(perform: settings.removeBookmark)
}
}
}
}
.navigationTitle("Bookmarks")
.searchable(text: $bookmarksSearchText)
.toolbar {
ToolbarItem {
Button(action: {
isShowingRemoveAllConfirmation = true
}) {
Label("Remove All Bookmarks", systemImage: "trash")
}
}
}
.confirmationDialog(
"Are you sure you want to remove all bookmarks? This action cannot be undone.",
isPresented: $isShowingRemoveAllConfirmation
) {
Button("Remove All Bookmarks") {
settings.bookmarks.removeAll()
}
}
}
}
#Preview {
BookmarksView(selectedTab: .constant(1))
.environmentObject(SettingsManager())
.environmentObject(BooruManager(.yandere))
}
|