LANCommander/LANCommander.Launcher/UI/Library/Components/LibraryList.razor
Pat Hartl 9ba9887eb1 Rename project files, namespaces, artifacts
Client has been renamed to launcher, and thus namespaces and artifact names had to change. The server project has also had some artifacts renamed in order to create a more clear separation of builds. This will break auto-updates before v0.9.0.
2024-08-04 17:53:19 -05:00

69 lines
No EOL
2.3 KiB
Text

@using LANCommander.Launcher.Models
@inject LibraryService LibraryService
@inject ImportService ImportService
@inject MessageBusService MessageBusService
<div class="library-list">
<Collapse>
@if (Groups.Count > 1)
{
foreach (var group in Groups.OrderByTitle(g => g))
{
<Panel Header="@group" Key="@group">
<AntList DataSource="@(LibraryItems.Where(i => i.Groups.Contains(group) || (group == "Uncategorized" && !i.Groups.Any())))" TItem="LibraryItem" Class="ant-list-clickable" Size="small">
<LibraryListItem Model="@context" OnClick="() => SelectItem(context)" @bind-SelectedItem="SelectedItem" />
</AntList>
</Panel>
}
}
else
{
<Panel Class="no-header">
<AntList DataSource="LibraryService.LibraryItems" TItem="LibraryItem" Class="ant-list-clickable" Size="small">
<LibraryListItem Model="@context" OnClick="() => SelectItem(context)" @bind-SelectedItem="SelectedItem" />
</AntList>
</Panel>
}
</Collapse>
</div>
@code {
[Parameter] public Guid? SelectedItem { get; set; }
[Parameter] public EventCallback<Guid> OnItemSelected { get; set; }
List<string> Groups = new List<string>();
IEnumerable<LibraryItem> 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<LibraryItem> 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;
}
}