mirror of
https://github.com/yattee/yattee.git
synced 2024-12-24 14:33:40 +00:00
Improve queue details loading
This commit is contained in:
parent
05f1c0b6c8
commit
281c88df45
@ -179,10 +179,6 @@ extension PlayerModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func restoreQueue() {
|
func restoreQueue() {
|
||||||
guard !accounts.current.isNil else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var restoredQueue = [PlayerQueueItem?]()
|
var restoredQueue = [PlayerQueueItem?]()
|
||||||
|
|
||||||
if let lastPlayed = Defaults[.lastPlayed],
|
if let lastPlayed = Defaults[.lastPlayed],
|
||||||
@ -194,13 +190,15 @@ extension PlayerModel {
|
|||||||
|
|
||||||
restoredQueue.append(contentsOf: Defaults[.queue])
|
restoredQueue.append(contentsOf: Defaults[.queue])
|
||||||
queue = restoredQueue.compactMap { $0 }
|
queue = restoredQueue.compactMap { $0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadQueueVideoDetails(_ item: PlayerQueueItem) {
|
||||||
|
guard !accounts.current.isNil, !item.hasDetailsLoaded else { return }
|
||||||
|
|
||||||
queue.forEach { item in
|
|
||||||
accounts.api.loadDetails(item) { newItem in
|
accounts.api.loadDetails(item) { newItem in
|
||||||
if let index = self.queue.firstIndex(where: { $0.id == item.id }) {
|
if let index = self.queue.firstIndex(where: { $0.id == item.id }) {
|
||||||
self.queue[index] = newItem
|
self.queue[index] = newItem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,10 @@ struct PlayerQueueItem: Hashable, Identifiable, Defaults.Serializable {
|
|||||||
return duration - seconds <= 10
|
return duration - seconds <= 10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var hasDetailsLoaded: Bool {
|
||||||
|
!video.isNil
|
||||||
|
}
|
||||||
|
|
||||||
func hash(into hasher: inout Hasher) {
|
func hash(into hasher: inout Hasher) {
|
||||||
hasher.combine(id)
|
hasher.combine(id)
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ struct VideoDetails: View {
|
|||||||
.font(.system(size: 10).bold())
|
.font(.system(size: 10).bold())
|
||||||
.overlay(
|
.overlay(
|
||||||
RoundedRectangle(cornerRadius: 2)
|
RoundedRectangle(cornerRadius: 2)
|
||||||
.stroke(active ? Color.accentColor : .gray, lineWidth: 2)
|
.stroke(active ? Color.accentColor : .gray, lineWidth: 1.2)
|
||||||
.foregroundColor(.clear)
|
.foregroundColor(.clear)
|
||||||
)
|
)
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
|
@ -24,14 +24,14 @@ struct VideoBanner: View {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
Text(video?.title ?? "Unknown title")
|
Text(video?.title ?? "Loading...")
|
||||||
.truncationMode(.middle)
|
.truncationMode(.middle)
|
||||||
.lineLimit(2)
|
.lineLimit(2)
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
.frame(alignment: .leading)
|
.frame(alignment: .leading)
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Text(video?.author ?? "Unknown author")
|
Text(video?.author ?? "")
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
@ -68,6 +68,9 @@ struct NowPlayingView: View {
|
|||||||
} label: {
|
} label: {
|
||||||
VideoBanner(video: item.video)
|
VideoBanner(video: item.video)
|
||||||
}
|
}
|
||||||
|
.onAppear {
|
||||||
|
player.loadQueueVideoDetails(item)
|
||||||
|
}
|
||||||
.contextMenu {
|
.contextMenu {
|
||||||
Button("Remove", role: .destructive) {
|
Button("Remove", role: .destructive) {
|
||||||
player.remove(item)
|
player.remove(item)
|
||||||
|
Loading…
Reference in New Issue
Block a user