Skip to content

Commit

Permalink
Lock task execution during upload, display upload load animation
Browse files Browse the repository at this point in the history
  • Loading branch information
cobbr committed Sep 22, 2020
1 parent 04aa791 commit 0d8e032
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Covenant/Components/Grunts/GruntTaskOptionsModal.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@inherits OwningComponentBase<ICovenantService>

@using System.IO
@using System.Threading
@using System.Threading.Tasks
@using Microsoft.JSInterop
@using BlazorInputFile
@using Covenant.Core
Expand Down Expand Up @@ -44,6 +46,10 @@
}
</div>
<div class="modal-footer">
@if (this.UploadInProgress)
{
<span class="fe fe-loader" style="animation: spin-animation 1s infinite;"></span>
}
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" @onclick="Execute" class="btn btn-primary">Execute</button>
</div>
Expand All @@ -58,6 +64,8 @@
private GruntTask GruntTask { get; set; }
private InputFile InputFile { get; set; }
private IList<MemoryStream> UploadedFiles { get; set; }
private SemaphoreSlim UploadSemaphore { get; set; } = new SemaphoreSlim(1, 1);
private bool UploadInProgress { get; set; } = false;

public async Task Show(GruntTask task)
{
Expand All @@ -68,10 +76,12 @@

private async Task Execute()
{
await UploadSemaphore.WaitAsync();
if (this.UploadedFiles != null && this.GruntTask.Options.Any(O => O.FileOption && string.IsNullOrEmpty(O.Value)))
{
this.OnRead(this.UploadedFiles);
}
UploadSemaphore.Release();
await IJSRuntime.InvokeAsync<string>("ModalCommand", "#file-modal", "hide");
await OnSubmit.InvokeAsync(GruntTask);
}
Expand All @@ -81,6 +91,9 @@
{
try
{
await UploadSemaphore.WaitAsync();
this.UploadInProgress = true;
this.StateHasChanged();
this.UploadedFiles = new List<MemoryStream>();
for (int i = 0; i < files.Length; i++)
{
Expand All @@ -98,6 +111,8 @@
this.ErrorMessage = e.Message;
this.StateHasChanged();
}
this.UploadInProgress = false;
UploadSemaphore.Release();
}

private void OnRead(IList<MemoryStream> Streams)
Expand Down
10 changes: 10 additions & 0 deletions Covenant/wwwroot/css/covenant.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ main {
opacity: 1.0;
}

@keyframes spin-animation {
0% {
transform: rotate(0deg);
}

100% {
transform: rotate(359deg);
}
}

.grunt-interact {
display: flex;
flex-wrap: wrap;
Expand Down

0 comments on commit 0d8e032

Please sign in to comment.