encapsulated render logic into a function to be able to call it recursively

This commit is contained in:
krut_ni 2026-03-10 16:45:01 +01:00
parent dbdcdef83c
commit 4f836e2dfb
No known key found for this signature in database
GPG Key ID: A5C0151B4DDB172C
2 changed files with 239 additions and 247 deletions

View File

@ -1,4 +1,4 @@
@attribute [Route(Routes.ASSISTANT_DYNAMIC)]
@attribute [Route(Routes.ASSISTANT_DYNAMIC)]
@using AIStudio.Components
@using AIStudio.Settings
@using AIStudio.Tools.PluginSystem.Assistants.DataModel
@ -6,6 +6,18 @@
@foreach (var component in this.RootComponent!.Children)
{
@this.RenderComponent(component)
}
@code {
private RenderFragment RenderChildren(IEnumerable<IAssistantComponent> children) => @<text>
@foreach (var child in children)
{
@this.RenderComponent(child)
}
</text>;
private RenderFragment RenderComponent(IAssistantComponent component) => @<text>
@switch (component.Type)
{
case AssistantComponentType.TEXT_AREA:
@ -31,8 +43,7 @@
AutoGrow="@true"
MaxLines="12"
Class='@MergeClass(textArea.Class, "mb-3")'
Style="@this.GetOptionalStyle(textArea.Style)"
/>
Style="@this.GetOptionalStyle(textArea.Style)" />
}
break;
case AssistantComponentType.IMAGE:
@ -43,7 +54,7 @@
{
var image = assistantImage;
<div Class="mb-4">
<MudImage Fluid="true" Src="@resolvedSource" Alt="@image.Alt" Class='@MergeClass(image.Class, "rounded-lg mb-2")' Style="@this.GetOptionalStyle(image.Style)" Elevation="20"/>
<MudImage Fluid="true" Src="@resolvedSource" Alt="@image.Alt" Class='@MergeClass(image.Class, "rounded-lg mb-2")' Style="@this.GetOptionalStyle(image.Style)" Elevation="20" />
@if (!string.IsNullOrWhiteSpace(image.Caption))
{
<MudText Typo="Typo.caption" Align="Align.Center">@image.Caption</MudText>
@ -60,7 +71,7 @@
ProviderSettings="@this.providerSettings"
@bind-AgentIsRunning="@webState.AgentIsRunning"
@bind-Preselect="@webState.Preselect"
@bind-PreselectContentCleanerAgent="@webState.PreselectContentCleanerAgent"/>
@bind-PreselectContentCleanerAgent="@webState.PreselectContentCleanerAgent" />
</div>
}
break;
@ -72,7 +83,6 @@
</div>
}
break;
case AssistantComponentType.DROPDOWN:
if (component is AssistantDropdown assistantDropdown)
{
@ -82,14 +92,14 @@
Label="@assistantDropdown.Label"
Icon="@Icons.Material.Filled.Translate"
Class="@assistantDropdown.Class"
Style="@assistantDropdown.Style"/>
Style="@assistantDropdown.Style" />
}
break;
case AssistantComponentType.BUTTON:
if (component is AssistantButton assistantButton)
{
var button = assistantButton;
<div >
<div>
<MudButton Variant="@button.GetButtonVariant()"
Color="@AssistantComponentPropHelper.GetColor(button.Color, Color.Default)"
OnClick="@(() => this.ExecuteButtonActionAsync(button))"
@ -103,7 +113,8 @@
Class='@MergeClass(button.Class, "mb-3")'
Style="@this.GetOptionalStyle(button.Style)">
@button.Text
</MudButton></div>
</MudButton>
</div>
}
break;
case AssistantComponentType.BUTTON_GROUP:
@ -118,26 +129,7 @@
DropShadow="@buttonGroup.DropShadow"
Class='@MergeClass(buttonGroup.Class, "mb-3")'
Style="@this.GetOptionalStyle(buttonGroup.Style)">
@foreach (var child in buttonGroup.Children)
{
if (child is AssistantButton childButton)
{
<MudButton Variant="@childButton.GetButtonVariant()"
Color="@AssistantComponentPropHelper.GetColor(childButton.Color, Color.Default)"
OnClick="@(() => this.ExecuteButtonActionAsync(childButton))"
Size="@AssistantComponentPropHelper.GetComponentSize(childButton.Size, Size.Medium)"
FullWidth="@childButton.IsFullWidth"
StartIcon="@AssistantComponentPropHelper.GetIconSvg(childButton.StartIcon)"
EndIcon="@AssistantComponentPropHelper.GetIconSvg(childButton.EndIcon)"
IconColor="@AssistantComponentPropHelper.GetColor(childButton.IconColor, Color.Inherit)"
IconSize="@AssistantComponentPropHelper.GetComponentSize(childButton.IconSize, Size.Medium)"
Disabled="@this.IsButtonActionRunning(childButton.Name)"
Class="@childButton.Class"
Style="@this.GetOptionalStyle(childButton.Style)">
@childButton.Text
</MudButton>
}
}
@this.RenderChildren(buttonGroup.Children)
</MudButtonGroup>
}
break;
@ -246,9 +238,10 @@
Rounded="@rounded"
Elevation="@elevation"
Style="@($"color: {this.colorPickerFields[colorPicker.Name]};")"
Class="@MergeClass(colorPicker.Class, "mb-3")"/>
Class="@MergeClass(colorPicker.Class, "mb-3")" />
</MudItem>
}
break;
}
</text>;
}

View File

@ -571,5 +571,4 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
var time = this.AddUserRequest(await this.CollectUserPromptAsync());
await this.AddAIResponseAsync(time);
}
}