@using LANCommander.Launcher.Models
@inject LibraryService LibraryService
@inject ImportService ImportService
@inject MessageBusService MessageBusService
@if (Groups.Count > 1)
{
foreach (var group in Groups.OrderByTitle(g => g))
{
}
}
else
{
}
@code {
[Parameter] public Guid? SelectedItem { get; set; }
[Parameter] public EventCallback OnItemSelected { get; set; }
List Groups = new List();
IEnumerable LibraryItems;
protected override void OnInitialized()
{
LibraryService.OnLibraryChanged += UpdateGroups;
LibraryService.OnLibraryItemsFiltered += UpdateGroups;
UpdateGroups(LibraryService.LibraryItems);
}
async Task SelectItem(LibraryItem item)
{
if (OnItemSelected.HasDelegate)
await OnItemSelected.InvokeAsync(item.Key);
}
async Task UpdateGroups(IEnumerable items)
{
LibraryItems = items;
Groups = LibraryItems.SelectMany(i => i.Groups).Distinct().ToList();
if (LibraryItems.Any(i => i.Groups == null || i.Groups.Length == 0))
Groups.Add("Uncategorized");
await InvokeAsync(StateHasChanged);
}
public void Dispose()
{
LibraryService.OnLibraryChanged -= UpdateGroups;
LibraryService.OnLibraryItemsFiltered -= UpdateGroups;
ImportService.OnImportComplete -= LibraryService.LibraryChanged;
}
}