Merge nowplaying-card-reactivity into dev (NowPlaying card now re-renders on track change)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
@using DeepDrftPublic.Client.Services
|
@using DeepDrftPublic.Client.Services
|
||||||
|
@implements IDisposable
|
||||||
<div class="now-playing">
|
<div class="now-playing">
|
||||||
<div class="np-label"><span class="np-dot"></span>Now Playing</div>
|
<div class="np-label"><span class="np-dot"></span>Now Playing</div>
|
||||||
<div class="np-title">@(Player?.CurrentTrack?.TrackName ?? "Nothing playing")</div>
|
<div class="np-title">@(Player?.CurrentTrack?.TrackName ?? "Nothing playing")</div>
|
||||||
@@ -12,4 +13,29 @@
|
|||||||
|
|
||||||
@code {
|
@code {
|
||||||
[CascadingParameter] public IStreamingPlayerService? Player { get; set; }
|
[CascadingParameter] public IStreamingPlayerService? Player { get; set; }
|
||||||
}
|
|
||||||
|
private IStreamingPlayerService? _subscribedPlayer;
|
||||||
|
|
||||||
|
protected override void OnParametersSet()
|
||||||
|
{
|
||||||
|
if (Player != null && !ReferenceEquals(Player, _subscribedPlayer))
|
||||||
|
{
|
||||||
|
if (_subscribedPlayer != null)
|
||||||
|
_subscribedPlayer.StateChanged -= OnPlayerStateChanged;
|
||||||
|
|
||||||
|
Player.StateChanged += OnPlayerStateChanged;
|
||||||
|
_subscribedPlayer = Player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPlayerStateChanged() => InvokeAsync(StateHasChanged);
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (_subscribedPlayer != null)
|
||||||
|
{
|
||||||
|
_subscribedPlayer.StateChanged -= OnPlayerStateChanged;
|
||||||
|
_subscribedPlayer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user