1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 22:30: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 presentingAlert = true
} }
func presentAlert(_ alert: Alert) {
self.alert = alert
presentingAlert = true
}
func presentShareSheet(_ url: URL) { func presentShareSheet(_ url: URL) {
shareURL = url shareURL = url
presentingShareSheet = true presentingShareSheet = true

View File

@ -221,9 +221,6 @@ struct SearchView: View {
VStack { VStack {
if showRecentQueries { if showRecentQueries {
recentQueries recentQueries
#if os(iOS)
.padding(.bottom, 90)
#endif
} else { } else {
#if os(tvOS) #if os(tvOS)
ScrollView(.vertical, showsIndicators: false) { ScrollView(.vertical, showsIndicators: false) {
@ -299,8 +296,11 @@ struct SearchView: View {
} }
} }
.redrawOn(change: recentsChanged) .redrawOn(change: recentsChanged)
Section(footer: Color.clear.frame(minHeight: 80)) {
clearHistoryButton
}
} }
.id(UUID())
} }
#if os(iOS) #if os(iOS)
.listStyle(.insetGrouped) .listStyle(.insetGrouped)
@ -351,7 +351,7 @@ struct SearchView: View {
} }
.contextMenu { .contextMenu {
removeButton(item) removeButton(item)
removeAllButton
#if os(tvOS) #if os(tvOS)
Button("Cancel", role: .cancel) {} Button("Cancel", role: .cancel) {}
#endif #endif
@ -367,13 +367,24 @@ struct SearchView: View {
} }
} }
private var removeAllButton: some View { private var clearHistoryButton: some View {
Button { 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() recents.clear()
recentsChanged.toggle() recentsChanged.toggle()
},
secondaryButton: .cancel()
)
)
} label: { } label: {
Label("Remove All", systemImage: "trash.fill") Label("Clear Search History...", systemImage: "trash.fill")
} }
.labelStyle(.titleOnly)
.foregroundColor(Color("AppRedColor"))
} }
private var searchFiltersActive: Bool { private var searchFiltersActive: Bool {