From e1c57967e46f90a4075bd18bb71b40f8212e5da0 Mon Sep 17 00:00:00 2001 From: troogs Date: Sun, 10 May 2026 19:40:06 +0200 Subject: [PATCH] Fix EditProspectDialog and Prospects: prevent multiple modal openings during save and create operations --- .../Dialogs/EditProspectDialog.razor.cs | 31 +++++++++++++------ .../Pages/Prospects.razor.cs | 13 +++++++- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor.cs b/FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor.cs index b175065..49b2481 100644 --- a/FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor.cs +++ b/FoodsharingSiegen.Server/Dialogs/EditProspectDialog.razor.cs @@ -82,23 +82,34 @@ namespace FoodsharingSiegen.Server.Dialogs #region Private Method SaveClick + private bool _isSaving; + /// /// Saves the click (a. beging, 31.05.2022) /// private async Task SaveClick() { - if (IsUpdateMode) + if (_isSaving) return; + _isSaving = true; + try { - var updateR = await ProspectService.UpdateAsync(Prospect); - if (updateR.Success && OnSuccess != null) await OnSuccess.Invoke(); - } - else - { - var addR = await ProspectService.AddProspectAsync(Prospect); - if (addR.Success && OnSuccess != null) await OnSuccess.Invoke(); - } + if (IsUpdateMode) + { + var updateR = await ProspectService.UpdateAsync(Prospect); + if (updateR.Success && OnSuccess != null) await OnSuccess.Invoke(); + } + else + { + var addR = await ProspectService.AddProspectAsync(Prospect); + if (addR.Success && OnSuccess != null) await OnSuccess.Invoke(); + } - await ModalService.Hide(); + await ModalService.Hide(); + } + finally + { + _isSaving = false; + } } #endregion diff --git a/FoodsharingSiegen.Server/Pages/Prospects.razor.cs b/FoodsharingSiegen.Server/Pages/Prospects.razor.cs index 5e12399..460de62 100644 --- a/FoodsharingSiegen.Server/Pages/Prospects.razor.cs +++ b/FoodsharingSiegen.Server/Pages/Prospects.razor.cs @@ -56,13 +56,24 @@ namespace FoodsharingSiegen.Server.Pages #region Private Method CreateProspectAsync + private bool _isOpeningModal; + /// /// Asynchronously creates a new prospect by displaying the AddProspectModal dialog and refreshing the prospect list. /// /// A task that represents the asynchronous operation. private async Task CreateProspectAsync() { - await EditProspectDialog.ShowAsync(ModalService, LoadProspects); + if (_isOpeningModal) return; + _isOpeningModal = true; + try + { + await EditProspectDialog.ShowAsync(ModalService, LoadProspects); + } + finally + { + _isOpeningModal = false; + } } #endregion