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) let jsonTransformer = Transformer<JSON>(toData: toData, fromData: fromData)
videoStorage = try? Storage<Video.ID, JSON>(diskConfig: videoStorageConfig, memoryConfig: videoStorageMemoryConfig, transformer: jsonTransformer) 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 { struct HistorySettings: View {
static let watchedThresholds = [50, 60, 70, 80, 90, 95, 100] static let watchedThresholds = [50, 60, 70, 80, 90, 95, 100]
@State private var presentingClearHistoryConfirmation = false
@EnvironmentObject<PlayerModel> private var player @EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<SettingsModel> private var settings
@Default(.saveRecents) private var saveRecents @Default(.saveRecents) private var saveRecents
@Default(.saveLastPlayed) private var saveLastPlayed @Default(.saveLastPlayed) private var saveLastPlayed
@ -143,25 +142,26 @@ struct HistorySettings: View {
} }
private var clearHistoryButton: some View { private var clearHistoryButton: some View {
Button("Clear History") { Button {
presentingClearHistoryConfirmation = true settings.presentAlert(
} Alert(
.alert(isPresented: $presentingClearHistoryConfirmation) { title: Text(
Alert( "Are you sure you want to clear history of watched videos?"
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."
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()
primaryButton: .destructive(Text("Clear All")) { CacheModel.shared.removeAll()
player.removeAllWatches() },
presentingClearHistoryConfirmation = false secondaryButton: .cancel()
}, )
secondaryButton: .cancel()
) )
} label: {
Text("Clear History")
.foregroundColor(.red)
} }
.foregroundColor(.red)
} }
} }