From 755fb4cc07ea3e795835901a7e6a2d3ca513dbc1 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Sun, 14 Jan 2024 00:08:01 +0330 Subject: [PATCH] Add onaftersuccess --- .../DeleteBaseDialog.razor | 17 ++++++++- ...syMicroservices.UI.BlazorComponents.csproj | 2 +- .../SaveChangeBaseDialog.razor | 38 +++++++++++++------ .../EasyMicroservices.UI.Cores.Mvvm.csproj | 2 +- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/CSharp/BlazorComponents/EasyMicroservices.UI.BlazorComponents/DeleteBaseDialog.razor b/src/CSharp/BlazorComponents/EasyMicroservices.UI.BlazorComponents/DeleteBaseDialog.razor index 2c886c7..7c1e177 100644 --- a/src/CSharp/BlazorComponents/EasyMicroservices.UI.BlazorComponents/DeleteBaseDialog.razor +++ b/src/CSharp/BlazorComponents/EasyMicroservices.UI.BlazorComponents/DeleteBaseDialog.razor @@ -98,15 +98,27 @@ } } - public void ShowDeleteDialog(TItem item, Func onDelete) + Func _onAfterSuccessAsync; + + public void ShowDeleteDialog(TItem item, Func onDelete, Action onAfterSuccess = null) { + if (onAfterSuccess != null) + { + _onAfterSuccessAsync = () => + { + onAfterSuccess(); + return Task.CompletedTask; + }; + } OnDeleteAsync = null; OnDelete = onDelete; ShowDeleteDialog(item); } - public void ShowDeleteDialogAsync(TItem item, Func> onDeleteAsync) + public void ShowDeleteDialogAsync(TItem item, Func> onDeleteAsync, Func onAfterSuccess = null) { + if (onAfterSuccess != null) + _onAfterSuccessAsync = onAfterSuccess; OnDelete = null; OnDeleteAsync = onDeleteAsync; ShowDeleteDialog(item); @@ -120,6 +132,7 @@ void ShowSucess() { + _onAfterSuccessAsync?.Invoke(); Snackbar.Add(SuccessMessage, Severity.Success, key: Guid.NewGuid().ToString()); deleteDialog.CloseDialog(); } diff --git a/src/CSharp/BlazorComponents/EasyMicroservices.UI.BlazorComponents/EasyMicroservices.UI.BlazorComponents.csproj b/src/CSharp/BlazorComponents/EasyMicroservices.UI.BlazorComponents/EasyMicroservices.UI.BlazorComponents.csproj index f5f0754..2db557b 100644 --- a/src/CSharp/BlazorComponents/EasyMicroservices.UI.BlazorComponents/EasyMicroservices.UI.BlazorComponents.csproj +++ b/src/CSharp/BlazorComponents/EasyMicroservices.UI.BlazorComponents/EasyMicroservices.UI.BlazorComponents.csproj @@ -4,7 +4,7 @@ net6.0;net7.0 EasyMicroservices true - 0.0.0.22 + 0.0.0.23 Core UI compoents. EasyMicroservices@gmail.com component,microcomponent,ui,core diff --git a/src/CSharp/BlazorComponents/EasyMicroservices.UI.BlazorComponents/SaveChangeBaseDialog.razor b/src/CSharp/BlazorComponents/EasyMicroservices.UI.BlazorComponents/SaveChangeBaseDialog.razor index 74160b0..6b420cf 100644 --- a/src/CSharp/BlazorComponents/EasyMicroservices.UI.BlazorComponents/SaveChangeBaseDialog.razor +++ b/src/CSharp/BlazorComponents/EasyMicroservices.UI.BlazorComponents/SaveChangeBaseDialog.razor @@ -68,15 +68,22 @@ } Func _onAfterLoadAsync; + Func _onAfterSuccessAsync; + bool IsShowedOnce = false; protected override async Task OnAfterRenderAsync(bool firstRender) { await base.OnAfterRenderAsync(firstRender); - _ = Task.Run(async () => + if (!IsShowedOnce) { - await Task.Delay(200); - await _onAfterLoadAsync?.Invoke(); - }); + IsShowedOnce = true; + _ = Task.Run(async () => + { + await Task.Delay(200); + await _onAfterLoadAsync?.Invoke(); + }); + } } + async void DoSave() { try @@ -114,7 +121,7 @@ } } - public void ShowSaveDialog(TItem item, Func onSave, Action onAfterLoad = null) + public void ShowSaveDialog(TItem item, Func onSave, Action onAfterLoad = null, Action onAfterSuccess = null) { if (onAfterLoad != null) { @@ -124,20 +131,25 @@ return Task.CompletedTask; }; } + if (onAfterSuccess != null) + { + _onAfterSuccessAsync = () => + { + onAfterSuccess(); + return Task.CompletedTask; + }; + } OnSaveAsync = null; OnSave = onSave; ShowSaveDialog(item); } - public void ShowSaveDialogAsync(TItem item, Func> onSaveAsync, Func onAfterLoad = null) + public void ShowSaveDialogAsync(TItem item, Func> onSaveAsync, Func onAfterLoad = null, Func onAfterSuccess = null) { if (onAfterLoad != null) - { - _onAfterLoadAsync = async () => - { - await onAfterLoad(); - }; - } + _onAfterLoadAsync = onAfterLoad; + if (onAfterSuccess != null) + _onAfterSuccessAsync = onAfterSuccess; OnSave = null; OnSaveAsync = onSaveAsync; ShowSaveDialog(item); @@ -145,12 +157,14 @@ void ShowSaveDialog(TItem item) { + IsShowedOnce = false; selectedItem = item; saveDialog.ShowDialog(); } void ShowSucess() { + _onAfterSuccessAsync?.Invoke(); Snackbar.Add(SuccessMessage, Severity.Success, key: Guid.NewGuid().ToString()); saveDialog.CloseDialog(); } diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj index 8e5828c..b1accd6 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.22 + 0.0.0.23 Model View View Model EasyMicroservices@gmail.com mvvm,mvpvm,modelview,modelviewviewmodel