From 6e0deb4e64b72e98b072772335f2c9211a2b2b6f Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Thu, 17 Apr 2025 11:57:37 +0200 Subject: [PATCH] Refactor Settings component to inherit from MSGComponentBase --- app/MindWork AI Studio/Pages/Settings.razor | 3 +- .../Pages/Settings.razor.cs | 39 +++++-------------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/app/MindWork AI Studio/Pages/Settings.razor b/app/MindWork AI Studio/Pages/Settings.razor index c048a542..ebcd9248 100644 --- a/app/MindWork AI Studio/Pages/Settings.razor +++ b/app/MindWork AI Studio/Pages/Settings.razor @@ -1,6 +1,7 @@ -@attribute [Route(Routes.SETTINGS)] @using AIStudio.Components.Settings @using AIStudio.Settings.DataModel +@attribute [Route(Routes.SETTINGS)] +@inherits MSGComponentBase
Settings diff --git a/app/MindWork AI Studio/Pages/Settings.razor.cs b/app/MindWork AI Studio/Pages/Settings.razor.cs index 57c34c5a..4ed9361b 100644 --- a/app/MindWork AI Studio/Pages/Settings.razor.cs +++ b/app/MindWork AI Studio/Pages/Settings.razor.cs @@ -1,17 +1,12 @@ +using AIStudio.Components; using AIStudio.Settings; using Microsoft.AspNetCore.Components; namespace AIStudio.Pages; -public partial class Settings : ComponentBase, IMessageBusReceiver, IDisposable +public partial class Settings : MSGComponentBase { - [Inject] - private SettingsManager SettingsManager { get; init; } = null!; - - [Inject] - private MessageBus MessageBus { get; init; } = null!; - private List> availableLLMProviders = new(); private List> availableEmbeddingProviders = new(); @@ -19,20 +14,18 @@ public partial class Settings : ComponentBase, IMessageBusReceiver, IDisposable protected override async Task OnInitializedAsync() { - // Register this component with the message bus: - this.MessageBus.RegisterComponent(this); - this.MessageBus.ApplyFilters(this, [], [ Event.CONFIGURATION_CHANGED ]); + this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]); await base.OnInitializedAsync(); } #endregion - - #region Implementation of IMessageBusReceiver - public string ComponentName => nameof(Settings); - - public Task ProcessMessage(ComponentBase? sendingComponent, Event triggeredEvent, TMsg? data) + #region Overrides of MSGComponentBase + + public override string ComponentName => nameof(Settings); + + protected override Task ProcessIncomingMessage(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default { switch (triggeredEvent) { @@ -40,23 +33,9 @@ public partial class Settings : ComponentBase, IMessageBusReceiver, IDisposable this.StateHasChanged(); break; } - + return Task.CompletedTask; } - public Task ProcessMessageWithResult(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data) - { - return Task.FromResult(default); - } - - #endregion - - #region Implementation of IDisposable - - public void Dispose() - { - this.MessageBus.Unregister(this); - } - #endregion } \ No newline at end of file