From 920bc299aa2ee511317ed0b201f4cbdc4e17ca57 Mon Sep 17 00:00:00 2001 From: Loretta Date: Tue, 9 Dec 2025 11:27:21 +0100 Subject: [PATCH] Add grid sync state tracking and robust login redirection Introduce IsSyncing and OnSyncingStateChanged to IMgGridBase and MgGridBase for real-time sync state tracking and event notification. Update FruitBankToolbarTemplate to enable/disable the reload button based on grid sync and reload state, subscribing to sync events and cleaning up on disposal. Implement IAsyncDisposable in MgGridBase to prevent memory leaks. Update login navigation to use forceLoad for reliability. These changes improve UI responsiveness and resource management. --- .../Components/Grids/MgGridBase.cs | 68 +++++++++++++++++-- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/AyCode.Blazor.Components/Components/Grids/MgGridBase.cs b/AyCode.Blazor.Components/Components/Grids/MgGridBase.cs index 7edf4f2..eb06c58 100644 --- a/AyCode.Blazor.Components/Components/Grids/MgGridBase.cs +++ b/AyCode.Blazor.Components/Components/Grids/MgGridBase.cs @@ -15,10 +15,18 @@ namespace AyCode.Blazor.Components.Components.Grids; public interface IMgGridBase : IGrid { - + /// + /// Indicates whether any synchronization operation is in progress + /// + bool IsSyncing { get; } + + /// + /// Event fired when synchronization state changes (true = syncing started, false = syncing ended) + /// + event Action? OnSyncingStateChanged; } -public abstract class MgGridBase : DxGrid, IMgGridBase +public abstract class MgGridBase : DxGrid, IMgGridBase, IAsyncDisposable where TSignalRDataSource : AcSignalRDataSource> where TDataItem : class, IId where TId : struct @@ -29,11 +37,18 @@ public abstract class MgGridBase? _dataSourceParam = []; private string _gridLogName; + /// + public bool IsSyncing => _dataSource?.IsSyncing ?? false; + + /// + public event Action? OnSyncingStateChanged; + public MgGridBase() : base() { } @@ -133,6 +148,7 @@ public abstract class MgGridBase args) { + if (_isDisposed) return; if (args.TrackingState is TrackingState.GetAll or TrackingState.None) return; Logger.Debug($"{_gridLogName} OnDataSourceItemChanged; trackingState: {args.TrackingState}"); @@ -174,7 +203,7 @@ public abstract class MgGridBase(this, args.Item, args.TrackingState); await OnGridItemChanged.InvokeAsync(changedEventArgs); - if (!changedEventArgs.CancelStateChangeInvoke) + if (!changedEventArgs.CancelStateChangeInvoke && !_isDisposed) { //BeginUpdate(); await InvokeAsync(StateHasChanged); //TODO: bezárja a DetailRow-t! pl: az email-nél IsReaded=true update... - J. @@ -184,6 +213,8 @@ public abstract class MgGridBase) @@ -192,8 +223,11 @@ public abstract class MgGridBase : GridDataItemChangedEventArgs where TDataItem : class