diff --git a/src/iRLeagueManager.Web/Components/Dialogs/PromptDialog.razor.cs b/src/iRLeagueManager.Web/Components/Dialogs/PromptDialog.razor.cs index 579b5bd8..feb7d858 100644 --- a/src/iRLeagueManager.Web/Components/Dialogs/PromptDialog.razor.cs +++ b/src/iRLeagueManager.Web/Components/Dialogs/PromptDialog.razor.cs @@ -9,7 +9,7 @@ public class PromptDialog : ComponentBase, IDisposable { private bool disposedValue; - [CascadingParameter] MudDialogInstance MudDialog { get; set; } = default!; + [CascadingParameter] protected MudDialogInstance MudDialog { get; set; } = default!; [Parameter] public T Value { get; set; } = default!; [Parameter] public Func>? OnSubmit { get; set; } [Parameter] public Func? OnCancel { get; set; } @@ -18,6 +18,7 @@ public class PromptDialog : ComponentBase, IDisposable [Parameter] public string? Label { get; set; } [Parameter] public string? HelperText { get; set; } [Parameter] public Variant Variant { get; set; } = Variant.Outlined; + [Parameter] public object? Validation { get; set; } private CancellationTokenSource Cts { get; } = new(); protected CancellationToken CancellationToken => Cts.Token; diff --git a/src/iRLeagueManager.Web/Components/Dialogs/TextPromptDialog.razor b/src/iRLeagueManager.Web/Components/Dialogs/TextPromptDialog.razor index eb48d2f0..24b1a921 100644 --- a/src/iRLeagueManager.Web/Components/Dialogs/TextPromptDialog.razor +++ b/src/iRLeagueManager.Web/Components/Dialogs/TextPromptDialog.razor @@ -10,7 +10,8 @@ Variant="Variant" InputType="InputType" Placeholder="@Placeholder" - Clearable="Clearable"/> + Clearable="Clearable" + Validation="Validation"/> diff --git a/src/iRLeagueManager.Web/Components/Results/FetchResultsDialog.razor b/src/iRLeagueManager.Web/Components/Results/FetchResultsDialog.razor new file mode 100644 index 00000000..808c5b21 --- /dev/null +++ b/src/iRLeagueManager.Web/Components/Results/FetchResultsDialog.razor @@ -0,0 +1,64 @@ +@namespace iRLeagueManager.Web.Components +@using iRLeagueApiCore.Common.Models +@inject LeagueApiService apiService +@inherits PromptDialog + + + + + + + + + + +@code { + [Parameter] public EventModel Event { get; set; } = default!; + + private bool hasError = false; + private string errorText = string.Empty; + + protected override async Task Submit() + { + hasError = false; + errorText = string.Empty; + + if (apiService.CurrentLeague is null) + { + MudDialog.Cancel(); + return; + } + + if (int.TryParse(Value, out int subsessionId) == false) + { + hasError = true; + errorText = "Subsession id must be a valid number"; + return; + } + + var request = apiService.CurrentLeague + .Events() + .WithId(Event.Id) + .Results() + .Fetch() + .FromIracingSubSession(subsessionId) + .Post(CancellationToken); + var result = await request; + if (result.Success == false) + { + hasError = true; + errorText = @"Fetching results from iracing api failed. Please check the subsession id and if the league results are available from public. +Please use JSON upload if this does not work"; + } + + MudDialog.Close(Value); + } +} diff --git a/src/iRLeagueManager.Web/Pages/Results.razor b/src/iRLeagueManager.Web/Pages/Results.razor index e94f981b..9e754837 100644 --- a/src/iRLeagueManager.Web/Pages/Results.razor +++ b/src/iRLeagueManager.Web/Pages/Results.razor @@ -108,7 +108,10 @@ @if (SharedState.SeasonFinished == false) { - Upload Result + + Upload Result + Fetch from SubsessionId + } @@ -191,6 +194,25 @@ } } + private async Task FetchResultsClick() + { + var @event = vm.SelectedEvent?.GetModel(); + if (@event is null) + { + return; + } + var parameters = new DialogParameters() + { + { x => x.Event, @event }, + }; + var result = await DialogService.Show("Fetch results from iracing subsession", parameters).Result; + if (result.Canceled == false) + { + await Task.Delay(2000); + await vm.LoadFromEventAsync(@event.Id); + } + } + private async Task TriggerCalculation() { if (vm.Loading)