Skip to content

Commit

Permalink
Merge pull request #151 from SSchulze1989/develop
Browse files Browse the repository at this point in the history
v 0.11.11
  • Loading branch information
SSchulze1989 authored May 13, 2024
2 parents 42b0bea + d549249 commit 28ee77a
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class PromptDialog<T> : 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<T?, CancellationToken, Task<bool>>? OnSubmit { get; set; }
[Parameter] public Func<T?, CancellationToken, Task>? OnCancel { get; set; }
Expand All @@ -18,6 +18,7 @@ public class PromptDialog<T> : 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
Variant="Variant"
InputType="InputType"
Placeholder="@Placeholder"
Clearable="Clearable"/>
Clearable="Clearable"
Validation="Validation"/>
</DialogContent>
<DialogActions>
<PromptDialogButtons OkClick="Submit" OkText="@OkText" CancelClick="Cancel" CancelText="@CancelText" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@namespace iRLeagueManager.Web.Components
@using iRLeagueApiCore.Common.Models
@inject LeagueApiService apiService
@inherits PromptDialog<string>

<MudDialog>
<DialogContent>
<MudTextField @bind-Value="Value"
Label="@Label"
HelperText="@HelperText"
Variant="Variant"
InputType="InputType.Text"
Placeholder="1234567"
Clearable="true"
Error="hasError"
ErrorText="@errorText"/>
</DialogContent>
<DialogActions>
<PromptDialogButtons OkClick="Submit" OkText="Upload" CancelClick="Cancel"/>
</DialogActions>
</MudDialog>

@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);
}
}
24 changes: 23 additions & 1 deletion src/iRLeagueManager.Web/Pages/Results.razor
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@
<Authorized>
@if (SharedState.SeasonFinished == false)
{
<MudButton Color="Color.Primary" OnClick=UploadButtonClick Class="mt-2">Upload Result</MudButton>
<MudButtonGroup Color="Color.Primary" Variant="Variant.Outlined" Class="mt-2">
<MudButton OnClick=UploadButtonClick>Upload Result</MudButton>
<MudButton OnClick="FetchResultsClick">Fetch from SubsessionId</MudButton>
</MudButtonGroup>
}
</Authorized>
</AuthorizeView>
Expand Down Expand Up @@ -191,6 +194,25 @@
}
}

private async Task FetchResultsClick()
{
var @event = vm.SelectedEvent?.GetModel();
if (@event is null)
{
return;
}
var parameters = new DialogParameters<FetchResultsDialog>()
{
{ x => x.Event, @event },
};
var result = await DialogService.Show<FetchResultsDialog>("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)
Expand Down
2 changes: 1 addition & 1 deletion src/iRLeagueManager.Web/iRLeagueManager.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Version>0.11.10</Version>
<Version>0.11.11</Version>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-iRLeagueManager.Web-2B05F9DC-55A3-49D1-BD64-31507000EDF3</UserSecretsId>
Expand Down

0 comments on commit 28ee77a

Please sign in to comment.