LANCommander/LANCommander.Server/UI/Pages/Games/Components/GameMetadataLookup.razor

55 lines
1.6 KiB
Text
Raw Permalink Normal View History

@inject MetadataService MetadataService
<Modal Visible="_modalVisible" Title="Game Metadata Lookup" Footer="null" Class="game-metadata-lookup-modal" OnCancel="Close">
<MetadataLookupPanel
GameId="GameId"
AutoFocus="true"
Search="@Value"
OnImported="OnPanelImported"
OnCancel="Close" />
</Modal>
<Flex Gap="FlexGap.Small">
<Input @bind-Value="Value" BindOnInput="true" OnkeyDown="SearchFieldOnKeyDown" OnChange="ValueChanged" AutoFocus="AutoFocus" />
<Button OnClick="OpenLookup" Type="ButtonType.Primary" Disabled="@(String.IsNullOrWhiteSpace(Value) || !_hasProviders)">@ButtonText</Button>
</Flex>
@code {
[Parameter] public Guid GameId { get; set; }
[Parameter] public EventCallback<Guid> OnImported { get; set; }
[Parameter] public string ButtonText { get; set; } = "Lookup";
[Parameter] public bool AutoFocus { get; set; }
[Parameter] public string Value { get; set; }
[Parameter] public EventCallback<string> ValueChanged { get; set; }
bool _modalVisible;
bool _hasProviders;
protected override void OnInitialized()
{
_hasProviders = MetadataService.GetProviderNames().Any();
}
private async Task SearchFieldOnKeyDown(KeyboardEventArgs e)
{
if ((e.Code == "Enter" || e.Code == "NumpadEnter") && !String.IsNullOrWhiteSpace(Value))
OpenLookup();
}
private void OpenLookup()
{
_modalVisible = true;
}
private void Close()
{
_modalVisible = false;
}
private async Task OnPanelImported(Guid gameId)
{
_modalVisible = false;
await OnImported.InvokeAsync(gameId);
}
}