1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 06:10:32 +05:30

Add clear history button (fix #205)

This commit is contained in:
Arkadiusz Fal 2022-08-21 17:39:06 +02:00
parent 3219e26aba
commit 5e6eff9680
2 changed files with 25 additions and 9 deletions

View File

@ -255,6 +255,11 @@ final class NavigationModel: ObservableObject {
presentingAlert = true
}
func presentAlert(_ alert: Alert) {
self.alert = alert
presentingAlert = true
}
func presentShareSheet(_ url: URL) {
shareURL = url
presentingShareSheet = true

View File

@ -221,9 +221,6 @@ struct SearchView: View {
VStack {
if showRecentQueries {
recentQueries
#if os(iOS)
.padding(.bottom, 90)
#endif
} else {
#if os(tvOS)
ScrollView(.vertical, showsIndicators: false) {
@ -299,8 +296,11 @@ struct SearchView: View {
}
}
.redrawOn(change: recentsChanged)
Section(footer: Color.clear.frame(minHeight: 80)) {
clearHistoryButton
}
}
.id(UUID())
}
#if os(iOS)
.listStyle(.insetGrouped)
@ -351,7 +351,7 @@ struct SearchView: View {
}
.contextMenu {
removeButton(item)
removeAllButton
#if os(tvOS)
Button("Cancel", role: .cancel) {}
#endif
@ -367,13 +367,24 @@ struct SearchView: View {
}
}
private var removeAllButton: some View {
private var clearHistoryButton: some View {
Button {
navigation.presentAlert(
Alert(
title: Text("Are you sure you want to clear search history?"),
message: Text("This cannot be reverted"),
primaryButton: .destructive(Text("Clear")) {
recents.clear()
recentsChanged.toggle()
},
secondaryButton: .cancel()
)
)
} label: {
Label("Remove All", systemImage: "trash.fill")
Label("Clear Search History...", systemImage: "trash.fill")
}
.labelStyle(.titleOnly)
.foregroundColor(Color("AppRedColor"))
}
private var searchFiltersActive: Bool {