mirror of
https://github.com/yattee/yattee.git
synced 2025-10-11 01:48:12 +00:00
HomeView: Changes to Favourites and History Widget
The History Widget in the Home View was hard-coded to 10 items. Now it uses the limit set in the settings. The items weren't immediate updated when the limit was changed. List Views had a hard-coded limit of 10 items. Now they use the limit supplied in the parameter.
This commit is contained in:
@@ -1,19 +1,14 @@
|
||||
import SwiftUI
|
||||
|
||||
struct HistoryView: View {
|
||||
var limit = 10
|
||||
var limit: Int
|
||||
|
||||
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
||||
var watches: FetchedResults<Watch>
|
||||
|
||||
@ObservedObject private var player = PlayerModel.shared
|
||||
|
||||
@State private var visibleWatches = [Watch]()
|
||||
|
||||
init(limit: Int = 10) {
|
||||
self.limit = limit
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
LazyVStack {
|
||||
if visibleWatches.isEmpty {
|
||||
@@ -38,10 +33,14 @@ struct HistoryView: View {
|
||||
func reloadVisibleWatches() {
|
||||
visibleWatches = Array(watches.filter { $0.videoID != player.currentVideo?.videoID }.prefix(limit))
|
||||
}
|
||||
|
||||
init(limit: Int = 10) {
|
||||
self.limit = limit
|
||||
}
|
||||
}
|
||||
|
||||
struct HistoryView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
HistoryView()
|
||||
HistoryView(limit: 10)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user