Fix clear history, add clear cache

This commit is contained in:
Arkadiusz Fal 2022-11-10 21:46:37 +01:00
parent 4d94126abd
commit 4a26ef2839
2 changed files with 24 additions and 19 deletions

View File

@ -22,4 +22,9 @@ struct CacheModel {
let jsonTransformer = Transformer<JSON>(toData: toData, fromData: fromData)
videoStorage = try? Storage<Video.ID, JSON>(diskConfig: videoStorageConfig, memoryConfig: videoStorageMemoryConfig, transformer: jsonTransformer)
}
func removeAll() {
try? videoStorage?.removeAll()
try? urlBookmarksStorage?.removeAll()
}
}

View File

@ -4,9 +4,8 @@ import SwiftUI
struct HistorySettings: View {
static let watchedThresholds = [50, 60, 70, 80, 90, 95, 100]
@State private var presentingClearHistoryConfirmation = false
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<SettingsModel> private var settings
@Default(.saveRecents) private var saveRecents
@Default(.saveLastPlayed) private var saveLastPlayed
@ -143,25 +142,26 @@ struct HistorySettings: View {
}
private var clearHistoryButton: some View {
Button("Clear History") {
presentingClearHistoryConfirmation = true
}
.alert(isPresented: $presentingClearHistoryConfirmation) {
Alert(
title: Text(
"Are you sure you want to clear history of watched videos?"
),
message: Text(
"This cannot be reverted. You might need to switch between views or restart the app to see changes."
),
primaryButton: .destructive(Text("Clear All")) {
player.removeAllWatches()
presentingClearHistoryConfirmation = false
},
secondaryButton: .cancel()
Button {
settings.presentAlert(
Alert(
title: Text(
"Are you sure you want to clear history of watched videos?"
),
message: Text(
"This cannot be reverted. You might need to switch between views or restart the app to see changes."
),
primaryButton: .destructive(Text("Clear All")) {
player.removeAllWatches()
CacheModel.shared.removeAll()
},
secondaryButton: .cancel()
)
)
} label: {
Text("Clear History")
.foregroundColor(.red)
}
.foregroundColor(.red)
}
}