Improve queue details loading

This commit is contained in:
Arkadiusz Fal 2022-06-26 13:12:32 +02:00
parent 0f48a14e96
commit fe94d35af0
5 changed files with 17 additions and 12 deletions

View File

@ -179,10 +179,6 @@ extension PlayerModel {
}
func restoreQueue() {
guard !accounts.current.isNil else {
return
}
var restoredQueue = [PlayerQueueItem?]()
if let lastPlayed = Defaults[.lastPlayed],
@ -194,12 +190,14 @@ extension PlayerModel {
restoredQueue.append(contentsOf: Defaults[.queue])
queue = restoredQueue.compactMap { $0 }
}
queue.forEach { item in
accounts.api.loadDetails(item) { newItem in
if let index = self.queue.firstIndex(where: { $0.id == item.id }) {
self.queue[index] = newItem
}
func loadQueueVideoDetails(_ item: PlayerQueueItem) {
guard !accounts.current.isNil, !item.hasDetailsLoaded else { return }
accounts.api.loadDetails(item) { newItem in
if let index = self.queue.firstIndex(where: { $0.id == item.id }) {
self.queue[index] = newItem
}
}
}

View File

@ -39,6 +39,10 @@ struct PlayerQueueItem: Hashable, Identifiable, Defaults.Serializable {
return duration - seconds <= 10
}
var hasDetailsLoaded: Bool {
!video.isNil
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}

View File

@ -159,7 +159,7 @@ struct VideoDetails: View {
.font(.system(size: 10).bold())
.overlay(
RoundedRectangle(cornerRadius: 2)
.stroke(active ? Color.accentColor : .gray, lineWidth: 2)
.stroke(active ? Color.accentColor : .gray, lineWidth: 1.2)
.foregroundColor(.clear)
)
.frame(maxWidth: .infinity)

View File

@ -24,14 +24,14 @@ struct VideoBanner: View {
#endif
}
VStack(alignment: .leading, spacing: 4) {
Text(video?.title ?? "Unknown title")
Text(video?.title ?? "Loading...")
.truncationMode(.middle)
.lineLimit(2)
.font(.headline)
.frame(alignment: .leading)
HStack {
Text(video?.author ?? "Unknown author")
Text(video?.author ?? "")
.lineLimit(1)
Spacer()

View File

@ -68,6 +68,9 @@ struct NowPlayingView: View {
} label: {
VideoBanner(video: item.video)
}
.onAppear {
player.loadQueueVideoDetails(item)
}
.contextMenu {
Button("Remove", role: .destructive) {
player.remove(item)