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.Components
@using AIStudio.Settings @using AIStudio.Settings
@using AIStudio.Tools.PluginSystem.Assistants.DataModel @using AIStudio.Tools.PluginSystem.Assistants.DataModel
@ -6,6 +6,18 @@
@foreach (var component in this.RootComponent!.Children) @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) @switch (component.Type)
{ {
case AssistantComponentType.TEXT_AREA: case AssistantComponentType.TEXT_AREA:
@ -31,8 +43,7 @@
AutoGrow="@true" AutoGrow="@true"
MaxLines="12" MaxLines="12"
Class='@MergeClass(textArea.Class, "mb-3")' Class='@MergeClass(textArea.Class, "mb-3")'
Style="@this.GetOptionalStyle(textArea.Style)" Style="@this.GetOptionalStyle(textArea.Style)" />
/>
} }
break; break;
case AssistantComponentType.IMAGE: case AssistantComponentType.IMAGE:
@ -72,7 +83,6 @@
</div> </div>
} }
break; break;
case AssistantComponentType.DROPDOWN: case AssistantComponentType.DROPDOWN:
if (component is AssistantDropdown assistantDropdown) if (component is AssistantDropdown assistantDropdown)
{ {
@ -103,7 +113,8 @@
Class='@MergeClass(button.Class, "mb-3")' Class='@MergeClass(button.Class, "mb-3")'
Style="@this.GetOptionalStyle(button.Style)"> Style="@this.GetOptionalStyle(button.Style)">
@button.Text @button.Text
</MudButton></div> </MudButton>
</div>
} }
break; break;
case AssistantComponentType.BUTTON_GROUP: case AssistantComponentType.BUTTON_GROUP:
@ -118,26 +129,7 @@
DropShadow="@buttonGroup.DropShadow" DropShadow="@buttonGroup.DropShadow"
Class='@MergeClass(buttonGroup.Class, "mb-3")' Class='@MergeClass(buttonGroup.Class, "mb-3")'
Style="@this.GetOptionalStyle(buttonGroup.Style)"> Style="@this.GetOptionalStyle(buttonGroup.Style)">
@foreach (var child in buttonGroup.Children) @this.RenderChildren(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>
}
}
</MudButtonGroup> </MudButtonGroup>
} }
break; break;
@ -251,4 +243,5 @@
} }
break; break;
} }
</text>;
} }

View File

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