LANCommander/LANCommander.Launcher/UI/Depot/Index.razor
Pat Hartl 5a32bbf890 Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00

135 lines
4.2 KiB
Text

@page "/Depot"
@page "/Depot/{id:guid}"
@using LANCommander.Launcher.Models
@using LANCommander.Launcher.UI.Depot.Components
@using LANCommander.SDK.Exceptions
@implements IDisposable
@inject NavigationManager NavigationManager
@inject DepotService DepotService
@inject LibraryService LibraryService
@inject KeepAliveService KeepAliveService
@inject MessageService MessageService
@inject ILogger<Index> Logger
@inject LocalizationService LocalizationService
<Spin Spinning="Disabled">
<Layout>
<Content Class="depot">
<DepotFilter />
<DepotList OnItemSelected="@((item) => NavigationManager.NavigateTo($"/Depot/{item.Key}"))" />
</Content>
</Layout>
<DepotGameDetails @ref="DepotGameDetails" ItemId="@(SelectedItem?.Key ?? Guid.Empty)" OnClose="@(() => NavigationManager.NavigateTo("/Depot"))" />
</Spin>
<div class="logo">
<img src="assets/logo-cut.svg" />
</div>
<LANCommander.Launcher.UI.Components.Footer />
@code {
[Parameter] public Guid Id { get; set; }
DepotGameDetails DepotGameDetails;
IEnumerable<Models.ListItem> ListItems = new List<Models.ListItem>();
Models.ListItem SelectedItem { get; set; }
Settings Settings = SettingService.GetSettings();
bool Disabled = false;
protected override async Task OnInitializedAsync()
{
DepotService.OnItemsFiltered += LoadFilteredItems;
LibraryService.OnLibraryItemsUpdated += OnLibraryItemsUpdated;
KeepAliveService.ConnectionSevered += KeepAliveServiceOnConnectionSevered;
KeepAliveService.ConnectionEstablished += KeepAliveServiceOnConnectionEstablished;
KeepAliveService.ConnectionLostPermanently += KeepAliveServiceOnConnectionLostPermanently;
try
{
await DepotService.RefreshItemsAsync();
}
catch (DepotNoResultsException ex)
{
MessageService.Error(LocalizationService.GetString("DepotResultsCouldNotBeFetched"));
Logger?.LogError(ex, "The depot returned no results");
}
catch (Exception ex)
{
MessageService.Error(LocalizationService.GetString("UnexpectedErrorFetchingDepotResults"));
Logger?.LogError(ex, "Unexpected error fetching depot results");
}
}
private void KeepAliveServiceOnConnectionLostPermanently(object? sender, EventArgs e)
{
NavigationManager.NavigateTo("/");
}
private async void KeepAliveServiceOnConnectionEstablished(object? sender, EventArgs e)
{
Disabled = false;
await InvokeAsync(StateHasChanged);
}
private async void KeepAliveServiceOnConnectionSevered(object? sender, EventArgs e)
{
Disabled = true;
await InvokeAsync(StateHasChanged);
}
protected override async Task OnParametersSetAsync()
{
SelectedItem = DepotService.Items.FirstOrDefault(i => i.Key == Id);
if (SelectedItem != null && Id != Guid.Empty)
{
await DepotGameDetails.Show();
}
}
async Task LoadFilteredItems(IEnumerable<Models.ListItem> listItems)
{
ListItems = listItems;
await InvokeAsync(StateHasChanged);
}
protected Task OnLibraryItemsUpdated(IEnumerable<Models.ListItem> itemsUpdatedOrAdded, IEnumerable<Models.ListItem> itemsRemoved)
{
foreach (var item in itemsUpdatedOrAdded ?? [])
{
if (ListItems?.FirstOrDefault()?.DataItem is SDK.Models.DepotGame depotItem)
{
depotItem.InLibrary = true;
}
}
foreach (var item in itemsRemoved ?? [])
{
if (ListItems?.FirstOrDefault()?.DataItem is SDK.Models.DepotGame depotItem)
{
depotItem.InLibrary = false;
}
}
return Task.CompletedTask;
}
public void Dispose()
{
DepotService.OnItemsFiltered -= LoadFilteredItems;
LibraryService.OnLibraryItemsUpdated -= OnLibraryItemsUpdated;
KeepAliveService.ConnectionEstablished -= KeepAliveServiceOnConnectionEstablished;
KeepAliveService.ConnectionSevered -= KeepAliveServiceOnConnectionSevered;
KeepAliveService.ConnectionLostPermanently -= KeepAliveServiceOnConnectionLostPermanently;
}
}