LANCommander/LANCommander.Server/UI/Pages/Games/Components/CustomFieldEditor.razor
Pat Hartl 20731f355a Fix certain taxonomies (tag, genre, platform) being removed from game on save
Fixes the action, custom field, multiplayer mode, and save path editors from clearing out taxonomies when saving. Also passes the Game/Server/Redistributable ID as a cascading parameter.
2025-12-08 00:51:32 -06:00

80 lines
2.5 KiB
Text

@inject GameCustomFieldService GameCustomFieldService
@inject IMessageService MessageService
@inject ILogger<CustomFieldEditor> Logger
<Flex Vertical Gap="FlexGap.Large">
<Table TItem="GameCustomField" DataSource="@_customFields" HidePagination="true" Responsive>
<PropertyColumn Property="p => p.Name">
<Input @bind-Value="context.Name" />
</PropertyColumn>
<PropertyColumn Property="p => p.Value">
<Input @bind-Value="context.Value" />
</PropertyColumn>
<ActionColumn>
<Flex Gap="FlexGap.Small" Justify="FlexJustify.End">
<Popconfirm OnConfirm="() => Remove(context)" Title="Are you sure you want to delete this custom field?">
<Button Type="ButtonType.Text" Danger Icon="@IconType.Outline.Close"/>
</Popconfirm>
</Flex>
</ActionColumn>
</Table>
<GridRow Justify="RowJustify.End">
<GridCol>
<Button OnClick="Add" Type="@ButtonType.Primary">Add Field</Button>
</GridCol>
</GridRow>
</Flex>
@code {
[CascadingParameter(Name = "GameId")] public Guid GameId { get; set; }
ICollection<GameCustomField> _customFields { get; set; } = new List<GameCustomField>();
Game _game;
protected override async Task OnInitializedAsync()
=> await LoadCustomFields();
async Task LoadCustomFields()
=> _customFields = await GameCustomFieldService.GetAsync(cf => cf.GameId == GameId);
async Task Add()
{
_customFields.Add(new GameCustomField
{
GameId = GameId
});
}
async Task Remove(GameCustomField customField)
{
if (customField.Id != Guid.Empty)
await GameCustomFieldService.DeleteAsync(customField);
_customFields.Remove(customField);
}
public async Task Save()
{
try
{
foreach (var customField in _customFields)
{
if (customField.Id == Guid.Empty)
await GameCustomFieldService.AddAsync(customField);
else
await GameCustomFieldService.UpdateAsync(customField);
}
MessageService.SuccessAsync("Custom fields updated!");
}
catch (Exception ex)
{
MessageService.ErrorAsync("Could not save custom fields!");
Logger?.LogError(ex, "Could not save custom fields!");
}
await LoadCustomFields();
}
}