Selector/Selector.MAUI/Pages/Now.razor

65 lines
1.5 KiB
Plaintext
Raw Normal View History

@page "/now"
@using Selector.SignalR;
2023-01-23 18:11:37 +00:00
@implements IDisposable
<h1>Now</h1>
2023-01-23 18:11:37 +00:00
@*@if (nowCache?.LastPlaying?.Track is not null)
{
<p role="status">@nowCache.LastPlaying.Track.Name</p>
2023-01-23 18:11:37 +00:00
}*@
<NowPlayingCard Track="@nowCache.LastPlaying?.Track" Episode="@nowCache.LastPlaying?.Episode" />
2023-01-25 22:22:05 +00:00
<PlayCountCard Track="@nowCache.LastPlaying?.Track" Count="@nowCache.LastPlayCount" Username="@nowCache.LastPlayCount?.Username" />
@code {
[Inject]
private NowHubCache nowCache { get; set; }
2023-01-23 18:11:37 +00:00
protected async override Task OnInitializedAsync()
{
nowCache.NewNowPlaying += OnNewPlaying;
nowCache.NewCard += OnNewCard;
nowCache.NewPlayCount += OnNewPlayCount;
nowCache.NewAudioFeature += OnNewAudioFeature;
}
private void OnNewPlaying(object sender, EventArgs args)
{
Update();
}
private void OnNewCard(object sender, EventArgs args)
{
Update();
}
private void OnNewPlayCount(object sender, EventArgs args)
{
Update();
}
private void OnNewAudioFeature(object sender, EventArgs args)
{
Update();
}
public void Update()
{
Application.Current.Dispatcher.Dispatch(() =>
{
StateHasChanged();
});
}
public void Dispose()
{
nowCache.NewNowPlaying -= OnNewPlaying;
nowCache.NewCard -= OnNewCard;
nowCache.NewPlayCount -= OnNewPlayCount;
nowCache.NewAudioFeature -= OnNewAudioFeature;
}
}