Action history is logged and displayed to the user's library. These are triggered whenever the magnet choice sheet is displayed. Also redo alerts and action sheets to avoid deprecation notices for >iOS 14. These will be removed when iOS 14 support is dropped. There was also a problem with sheet presentation not working after a sheet was dismissed. Disable the appropriate view when a sheet is being presented. Signed-off-by: kingbri <bdashore3@proton.me>
54 lines
1.5 KiB
Swift
54 lines
1.5 KiB
Swift
//
|
|
// HistoryActionsView.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 9/7/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct HistoryActionsView: View {
|
|
@EnvironmentObject var toastModel: ToastViewModel
|
|
|
|
@State private var showActionSheet = false
|
|
|
|
var body: some View {
|
|
Button("Clear") {
|
|
showActionSheet.toggle()
|
|
}
|
|
.dynamicAccentColor(.red)
|
|
.dynamicActionSheet(
|
|
isPresented: $showActionSheet,
|
|
title: "Clear watch history",
|
|
message: "This is an irreversible action!",
|
|
buttons: [
|
|
AlertButton("Past day", role: .destructive) {
|
|
deleteHistory(.day)
|
|
},
|
|
AlertButton("Past week", role: .destructive) {
|
|
deleteHistory(.week)
|
|
},
|
|
AlertButton("Past month", role: .destructive) {
|
|
deleteHistory(.month)
|
|
},
|
|
AlertButton("All time", role: .destructive) {
|
|
deleteHistory(.allTime)
|
|
}
|
|
]
|
|
)
|
|
}
|
|
|
|
func deleteHistory(_ deleteRange: HistoryDeleteRange) {
|
|
do {
|
|
try PersistenceController.shared.batchDeleteHistory(range: deleteRange)
|
|
} catch {
|
|
toastModel.updateToastDescription("History delete error: \(error)")
|
|
}
|
|
}
|
|
}
|
|
|
|
struct HistoryActionsView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
HistoryActionsView()
|
|
}
|
|
}
|