Adding a game now immediately provides a dialog to lookup a game through metadata providers. Selecting a result will create the game with the populated metadata. An additional option of automatically downloading art (icon, cover, background, logo) is also provided, though may be inaccurate and completely up to the results of the provider.
54 lines
1.6 KiB
Text
54 lines
1.6 KiB
Text
@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);
|
|
}
|
|
}
|