LANCommander/LANCommander.Launcher/UI/Components/RemoveFromLibraryDialog.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

85 lines
No EOL
2.9 KiB
Text

@using LANCommander.Launcher.Data.Models
@using LANCommander.Launcher.Models
@using LANCommander.SDK.Extensions
@inherits FeedbackComponent<Models.ListItem, string>
@inject LibraryService LibraryService
@inject IMessageService MessageService
@inject ILogger<RemoveFromLibraryDialog> Logger
@inject LocalizationService LocalizationService
<div class="remove-from-library-dialog" style="padding: 16px;">
<div class="game-item">
<div class="icon">
<MediaImage Id="@Options.IconId" />
</div>
<span class="title-pre">@LocalizationService.GetString("BaseGame")</span>
<span class="title">@Options.Name</span>
</div>
@if (DependentGames.Any())
{
<Divider Text="@LocalizationService.GetString("AddonsToRemove")" Orientation="DividerOrientation.Left" Plain />
<CheckboxButtonGroup @bind-Selected="SelectedDependentGames" DataSource="DependentGames"
KeySelector="a => a.Id"
LabelSelector="a => a.Title"
Direction="SpaceDirection.Vertical"
IconSelected="@IconType.Outline.Close"
IconUnselected="@IconType.Fill.Pushpin"
ButtonPropsSelected="@(new[] { ("Danger", (object)true) })"
DisableSelector="g => g.Type == Data.Enums.GameType.Mod || g.Type == Data.Enums.GameType.Expansion"
/>
}
</div>
<Flex Gap="FlexGap.Middle" Style="padding: 16px; padding-top: 0px" Justify="FlexJustify.FlexEnd">
<Button Type="ButtonType.Primary" OnClick="RemoveFromLibrary">@LocalizationService.GetString("Remove")</Button>
<Button OnClick="() => Close()">@LocalizationService.GetString("Close")</Button>
</Flex>
@code {
Settings Settings = SettingService.GetSettings();
Data.Models.Game? Game;
List<Data.Models.Game> DependentGames = new();
IEnumerable<Data.Models.Game> SelectedDependentGames = [];
protected override void OnInitialized()
{
base.OnInitialized();
Game = (Game)Options.DataItem;
DependentGames = Game?.DependentGames.OrderBy(g => g.SortTitle ?? g.Title).ToList() ?? [];
SelectedDependentGames = DependentGames?.Where(g => g.Type == Data.Enums.GameType.Expansion || g.Type == Data.Enums.GameType.Mod) ?? [];
}
async Task Close()
{
await CloseFeedbackAsync();
}
async Task RemoveFromLibrary()
{
if (Options.DataItem is Game game)
{
try
{
var addonIds = SelectedDependentGames?.Select(a => a.Id).ToArray() ?? [];
await LibraryService.RemoveFromLibraryAsync(game!.Id, addonIds);
await LibraryService.RefreshItemsAsync(true);
}
catch (Exception ex)
{
MessageService.Error(LocalizationService.GetString("CouldNotRemoveGame"));
Logger?.LogError(ex, "Could not remove game {GameTitle}", game.Title);
}
}
await CloseFeedbackAsync();
}
}