LANCommander/LANCommander.Launcher/UI/Pages/Depot/Components/DepotList.razor
Pat Hartl 698a7523b6 Code cleanup
- Move all Launcher components to LANCommander.Launcher.UI namespace
- Move all SCSS files next to components (when possible)
- Refactor styles that control overflow of content into titlebar to MainWindow only
- Remove use in launcher UI of SDK.Client
2025-12-31 20:01:04 -06:00

88 lines
2.6 KiB
Text

@namespace LANCommander.Launcher.UI
@inject DepotService DepotService
@inject LocalizationService LocalizationService
<Spin Spinning="!Loaded" WrapperClassName="depot-list-spinner">
@if (ListItems.Any())
{
<div class="depot-list no-scrollbar">
@if (Groups.Count > 1)
{
@foreach (var group in Groups)
{
<div class="depot-list-group">
<Divider Text="@group" />
<div class="depot-list-group-items">
@foreach (var item in ListItems.Where(i => i.Groups.Contains(group) || (group == "Uncategorized" && i.Groups.Length == 0)))
{
<DepotGameItem Item="item" OnClick="OnItemSelected" />
}
</div>
</div>
}
}
else
{
<div class="depot-list-items">
@foreach (var item in ListItems)
{
<DepotGameItem Item="item" OnClick="OnItemSelected" />
}
</div>
}
</div>
}
else if (DepotService.GetItemCount() > 0)
{
<Result Title="@LocalizationService.GetString("NoResults")" />
}
else if (Loaded)
{
<Result
Status="ResultStatus.Error"
Title="@LocalizationService.GetString("NoResults")"
SubTitle="@LocalizationService.GetString("DepotEmptyOrUnauthorized")" />
}
</Spin>
@code {
[Parameter] public EventCallback<Models.ListItem> OnItemSelected { get; set; }
IEnumerable<Models.ListItem> ListItems { get; set; } = new List<Models.ListItem>();
List<string> Groups = new();
bool Loaded = false;
protected override void OnInitialized()
{
base.OnInitialized();
DepotService.OnItemsFiltered += LoadFilteredItems;
}
async Task LoadFilteredItems(IEnumerable<Models.ListItem> listItems)
{
ListItems = listItems;
Loaded = true;
await UpdateGroups();
}
async Task UpdateGroups()
{
Groups = ListItems.DistinctBy(i => i.Key).SelectMany(i => i.Groups).Distinct().ToList();
if (ListItems.DistinctBy(i => i.Key).Any(i => i.Groups == null || i.Groups.Length == 0))
Groups.Add(LocalizationService.GetString("Uncategorized"));
await InvokeAsync(StateHasChanged);
}
public void Dispose()
{
DepotService.OnItemsFiltered -= LoadFilteredItems;
}
}