Skip to content

Commit

Permalink
Added icon to map if it's in a playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisvHest committed Aug 25, 2024
1 parent 1dfc2ae commit ca15609
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions MapMaven.Core/Services/Interfaces/IPlaylistService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IPlaylistService
IObservable<IEnumerable<Playlist>> Playlists { get; }
BehaviorSubject<Playlist> SelectedPlaylist { get; }
IObservable<PlaylistTree<Playlist>> PlaylistTree { get; }
IObservable<Dictionary<string, Playlist[]>> MapsInPlaylistsByHash { get; }

Task<Playlist> AddLivePlaylist(EditLivePlaylistModel editPlaylistModel);
Task AddMapsToPlaylist(IEnumerable<Map> maps, Playlist playlist, bool loadPlaylists = true);
Expand Down
15 changes: 14 additions & 1 deletion MapMaven.Core/Services/PlaylistService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using MapMaven.Core.Models.LivePlaylists;
using MapMaven.Core.Models.Data;
using MapMaven.Core.Services.Interfaces;
using MapMaven.Core.Extensions;
using MapMaven.Core.Models.Data.Playlists;
using BeatSaberPlaylistsLib;
using MapMaven.Core.Models;
Expand All @@ -26,6 +25,10 @@ public class PlaylistService : IPlaylistService

public IObservable<PlaylistTree<Playlist>> PlaylistTree { get; private set; }
public IObservable<IEnumerable<Playlist>> Playlists { get; private set; }

public readonly BehaviorSubject<Dictionary<string, Playlist[]>> _mapsInPlaylistsByHash = new(new());
public IObservable<Dictionary<string, Playlist[]>> MapsInPlaylistsByHash => _mapsInPlaylistsByHash;

public BehaviorSubject<Playlist?> SelectedPlaylist { get; private set; } = new(null);

private readonly BehaviorSubject<bool> _creatingPlaylist = new(false);
Expand Down Expand Up @@ -60,6 +63,16 @@ public PlaylistService(IBeatSaberDataService beatSaberDataService, BeatSaberFile
return x.playlists.FirstOrDefault(p => p.PlaylistFilePath == x.selectedPlaylistFilePath);
})
.Subscribe(SelectedPlaylist.OnNext); // Subscribing here because of weird behavior with multiple subscriptions triggering multiple reruns of this observable.

Playlists.Subscribe(playlists =>
{
var mapsInPlaylistsByHash = playlists.SelectMany(p => p.Maps.Select(m => new { Map = m, Playlist = p }))
.Where(x => x.Map.Hash is not null)
.GroupBy(x => x.Map.Hash)
.ToDictionary(g => g.Key, g => g.Select(x => x.Playlist).Distinct().ToArray());

_mapsInPlaylistsByHash.OnNext(mapsInPlaylistsByHash);
});
}

private PlaylistFolder<Playlist> MapIPlaylistsToPlaylistsInFolder(PlaylistFolder<IPlaylist> folder)
Expand Down
7 changes: 5 additions & 2 deletions MapMaven/Components/Maps/MapBrowserRow.razor
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
}
</CellTemplate>
</TemplateColumn>
<TemplateColumn T="Map" Sortable="false" CellClass="pl-0" CellStyle="width: 50px; position: relative;">
<TemplateColumn T="Map" Sortable="false" CellClass="px-0" CellStyle="width: 50px; position: relative;">
<CellTemplate>
<div>
<div class="d-flex">
<div class="d-flex flex-column">
<MudTooltip Text="Play song preview" ShowOnFocus="false">
<SongPlaybackButton Map="context.Item"></SongPlaybackButton>
Expand All @@ -30,6 +30,9 @@
<MudIconButton Icon="@Icons.Material.Filled.Info" Class="pb-0 pt-1 no-hover-background" Variant="Variant.Text" Size="Size.Medium" OnClick="() => OpenDetails(context.Item)" />
</MudTooltip>
</div>
<div class="d-flex flex-column justify-center">
<MapInPlaylistIndicator MapHash="@context.Item.Hash"></MapInPlaylistIndicator>
</div>
</div>
</CellTemplate>
</TemplateColumn>
Expand Down
31 changes: 31 additions & 0 deletions MapMaven/Components/Maps/MapInPlaylistIndicator.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@inherits ReactiveComponent

@if (PlaylistsContainingMapHash.Any())
{
var tooltip = $"In playlists: {string.Join(", ", PlaylistsContainingMapHash.Select(p => p.Title))}";

<MudTooltip Text="@tooltip">
<MudIcon Icon="@Icons.Material.Filled.PlaylistAddCheckCircle" Style="opacity: 0.4" />
</MudTooltip>
}

@code {
[Inject]
IPlaylistService PlaylistService { get; set; }

[Parameter]
public string MapHash { get; set; }

Playlist[] PlaylistsContainingMapHash = [];

protected override void OnInitialized()
{
SubscribeAndBind(PlaylistService.MapsInPlaylistsByHash, mapsInPlaylistsByHash =>
{
if (!mapsInPlaylistsByHash.ContainsKey(MapHash))
return;

PlaylistsContainingMapHash = mapsInPlaylistsByHash[MapHash];
});
}
}

0 comments on commit ca15609

Please sign in to comment.