96 lines
No EOL
3.2 KiB
Text
96 lines
No EOL
3.2 KiB
Text
@using LANCommander.Launcher.Models
|
|
@using LANCommander.Launcher.Services.Extensions
|
|
@using LANCommander.SDK.Extensions
|
|
@inject LibraryService LibraryService
|
|
@inject ImportService ImportService
|
|
@inject MessageBusService MessageBusService
|
|
@inject NavigationManager NavigationManager
|
|
|
|
<Flex Vertical Class="library-list">
|
|
@if (LibraryService.Items == null || !LibraryService.Items.Any())
|
|
{
|
|
<Empty Simple Description="false">
|
|
<Button Type="ButtonType.Primary" OnClick="@(() => NavigationManager.NavigateTo("/Depot"))">Browse Depot</Button>
|
|
</Empty>
|
|
}
|
|
else
|
|
{
|
|
if (LibraryItems == null || !LibraryItems.Any())
|
|
{
|
|
<Empty Simple Description="@("No Results Found")">
|
|
<Button Type="ButtonType.Primary" OnClick="Filter.ResetFilter">Reset Filter</Button>
|
|
</Empty>
|
|
}
|
|
else
|
|
{
|
|
<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="Models.ListItem" Class="ant-list-clickable" Size="ListSize.Small">
|
|
<LibraryListItem Model="@context" OnClick="() => SelectItem(context)" @bind-SelectedItem="SelectedItem"/>
|
|
</AntList>
|
|
</Panel>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<Panel Class="no-header">
|
|
<AntList DataSource="LibraryItems" TItem="Models.ListItem" Class="ant-list-clickable" Size="ListSize.Small">
|
|
<LibraryListItem Model="@context" OnClick="() => SelectItem(context)" @bind-SelectedItem="SelectedItem"/>
|
|
</AntList>
|
|
</Panel>
|
|
}
|
|
</Collapse>
|
|
}
|
|
|
|
<LibraryItemFilter @ref="Filter" />
|
|
}
|
|
</Flex>
|
|
|
|
@code {
|
|
[Parameter] public Guid? SelectedItem { get; set; }
|
|
[Parameter] public EventCallback<Guid> OnItemSelected { get; set; }
|
|
|
|
List<string> Groups = new();
|
|
IEnumerable<Models.ListItem> LibraryItems;
|
|
LibraryItemFilter Filter;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
LibraryService.OnItemsFiltered += LoadFilteredItems;
|
|
|
|
await LibraryService.RefreshItemsAsync();
|
|
}
|
|
|
|
async Task LoadFilteredItems(IEnumerable<Models.ListItem> libraryItems)
|
|
{
|
|
LibraryItems = libraryItems;
|
|
|
|
await UpdateGroups();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
async Task SelectItem(Models.ListItem item)
|
|
{
|
|
if (OnItemSelected.HasDelegate)
|
|
await OnItemSelected.InvokeAsync(item.Key);
|
|
}
|
|
|
|
async Task UpdateGroups()
|
|
{
|
|
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.OnItemsFiltered -= LoadFilteredItems;
|
|
}
|
|
} |