Moved overwritten methods to the top

This commit is contained in:
Thorsten Sommer 2025-05-24 18:30:53 +02:00
parent b7c06588b7
commit 7e61d93468
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -67,6 +67,38 @@ public partial class ChatTemplateDialog : MSGComponentBase
// We get the form reference from Blazor code to validate it manually: // We get the form reference from Blazor code to validate it manually:
private MudForm form = null!; private MudForm form = null!;
#region Overrides of ComponentBase
protected override async Task OnInitializedAsync()
{
// Configure the spellchecking for the instance name input:
this.SettingsManager.InjectSpellchecking(SPELLCHECK_ATTRIBUTES);
// Load the used instance names:
this.UsedNames = this.SettingsManager.ConfigurationData.ChatTemplates.Select(x => x.Name.ToLowerInvariant()).ToList();
// When editing, we need to load the data:
if(this.IsEditing)
{
this.dataEditingPreviousName = this.DataName.ToLowerInvariant();
this.dataExampleConversation = this.ExampleConversation.Select(n => n.DeepClone()).ToList();
}
await base.OnInitializedAsync();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
// Reset the validation when not editing and on the first render.
// We don't want to show validation errors when the user opens the dialog.
if(!this.IsEditing && firstRender)
this.form.ResetValidation();
await base.OnAfterRenderAsync(firstRender);
}
#endregion
private ChatTemplate CreateChatTemplateSettings() => new() private ChatTemplate CreateChatTemplateSettings() => new()
{ {
Num = this.DataNum, Num = this.DataNum,
@ -137,23 +169,11 @@ public partial class ChatTemplateDialog : MSGComponentBase
this.StateHasChanged(); this.StateHasChanged();
} }
#region Overrides of ComponentBase
protected override async Task OnInitializedAsync()
private void ResetItem(object? element) private void ResetItem(object? element)
{ {
// Configure the spellchecking for the instance name input:
this.SettingsManager.InjectSpellchecking(SPELLCHECK_ATTRIBUTES);
// Load the used instance names:
this.UsedNames = this.SettingsManager.ConfigurationData.ChatTemplates.Select(x => x.Name.ToLowerInvariant()).ToList();
// When editing, we need to load the data:
if(this.IsEditing)
this.isInlineEditOnGoing = false; this.isInlineEditOnGoing = false;
switch (element) switch (element)
{ {
this.dataEditingPreviousName = this.DataName.ToLowerInvariant();
case ContentBlock block: case ContentBlock block:
if (this.messageEntryBeforeEdit is null) if (this.messageEntryBeforeEdit is null)
return; // No backup to restore from return; // No backup to restore from
@ -163,25 +183,15 @@ public partial class ChatTemplateDialog : MSGComponentBase
break; break;
} }
await base.OnInitializedAsync();
this.StateHasChanged(); this.StateHasChanged();
} }
protected override async Task OnAfterRenderAsync(bool firstRender)
private void CommitInlineEdit(object? element) private void CommitInlineEdit(object? element)
{ {
// Reset the validation when not editing and on the first render.
// We don't want to show validation errors when the user opens the dialog.
if(!this.IsEditing && firstRender)
this.form.ResetValidation();
await base.OnAfterRenderAsync(firstRender);
this.isInlineEditOnGoing = false; this.isInlineEditOnGoing = false;
this.StateHasChanged(); this.StateHasChanged();
} }
#endregion
private async Task Store() private async Task Store()
{ {
await this.form.Validate(); await this.form.Validate();