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

97 lines
3 KiB
Text

@using LANCommander.SDK.Models
@namespace LANCommander.Launcher.UI
@inherits FeedbackComponent<Data.Models.Game>
@inject SaveService SaveService
@inject IMessageService MessageService
@inject LocalizationService LocalizationService
<Table DataSource="Saves" Size="TableSize.Small" PageIndex="@CurrentPage" PageSize="@PageSize" PaginationPosition="none">
<PropertyColumn Property="s => s.CreatedOn" Title="@LocalizationService.GetString("CreatedOn")" />
<PropertyColumn Property="s => s.Size">
<ByteSize Value="context.Size" />
</PropertyColumn>
<ActionColumn>
<Flex Justify="FlexJustify.End">
<Popconfirm Title="@LocalizationService.GetString("AreYouSureReplaceLocalSaves")" OnConfirm="() => Download(context)">
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.Download" />
</Popconfirm>
<Popconfirm Title="@LocalizationService.GetString("AreYouSureDeleteSave")" OnConfirm="() => Delete(context)">
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.Close" Danger />
</Popconfirm>
</Flex>
</ActionColumn>
</Table>
<GridRow Wrap="false" Style="padding: 10px 16px;">
<GridCol Flex="@("auto")" Style=";display: flex; align-items: center;">
@if (Saves.Count() > PageSize)
{
<Pagination Simple PageSize="@PageSize" OnChange="OnPageChange" Total="Saves.Count()" />
}
</GridCol>
<GridCol>
<Space Direction="SpaceDirection.Horizontal">
<SpaceItem>
<Button OnClick="() => Upload()">@LocalizationService.GetString("Upload")</Button>
</SpaceItem>
<SpaceItem>
<Button Type="ButtonType.Primary" OnClick="() => Close()">@LocalizationService.GetString("Close")</Button>
</SpaceItem>
</Space>
</GridCol>
</GridRow>
@code {
IEnumerable<GameSave> Saves = new List<GameSave>();
int PageSize = 10;
int CurrentPage = 1;
protected override async Task OnInitializedAsync()
{
await LoadData();
}
async Task OnPageChange(PaginationEventArgs args)
{
CurrentPage = args.Page;
}
async Task Download(GameSave save)
{
await SaveService.DownloadAsync(Options.InstallDirectory, Options.Id, save.Id);
MessageService.Success(LocalizationService.GetString("SaveDownloaded"));
}
async Task Delete(GameSave save)
{
await SaveService.DeleteAsync(save.Id);
MessageService.Success(LocalizationService.GetString("SaveDeleted"));
await LoadData();
}
async Task Upload()
{
await SaveService.UploadAsync(Options.InstallDirectory, Options.Id);
MessageService.Success(LocalizationService.GetString("SaveUploaded"));
await LoadData();
}
async Task Close()
{
await CloseFeedbackAsync();
}
async Task LoadData()
{
Saves = await SaveService.Get(Options.Id);
Saves = Saves.OrderByDescending(s => s.CreatedOn);
}
}