@page "/now" @using Selector.SignalR; @using System.Linq; @implements IDisposable

Now

@if (nowCache.LastPlayCount?.ArtistCountData?.Count() > 0) {
} @if (nowCache.LastPlayCount?.TrackCountData?.Count() > 3) {
} @if (nowCache.LastPlayCount?.AlbumCountData?.Count() > 3) {
} @if (nowCache.LastPlayCount?.ArtistCountData?.Count() > 3) {
}
@code { class DataItem { public DateTime Date { get; set; } public int Plays { get; set; } } [Inject] private NowHubCache nowCache { get; set; } private bool smooth = true; private bool showDataLabels = false; private double strokeWidth = 5; private DataItem[] artistData { get; set; } private DataItem[] albumData { get; set; } private DataItem[] trackData { get; set; } protected async override Task OnInitializedAsync() { nowCache.NewNowPlaying += OnNewPlaying; nowCache.NewCard += OnNewCard; nowCache.NewPlayCount += OnNewPlayCount; nowCache.NewAudioFeature += OnNewAudioFeature; UpdateData(); } private void OnNewPlaying(object sender, EventArgs args) { Update(); } private void OnNewCard(object sender, EventArgs args) { Update(); } private void OnNewPlayCount(object sender, EventArgs args) { UpdateData(); Update(); } private void UpdateData() { artistData = nowCache.LastPlayCount?.ArtistCountData?.Select(x => new DataItem { Date = x.TimeStamp, Plays = x.Value }).ToArray(); albumData = nowCache.LastPlayCount?.AlbumCountData?.Select(x => new DataItem { Date = x.TimeStamp, Plays = x.Value }).ToArray(); trackData = nowCache.LastPlayCount?.TrackCountData?.Select(x => new DataItem { Date = x.TimeStamp, Plays = x.Value }).ToArray(); } 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; } }