The library list has been changed to supports instances where groups (collections for now) may not be used. This flattens the list of games. Groupings are also now sorted by name when used. Implements #77
79 lines
No EOL
2.6 KiB
Text
79 lines
No EOL
2.6 KiB
Text
@using LANCommander.Client.Models
|
|
@inject LibraryService LibraryService
|
|
|
|
<div class="library-list">
|
|
<Collapse>
|
|
@if (Groups.Any())
|
|
{
|
|
foreach (var group in Groups.OrderByTitle(g => g))
|
|
{
|
|
<Panel Header="@group" Key="@group">
|
|
<AntList DataSource="@(LibraryService.LibraryItems.Where(i => i.Groups.Contains(group) || (group == "Uncategorized" && !i.Groups.Any())))" TItem="LibraryItem" Class="ant-list-clickable" Size="small">
|
|
<ListItem OnClick='() => SelectItem(context)' Class="@GetItemClasses(context)">
|
|
<div class="library-list-icon">
|
|
<MediaImage Id="@context.IconId" />
|
|
</div>
|
|
<span>@context.Name</span>
|
|
</ListItem>
|
|
</AntList>
|
|
</Panel>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<Panel Class="no-header">
|
|
<AntList DataSource="LibraryService.LibraryItems" TItem="LibraryItem" Class="ant-list-clickable" Size="small">
|
|
<ListItem OnClick='() => SelectItem(context)' Class="@GetItemClasses(context)">
|
|
<div class="library-list-icon">
|
|
<MediaImage Id="@context.IconId" />
|
|
</div>
|
|
<span>@context.Name</span>
|
|
</ListItem>
|
|
</AntList>
|
|
</Panel>
|
|
}
|
|
</Collapse>
|
|
</div>
|
|
|
|
@code {
|
|
[Parameter] public Guid? SelectedItem { get; set; }
|
|
[Parameter] public EventCallback<Guid> OnItemSelected { get; set; }
|
|
|
|
List<string> Groups = new List<string>();
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
LibraryService.OnLibraryChanged += UpdateGroups;
|
|
|
|
UpdateGroups();
|
|
}
|
|
|
|
string GetItemClasses(LibraryItem item)
|
|
{
|
|
HashSet<string> classes = new HashSet<string>();
|
|
|
|
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();
|
|
}
|
|
} |