Skip to content

Commit 8707670

Browse files
committed
fix(backoffice): Disabling image upload/remove and submit buttons during image upload
1 parent bd02123 commit 8707670

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

src/Eurofurence.App.Backoffice/Components/EventDialog.razor

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<MudTooltip>
5555
<ChildContent>
5656
<div style="width: 500px;">
57-
<ImageField ImageResponse="@_bannerImage" ImageChanged="OnBannerImageUploaded" ImageUploadError="OnImageUploadError" />
57+
<ImageField ImageResponse="@_bannerImage" UploadStarted="OnImageUploadStarted" ImageChanged="OnBannerImageUploaded" ImageUploadError="OnImageUploadError" Disabled="_busy" />
5858
</div>
5959
</ChildContent>
6060
<TooltipContent>
@@ -69,7 +69,7 @@
6969
<MudTooltip>
7070
<ChildContent>
7171
<div style="width: 500px;">
72-
<ImageField ImageResponse="@_posterImage" ImageChanged="OnPosterImageUploaded" ImageUploadError="OnImageUploadError" />
72+
<ImageField ImageResponse="@_posterImage" UploadStarted="OnImageUploadStarted" ImageChanged="OnPosterImageUploaded" ImageUploadError="OnImageUploadError" Disabled="_busy" />
7373
</div>
7474
</ChildContent>
7575
<TooltipContent>
@@ -176,30 +176,41 @@
176176
return null;
177177
}
178178

179+
/// <summary>
180+
/// Called when an image uploaded is started.
181+
/// </summary>
182+
private void OnImageUploadStarted()
183+
{
184+
_busy = true;
185+
}
186+
179187
/// <summary>
180188
/// Called when an error occurs while uploading an image.
181189
/// </summary>
182190
private void OnImageUploadError()
183191
{
192+
_busy = false;
184193
Snackbar.Add("Error uploading image.", Severity.Error);
185194
}
186195

187196
/// <summary>
188-
/// Called when a banner image is uploaded.
197+
/// Called when a banner image has been uploaded.
189198
/// </summary>
190199
/// <param name="image">The uploaded image.</param>
191200
private void OnBannerImageUploaded(ImageResponse? image)
192201
{
202+
_busy = false;
193203
_bannerImage = image;
194204
Snackbar.Add("Banner image successfully uploaded.", Severity.Success);
195205
}
196206

197207
/// <summary>
198-
/// Called when a poster image is uploaded.
208+
/// Called when a poster image has been uploaded.
199209
/// </summary>
200210
/// <param name="image">The uploaded image.</param>
201211
private void OnPosterImageUploaded(ImageResponse? image)
202212
{
213+
_busy = false;
203214
_posterImage = image;
204215
Snackbar.Add("Poster image successfully uploaded.", Severity.Success);
205216
}

src/Eurofurence.App.Backoffice/Components/ImageField.razor

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
{
2828
<MudGrid>
2929
<MudItem xl="6" md="6">
30-
<MudFileUpload T="IBrowserFile" FilesChanged="UploadImage" Style="margin-top: 10px;" />
30+
<MudFileUpload T="IBrowserFile" Disabled="IsUploading || Disabled" FilesChanged="UploadImage" Style="margin-top: 10px;" />
3131
</MudItem>
3232
<MudItem xl="6" md="6">
33-
<MudButton Variant="Variant.Outlined" Color="Color.Error" OnClick="ClearImage" FullWidth="true" Style="margin-top: 10px;">
33+
<MudButton Variant="Variant.Outlined" Color="Color.Error" Disabled="IsUploading || Disabled" OnClick="ClearImage" FullWidth="true" Style="margin-top: 10px;">
3434
Remove
3535
</MudButton>
3636
</MudItem>
3737
</MudGrid>
3838
}
3939
else
4040
{
41-
<MudFileUpload T="IBrowserFile" FilesChanged="UploadImage" Style="margin-top: 10px;" />
41+
<MudFileUpload T="IBrowserFile" Disabled="IsUploading || Disabled" FilesChanged="UploadImage" Style="margin-top: 10px;" />
4242
}
4343
</div>
4444

@@ -50,6 +50,12 @@
5050
[Parameter]
5151
public ImageResponse? ImageResponse { get; set; }
5252

53+
/// <summary>
54+
/// Event raised when the image upload is started.
55+
/// </summary>
56+
[Parameter]
57+
public EventCallback UploadStarted { get; set; }
58+
5359
/// <summary>
5460
/// Event raised when the image is changed.
5561
/// </summary>
@@ -63,6 +69,12 @@
6369
[Parameter]
6470
public EventCallback ImageUploadError { get; set; }
6571

72+
/// <summary>
73+
/// Disables upload and remove buttons.
74+
/// </summary>
75+
[Parameter]
76+
public bool Disabled { get; set; }
77+
6678
/// <summary>
6779
/// Determines whether the remove button should be hidden.
6880
/// </summary>
@@ -83,6 +95,8 @@
8395
}
8496

8597
IsUploading = true;
98+
await UploadStarted.InvokeAsync();
99+
86100
StateHasChanged();
87101

88102
try

0 commit comments

Comments
 (0)