mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 22:00:31 +05:30
Add clear history button to home
This commit is contained in:
parent
8727fb1e30
commit
78ff495927
@ -94,6 +94,11 @@ extension PlayerModel {
|
||||
}
|
||||
}
|
||||
|
||||
func removeHistory() {
|
||||
removeAllWatches()
|
||||
CacheModel.shared.removeAll()
|
||||
}
|
||||
|
||||
func removeWatch(_ watch: Watch) {
|
||||
context.delete(watch)
|
||||
try? context.save()
|
||||
|
@ -3,13 +3,13 @@ import SwiftUI
|
||||
struct HistoryView: View {
|
||||
static let detailsPreloadLimit = 50
|
||||
|
||||
var limit = 10
|
||||
|
||||
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
||||
var watches: FetchedResults<Watch>
|
||||
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
|
||||
var limit = 10
|
||||
|
||||
var body: some View {
|
||||
LazyVStack {
|
||||
if visibleWatches.isEmpty {
|
||||
|
@ -12,6 +12,10 @@ struct HomeView: View {
|
||||
|
||||
@State private var favoritesChanged = false
|
||||
|
||||
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
||||
var watches: FetchedResults<Watch>
|
||||
@State private var historyID = UUID()
|
||||
|
||||
var favoritesObserver: Any?
|
||||
|
||||
#if !os(tvOS)
|
||||
@ -79,27 +83,45 @@ struct HomeView: View {
|
||||
#if os(macOS)
|
||||
.workaroundForVerticalScrollingBug()
|
||||
#endif
|
||||
#if os(iOS)
|
||||
.padding(.top, item == first && RefreshControl.navigationBarTitleDisplayMode == .inline ? 10 : 0)
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if homeHistoryItems > 0 {
|
||||
VStack {
|
||||
Text("History")
|
||||
HStack {
|
||||
Text("History")
|
||||
Spacer()
|
||||
Button {
|
||||
navigation.presentAlert(
|
||||
Alert(
|
||||
title: Text("Are you sure you want to clear history of watched videos?"),
|
||||
message: Text("It cannot be reverted"),
|
||||
primaryButton: .destructive(Text("Clear All")) {
|
||||
PlayerModel.shared.removeHistory()
|
||||
historyID = UUID()
|
||||
},
|
||||
secondaryButton: .cancel()
|
||||
)
|
||||
)
|
||||
} label: {
|
||||
Label("Clear History", systemImage: "trash")
|
||||
.font(.headline)
|
||||
.labelStyle(.iconOnly)
|
||||
}
|
||||
}
|
||||
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal, 40)
|
||||
.padding(.horizontal, 40)
|
||||
#else
|
||||
.padding(.horizontal, 15)
|
||||
.padding(.horizontal, 15)
|
||||
#endif
|
||||
.font(.title3.bold())
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.foregroundColor(.secondary)
|
||||
.font(.title3.bold())
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
HistoryView(limit: homeHistoryItems)
|
||||
.id(historyID)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,9 +29,12 @@ struct PlayerQueueRow: View {
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
guard let video = item.video else {
|
||||
guard let video = item.video else { return }
|
||||
guard video != player.currentVideo else {
|
||||
player.show()
|
||||
return
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
guard !video.localStreamIsDirectory else {
|
||||
if let url = video.localStream?.localURL {
|
||||
|
@ -151,10 +151,7 @@ struct HistorySettings: View {
|
||||
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()
|
||||
},
|
||||
primaryButton: .destructive(Text("Clear All"), action: player.removeHistory),
|
||||
secondaryButton: .cancel()
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user