|
13 | 13 | using Fluxor; |
14 | 14 | using Microsoft.AspNetCore.Components; |
15 | 15 | using Microsoft.AspNetCore.Components.Web; |
| 16 | +using Microsoft.Extensions.Logging; |
16 | 17 | using Microsoft.JSInterop; |
17 | 18 | using System.Collections.Immutable; |
18 | 19 | using IDispatcher = Fluxor.IDispatcher; |
@@ -43,14 +44,16 @@ public sealed partial class EventTable |
43 | 44 |
|
44 | 45 | [Inject] private ISettingsService Settings { get; init; } = null!; |
45 | 46 |
|
| 47 | + [Inject] private IFileLogger TraceLogger { get; init; } = null!; |
| 48 | + |
46 | 49 | protected override async Task OnInitializedAsync() |
47 | 50 | { |
48 | 51 | SelectedEventState.Select(s => s.SelectedEvents); |
49 | 52 |
|
50 | | - SubscribeToAction<EventTableAction.SetActiveTable>(action => InvokeAsync(ScrollToSelectedEvent)); |
51 | | - SubscribeToAction<EventTableAction.LoadColumnsCompleted>(action => InvokeAsync(RegisterTableEventHandlers)); |
52 | | - SubscribeToAction<EventTableAction.UpdateCombinedEvents>(action => InvokeAsync(ScrollToSelectedEvent)); |
53 | | - SubscribeToAction<EventTableAction.UpdateDisplayedEvents>(action => InvokeAsync(ScrollToSelectedEvent)); |
| 53 | + SubscribeToAction<EventTableAction.SetActiveTable>(OnSetActiveTable); |
| 54 | + SubscribeToAction<EventTableAction.LoadColumnsCompleted>(OnLoadColumnsCompleted); |
| 55 | + SubscribeToAction<EventTableAction.UpdateCombinedEvents>(OnUpdateCombinedEvents); |
| 56 | + SubscribeToAction<EventTableAction.UpdateDisplayedEvents>(OnUpdateDisplayedEvents); |
54 | 57 |
|
55 | 58 | _eventTableState = EventTableState.Value; |
56 | 59 |
|
@@ -156,6 +159,54 @@ private async Task InvokeContextMenu(MouseEventArgs args) => |
156 | 159 | private async Task InvokeTableColumnMenu(MouseEventArgs args) => |
157 | 160 | await JSRuntime.InvokeVoidAsync("invokeTableColumnMenu", args.ClientX, args.ClientY); |
158 | 161 |
|
| 162 | + private async void OnLoadColumnsCompleted(EventTableAction.LoadColumnsCompleted action) |
| 163 | + { |
| 164 | + try |
| 165 | + { |
| 166 | + await InvokeAsync(RegisterTableEventHandlers); |
| 167 | + } |
| 168 | + catch (Exception e) |
| 169 | + { |
| 170 | + TraceLogger.Trace($"Failed to register table event handlers: {e}", LogLevel.Error); |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + private async void OnSetActiveTable(EventTableAction.SetActiveTable action) |
| 175 | + { |
| 176 | + try |
| 177 | + { |
| 178 | + await InvokeAsync(ScrollToSelectedEvent); |
| 179 | + } |
| 180 | + catch (Exception e) |
| 181 | + { |
| 182 | + TraceLogger.Trace($"Failed to scroll to selected event on set active table: {e}", LogLevel.Error); |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + private async void OnUpdateCombinedEvents(EventTableAction.UpdateCombinedEvents action) |
| 187 | + { |
| 188 | + try |
| 189 | + { |
| 190 | + await InvokeAsync(ScrollToSelectedEvent); |
| 191 | + } |
| 192 | + catch (Exception e) |
| 193 | + { |
| 194 | + TraceLogger.Trace($"Failed to scroll to selected event on update combined events: {e}", LogLevel.Error); |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + private async void OnUpdateDisplayedEvents(EventTableAction.UpdateDisplayedEvents action) |
| 199 | + { |
| 200 | + try |
| 201 | + { |
| 202 | + await InvokeAsync(ScrollToSelectedEvent); |
| 203 | + } |
| 204 | + catch (Exception e) |
| 205 | + { |
| 206 | + TraceLogger.Trace($"Failed to scroll to selected event on update displayed events: {e}", LogLevel.Error); |
| 207 | + } |
| 208 | + } |
| 209 | + |
159 | 210 | private async Task RegisterTableEventHandlers() => await JSRuntime.InvokeVoidAsync("registerTableEvents"); |
160 | 211 |
|
161 | 212 | private async Task ScrollToSelectedEvent() |
|
0 commit comments