Refactor Settings component to inherit from MSGComponentBase

This commit is contained in:
Thorsten Sommer 2025-04-17 11:57:37 +02:00
parent 06fcaf7f8f
commit 6e0deb4e64
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 11 additions and 31 deletions

View File

@ -1,6 +1,7 @@
@attribute [Route(Routes.SETTINGS)]
@using AIStudio.Components.Settings
@using AIStudio.Settings.DataModel
@attribute [Route(Routes.SETTINGS)]
@inherits MSGComponentBase
<div class="inner-scrolling-context">
<MudText Typo="Typo.h3" Class="mb-12">Settings</MudText>

View File

@ -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<ConfigurationSelectData<string>> availableLLMProviders = new();
private List<ConfigurationSelectData<string>> 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<TMsg>(ComponentBase? sendingComponent, Event triggeredEvent, TMsg? data)
#region Overrides of MSGComponentBase
public override string ComponentName => nameof(Settings);
protected override Task ProcessIncomingMessage<T>(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<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
{
return Task.FromResult<TResult?>(default);
}
#endregion
#region Implementation of IDisposable
public void Dispose()
{
this.MessageBus.Unregister(this);
}
#endregion
}