fix: liked state not showing until track row disappears/reappears
likedTrackIds loads async after views appear, so isLiked was always false on initial render. Add onChange(of: likedTrackIds) to all track row types and the player bar to re-sync when the set is populated. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -203,6 +203,7 @@ private struct ArtistTrackRow: View {
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture { onPlay() }
|
||||
.onAppear { isLiked = authManager.likedTrackIds.contains(track.id) }
|
||||
.onChange(of: authManager.likedTrackIds) { _, ids in isLiked = ids.contains(track.id) }
|
||||
.popover(isPresented: $showInfo, arrowEdge: .trailing) {
|
||||
TrackInfoView(track: track)
|
||||
}
|
||||
|
||||
@@ -64,6 +64,9 @@ struct ContentView: View {
|
||||
.onChange(of: player.currentTrack?.id) { _, newId in
|
||||
isCurrentTrackLiked = newId.map { authManager.likedTrackIds.contains($0) } ?? false
|
||||
}
|
||||
.onChange(of: authManager.likedTrackIds) { _, ids in
|
||||
isCurrentTrackLiked = player.currentTrack.map { ids.contains($0.id) } ?? false
|
||||
}
|
||||
.onChange(of: deviceManager.remoteState?.updatedAtMs) { _, _ in
|
||||
remoteSeekOverride = nil
|
||||
}
|
||||
|
||||
@@ -172,6 +172,7 @@ private struct PlaylistTrackRow: View {
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture { onPlay() }
|
||||
.onAppear { isLiked = authManager.likedTrackIds.contains(track.id) }
|
||||
.onChange(of: authManager.likedTrackIds) { _, ids in isLiked = ids.contains(track.id) }
|
||||
.popover(isPresented: $showInfo, arrowEdge: .trailing) {
|
||||
TrackInfoView(track: track)
|
||||
}
|
||||
|
||||
@@ -170,6 +170,7 @@ private struct ReleaseTrackRow: View {
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture { onPlay() }
|
||||
.onAppear { isLiked = authManager.likedTrackIds.contains(track.id) }
|
||||
.onChange(of: authManager.likedTrackIds) { _, ids in isLiked = ids.contains(track.id) }
|
||||
.popover(isPresented: $showInfo, arrowEdge: .trailing) {
|
||||
TrackInfoView(track: track)
|
||||
}
|
||||
|
||||
@@ -137,6 +137,7 @@ private struct TrackRowSearch: View {
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture { onPlay() }
|
||||
.onAppear { isLiked = authManager.likedTrackIds.contains(track.id) }
|
||||
.onChange(of: authManager.likedTrackIds) { _, ids in isLiked = ids.contains(track.id) }
|
||||
.popover(isPresented: $showInfo, arrowEdge: .trailing) {
|
||||
TrackInfoView(track: track)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user