Merge pull request #3009 from ajahangard/dev

Using DynamicComponent Instead of RenderFragment in ContainerBuilder
This commit is contained in:
Shaun Walker 2023-07-12 16:40:09 -04:00 committed by GitHub
commit 90c1eeb312
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,12 +9,12 @@
@if (_useadminborder)
{
<div class="app-pane-admin-border">
@DynamicComponent
<DynamicComponent Type="@ComponentType"></DynamicComponent>
</div>
}
else
{
@DynamicComponent
<DynamicComponent Type="@ComponentType"></DynamicComponent>
}
</CascadingValue>
@ -23,6 +23,7 @@
@code {
private bool _visible = true;
private bool _useadminborder = false;
public Type ComponentType { get; set; }
[CascadingParameter]
protected PageState PageState { get; set; }
@ -30,8 +31,6 @@
[Parameter]
public Module ModuleState { get; set; }
RenderFragment DynamicComponent { get; set; }
protected override void OnInitialized()
{
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged += PropertyChanged;
@ -54,17 +53,7 @@
_useadminborder = false;
}
DynamicComponent = builder =>
{
Type containerType = Type.GetType(container);
if (containerType == null)
{
// fallback
containerType = Type.GetType(Constants.DefaultContainer);
}
builder.OpenComponent(0, containerType);
builder.CloseComponent();
};
ComponentType = Type.GetType(container) ?? Type.GetType(Constants.DefaultContainer);
}
private void PropertyChanged(object sender, PropertyChangedEventArgs e)
@ -83,4 +72,6 @@
{
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged -= PropertyChanged;
}
}