adding now playing card

This commit is contained in:
Andy Pack 2023-01-25 22:22:05 +00:00
parent 8501c2ca7e
commit f887414a8d
Signed by: sarsoo
GPG Key ID: A55BA3536A5E0ED7
5 changed files with 92 additions and 1 deletions

View File

@ -10,6 +10,7 @@
}*@ }*@
<NowPlayingCard Track="@nowCache.LastPlaying?.Track" Episode="@nowCache.LastPlaying?.Episode" /> <NowPlayingCard Track="@nowCache.LastPlaying?.Track" Episode="@nowCache.LastPlaying?.Episode" />
<PlayCountCard Track="@nowCache.LastPlaying?.Track" Count="@nowCache.LastPlayCount" Username="@nowCache.LastPlayCount?.Username" />
@code { @code {

View File

@ -0,0 +1,15 @@
@if (!string.IsNullOrWhiteSpace(Link))
{
<a href="@Link" target="_blank" class="lastfm-logo">
<img src="/last_fm.png">
</a>
}
else
{
<img src="/last_fm.png" class="lastfm-logo">
}
@code {
[Parameter]
public string Link { get; set; }
}

View File

@ -16,7 +16,7 @@
</div> </div>
<div class="nav-item px-3"> <div class="nav-item px-3">
<NavLink class="nav-link" href="now"> <NavLink class="nav-link" href="now">
<span class="oi oi-plus" aria-hidden="true"></span> Now <span class="oi oi-dashboard" aria-hidden="true"></span> Now
</NavLink> </NavLink>
</div> </div>
<div class="nav-item px-3"> <div class="nav-item px-3">

View File

@ -0,0 +1,74 @@
@using SpotifyAPI.Web;
@if (Count is not null) {
<div class="card info-card">
@if (Count.Track is not null) {
<h5>
<a href="@trackLink" class="subtle-link" style="color: #7a99c2">
Track: @Count.Track
@if (trackPercent >= 0.01)
{
<small>(@(trackPercentDisplay)%)</small>
}
</a>
</h5>
}
@if (Count.Album is not null)
{
<h5>
<a href="@albumLink" class="subtle-link" style="color: #a34c77">
Album: @Count.Album
@if (albumPercent >= 0.01)
{
<small>(@(albumPercentDisplay)%)</small>
}
</a>
</h5>
}
@if (Count.Artist is not null)
{
<h5>
<a href="@artistLink" class="subtle-link" style="color: #598556">
Artist: @Count.Artist
@if (artistPercent >= 0.1)
{
<small>(@(artistPercentDisplay)%)</small>
}
</a>
</h5>
}
@if (Count.User is not null)
{
<h5>
<a href="@userLink" class="subtle-link">
User: @Count.User
</a>
</h5>
}
<LastfmLogo Link="@userLink" />
</div>
}
@code {
[Parameter]
public FullTrack Track { get; set; }
[Parameter]
public PlayCount Count { get; set; }
[Parameter]
public string Username { get; set; }
private string trackLink => $"https://www.last.fm/user/{Username}/library/music/{Track.Artists.First().Name}/_/${Track.Name}";
private string albumLink => $"https://www.last.fm/user/{Username}/library/music/{Track.Album.Artists.First().Name}/${Track.Album.Name}";
private string artistLink => $"https://www.last.fm/user/{Username}/library/music/{Track.Artists.First().Name}";
private string userLink => $"https://www.last.fm/user/{Username}";
private float trackPercent => Count.Track.HasValue && Count.User.HasValue ? Count.Track.Value * 100 / Count.User.Value : 0f;
private float albumPercent => Count.Album.HasValue && Count.User.HasValue ? Count.Album.Value * 100 / Count.User.Value : 0f;
private float artistPercent => Count.Artist.HasValue && Count.User.HasValue ? Count.Artist.Value * 100 / Count.User.Value : 0f ;
private string trackPercentDisplay => string.Format("{0:#,##0.##}", trackPercent);
private string albumPercentDisplay => string.Format("{0:#,##0.##}", albumPercent);
private string artistPercentDisplay => string.Format("{0:#,##0.##}", artistPercent);
}

View File

@ -5,6 +5,7 @@
@using Microsoft.AspNetCore.Components.Web @using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization @using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop @using Microsoft.JSInterop
@using Selector
@using Selector.MAUI @using Selector.MAUI
@using Selector.MAUI.Shared @using Selector.MAUI.Shared
@using Selector.MAUI.Models @using Selector.MAUI.Models