From a9c77669f224c398bd14755c39c9974d643a67a5 Mon Sep 17 00:00:00 2001 From: Timo Schauties Date: Tue, 30 Jul 2024 06:50:42 +0200 Subject: [PATCH] [Add] 11 Attachment Delete With Single Click - added single click delete with warning --- src/Nexus.UI/Components/AttachmentView.razor | 30 ++++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Nexus.UI/Components/AttachmentView.razor b/src/Nexus.UI/Components/AttachmentView.razor index 540c79e9..63bba0cc 100644 --- a/src/Nexus.UI/Components/AttachmentView.razor +++ b/src/Nexus.UI/Components/AttachmentView.razor @@ -43,7 +43,7 @@ @if (Catalog.Info.IsWritable) { } @@ -102,6 +102,9 @@ [Inject] public INexusClient Client { get; set; } = default!; + [Inject] + private IDialogService DialogService { get; set; } = default!; + [Parameter] public ResourceCatalogViewModel Catalog { get; set; } = default!; @@ -110,14 +113,23 @@ _attachments = default; StateHasChanged(); - try - { - await Client.Catalogs.DeleteAttachmentAsync(Catalog.Id, attachment); - await GetAttachmentsAsync(); - } - catch (Exception ex) + bool? result = await DialogService.ShowMessageBox( + "Warning", + "Do you really want to delete the selected attachment?", + yesText:"Delete!", cancelText:"Cancel"); + bool deleteConfirmed = result == null ? false : true; + + if(deleteConfirmed) { - AppState.AddError(ex, Snackbar); + try + { + await Client.Catalogs.DeleteAttachmentAsync(Catalog.Id, attachment); + await GetAttachmentsAsync(); + } + catch (Exception ex) + { + AppState.AddError(ex, Snackbar); + } } } @@ -191,7 +203,7 @@ } } - private void OpenAttachmentModal() + private void OpenAttachmentModal() { _attachments = default; _isAttachmentDialogOpen = true;