@using LANCommander.Client.Models
@inject LibraryService LibraryService
@if (Groups.Count > 1)
{
foreach (var group in Groups.OrderByTitle(g => g))
{
@context.Name
}
}
else
{
}
@code {
[Parameter] public Guid? SelectedItem { get; set; }
[Parameter] public EventCallback OnItemSelected { get; set; }
List Groups = new List();
protected override void OnInitialized()
{
LibraryService.OnLibraryChanged += UpdateGroups;
UpdateGroups();
}
string GetItemClasses(LibraryItem item)
{
HashSet classes = new HashSet();
if (item.State == LibraryItemState.Installed)
classes.Add("installed");
if (SelectedItem == item.Key)
classes.Add("selected");
return String.Join(" ", classes);
}
async Task SelectItem(LibraryItem item)
{
if (OnItemSelected.HasDelegate)
await OnItemSelected.InvokeAsync(item.Key);
}
void UpdateGroups()
{
Groups = LibraryService.LibraryItems.SelectMany(i => i.Groups).Distinct().ToList();
if (LibraryService.LibraryItems.Any(i => i.Groups == null || i.Groups.Length == 0))
Groups.Add("Uncategorized");
StateHasChanged();
}
}