Skip to content

Commit

Permalink
Refactor bonid dashboard page;
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteLeon committed Sep 11, 2023
1 parent 77f9e79 commit 4f20405
Showing 1 changed file with 46 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,64 @@
@inject IPopupService popupService
@inject BondiCompetitionClient bondiCompetitionClient

<PageTitle>Bondi DashBoard</PageTitle>
<PageTitle>Bondi Option Trading Competition DashBoard</PageTitle>

<MCard Flat Rounded=@("xl")>
<MCardText Class="pa-6">
<PPageHeader Title="Bondi DashBoard" ShowFiltersByDefault>
<MCard Flat Rounded=@("xl") Class="my-3">
<MCardText>
<PPageHeader Title="Bondi Option Trading Competition DashBoard" ShowFiltersByDefault>
</PPageHeader>
</MCardText>
</MCard>
<MCard Flat Class="my-3" Rounded=@("xl") MaxWidth="1200">
<MFileInput @bind-Value="_files"
Chips
Multiple
Outlined
Counter=true
ShowSize
Label="Input DashBoard Csv Files"></MFileInput>
<MButton Color="primary"
Dark
Class="mb-2"
Loading="_loading"
OnClick="submitFiles">
Submit
</MButton>

<MCard Flat Class="mb-3" Rounded=@("xl")>
<MCardTitle>Market Quote Files</MCardTitle>
<MCardText>
<MRow>
<MCol>
<MFileInput Label="请选择市场行情文件。"
Multiple Chips Counter=true ShowSize
@bind-Value=this.marketQuoteFiles></MFileInput>
</MCol>
<MCol Cols=@("auto")>
<MButton Color="primary" Loading=this.isUploadingQuoteFiles Depressed Rounded OnClick=this.OnSubmitMarketQuoteFiles>
<MIcon>mdi-file-upload</MIcon> 上传
</MButton>
</MCol>
</MRow>
</MCardText>
</MCard>

@code {
private bool _loading = false;
public async void submitFiles()
private bool isUploadingQuoteFiles = false;
private List<IBrowserFile> marketQuoteFiles = new();

private async Task OnSubmitMarketQuoteFiles()
{
_loading = true;
if (!_files.Any())
{
await this.popupService.EnqueueSnackbarAsync("选取的文件不可为空", AlertTypes.Error);
return;
}
else
this.isUploadingQuoteFiles = true;
try
{
var ans = await this.bondiCompetitionClient.PostFilesAsync(_files);
foreach (var res in ans)
if (!(this.marketQuoteFiles?.Any() ?? false))
{
await this.popupService.EnqueueSnackbarAsync("请选择市场行情文件。", AlertTypes.Error);
return;
}

var uploadResponse = await this.bondiCompetitionClient.PostFilesAsync(this.marketQuoteFiles);
if (uploadResponse is null)
{
await this.popupService.EnqueueSnackbarAsync($"Submit Files Result: {res.Response}", res.IsSuccess ? AlertTypes.Success : AlertTypes.Error);
await this.popupService.EnqueueSnackbarAsync("UploadResponse is empty.", AlertTypes.Error);
return;
}
_loading = false;
}
catch (Exception ex)
{
await this.popupService.EnqueueSnackbarAsync($"OnSubmitMarketQuoteFiles Exception: {ex}", AlertTypes.Error);
this.logger.LogError(ex, "OnSubmitMarketQuoteFiles Exception:");
}
finally
{
this.isUploadingQuoteFiles = false;
this.StateHasChanged();
}

}
private List<IBrowserFile> _files = new();
}

0 comments on commit 4f20405

Please sign in to comment.