mirror of
				https://github.com/yattee/yattee.git
				synced 2025-10-31 04:31:54 +00:00 
			
		
		
		
	Add clear history button to home
This commit is contained in:
		| @@ -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) | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Arkadiusz Fal
					Arkadiusz Fal