Add clear history button (fix #205)

This commit is contained in:
Arkadiusz Fal 2022-08-21 17:39:06 +02:00
parent 4ea44a5267
commit e139d98bd7
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 {
recents.clear()
recentsChanged.toggle()
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 {