1
0
mirror of https://github.com/yattee/yattee.git synced 2025-04-29 16:30:32 +05:30

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,10 +142,8 @@ struct HistorySettings: View {
} }
private var clearHistoryButton: some View { private var clearHistoryButton: some View {
Button("Clear History") { Button {
presentingClearHistoryConfirmation = true settings.presentAlert(
}
.alert(isPresented: $presentingClearHistoryConfirmation) {
Alert( Alert(
title: Text( title: Text(
"Are you sure you want to clear history of watched videos?" "Are you sure you want to clear history of watched videos?"
@ -156,13 +153,16 @@ struct HistorySettings: View {
), ),
primaryButton: .destructive(Text("Clear All")) { primaryButton: .destructive(Text("Clear All")) {
player.removeAllWatches() player.removeAllWatches()
presentingClearHistoryConfirmation = false CacheModel.shared.removeAll()
}, },
secondaryButton: .cancel() secondaryButton: .cancel()
) )
} )
} label: {
Text("Clear History")
.foregroundColor(.red) .foregroundColor(.red)
} }
}
} }
struct HistorySettings_Previews: PreviewProvider { struct HistorySettings_Previews: PreviewProvider {