Fixed panel expansion logic

This commit is contained in:
Thorsten Sommer 2026-06-20 20:01:16 +02:00
parent ad593fdc34
commit 1382627f92
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 45 additions and 14 deletions

View File

@ -8,11 +8,11 @@
</MudText>
<InnerScrolling>
<MudExpansionPanels Class="mb-3" MultiExpansion="@false">
<MudExpansionPanels @key="@this.expansionPanelsRenderKey" Class="mb-3" MultiExpansion="@false">
@if (this.SettingsManager.ConfigurationData.App.ShowIntroduction)
{
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.MenuBook" HeaderText="@T("Introduction")" IsExpanded="@this.IsBuiltInIntroductionExpanded">
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.MenuBook" HeaderText="@T("Introduction")" IsExpanded="@this.IsPanelExpanded(PANEL_ID_BUILT_IN_INTRODUCTION)" ExpandedChanged="@(isExpanded => this.SetPanelExpanded(PANEL_ID_BUILT_IN_INTRODUCTION, isExpanded))">
<MudText Typo="Typo.h5" Class="mb-3">
@T("Welcome to MindWork AI Studio!")
</MudText>
@ -31,7 +31,7 @@
@foreach (var introduction in this.introductions)
{
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.Info" HeaderText="@introduction.Title" IsExpanded="@this.IsIntroductionExpanded(introduction)">
<ExpansionPanel @key="@introduction.Id" HeaderIcon="@Icons.Material.Filled.Info" HeaderText="@introduction.Title" IsExpanded="@this.IsPanelExpanded(IntroductionPanelId(introduction))" ExpandedChanged="@(isExpanded => this.SetPanelExpanded(IntroductionPanelId(introduction), isExpanded))">
<MudText Typo="Typo.body2" Class="mb-3">
@T("Version"): @introduction.VersionText
</MudText>
@ -39,21 +39,21 @@
</ExpansionPanel>
}
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.EventNote" HeaderText="@T("Last Changelog")" IsExpanded="@this.IsLastChangelogExpanded">
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.EventNote" HeaderText="@T("Last Changelog")" IsExpanded="@this.IsPanelExpanded(PANEL_ID_LAST_CHANGELOG)" ExpandedChanged="@(isExpanded => this.SetPanelExpanded(PANEL_ID_LAST_CHANGELOG, isExpanded))">
<MudMarkdown Value="@this.LastChangeContent" Props="Markdown.DefaultConfig" MarkdownPipeline="Markdown.SAFE_MARKDOWN_PIPELINE"/>
</ExpansionPanel>
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.Lightbulb" HeaderText="@T("Vision")">
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.Lightbulb" HeaderText="@T("Vision")" IsExpanded="@this.IsPanelExpanded(PANEL_ID_VISION)" ExpandedChanged="@(isExpanded => this.SetPanelExpanded(PANEL_ID_VISION, isExpanded))">
<Vision/>
</ExpansionPanel>
@if (this.SettingsManager.ConfigurationData.App.ShowQuickStartGuide)
{
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.RocketLaunch" HeaderText="@T("Quick Start Guide")">
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.RocketLaunch" HeaderText="@T("Quick Start Guide")" IsExpanded="@this.IsPanelExpanded(PANEL_ID_QUICK_START_GUIDE)" ExpandedChanged="@(isExpanded => this.SetPanelExpanded(PANEL_ID_QUICK_START_GUIDE, isExpanded))">
<MudMarkdown Props="Markdown.DefaultConfig" Value="@QUICK_START_GUIDE" MarkdownPipeline="Markdown.SAFE_MARKDOWN_PIPELINE"/>
</ExpansionPanel>
}
</MudExpansionPanels>
</InnerScrolling>
</div>
</div>

View File

@ -22,6 +22,13 @@ public partial class Home : MSGComponentBase
private List<DataIntroduction> introductions = [];
private string expandedPanelId = string.Empty;
private int expansionPanelsRenderKey;
private const string PANEL_ID_BUILT_IN_INTRODUCTION = "built-in-introduction";
private const string PANEL_ID_LAST_CHANGELOG = "last-changelog";
private const string PANEL_ID_VISION = "vision";
private const string PANEL_ID_QUICK_START_GUIDE = "quick-start-guide";
#region Overrides of ComponentBase
protected override async Task OnInitializedAsync()
@ -30,6 +37,7 @@ public partial class Home : MSGComponentBase
await base.OnInitializedAsync();
this.InitializeAdvantagesItems();
this.RefreshIntroductionPanels();
this.EnsureDefaultExpandedPanel();
// Read the last change content asynchronously
// without blocking the UI thread:
@ -75,11 +83,13 @@ public partial class Home : MSGComponentBase
case Event.PLUGINS_RELOADED:
this.InitializeAdvantagesItems();
this.RefreshIntroductionPanels();
this.EnsureDefaultExpandedPanel();
await this.InvokeAsync(this.StateHasChanged);
break;
case Event.CONFIGURATION_CHANGED:
this.RefreshIntroductionPanels();
this.EnsureDefaultExpandedPanel();
await this.InvokeAsync(this.StateHasChanged);
break;
}
@ -92,15 +102,36 @@ public partial class Home : MSGComponentBase
this.introductions = PluginFactory.GetIntroductions().ToList();
}
private bool IsBuiltInIntroductionExpanded => this.SettingsManager.ConfigurationData.App.ShowIntroduction;
private string GetDefaultExpandedPanelId()
{
if (this.SettingsManager.ConfigurationData.App.ShowIntroduction)
return PANEL_ID_BUILT_IN_INTRODUCTION;
private bool IsIntroductionExpanded(DataIntroduction introduction) =>
!this.SettingsManager.ConfigurationData.App.ShowIntroduction &&
this.introductions.FirstOrDefault() == introduction;
var firstIntroduction = this.introductions.FirstOrDefault();
return firstIntroduction is not null
? IntroductionPanelId(firstIntroduction)
: PANEL_ID_LAST_CHANGELOG;
}
private bool IsLastChangelogExpanded =>
!this.SettingsManager.ConfigurationData.App.ShowIntroduction &&
this.introductions.Count == 0;
private void EnsureDefaultExpandedPanel()
{
this.expandedPanelId = this.GetDefaultExpandedPanelId();
this.expansionPanelsRenderKey++;
}
private bool IsPanelExpanded(string panelId) => string.Equals(this.expandedPanelId, panelId, StringComparison.Ordinal);
private Task SetPanelExpanded(string panelId, bool isExpanded)
{
if (isExpanded)
this.expandedPanelId = panelId;
else if (this.IsPanelExpanded(panelId))
this.expandedPanelId = string.Empty;
return Task.CompletedTask;
}
private static string IntroductionPanelId(DataIntroduction introduction) => $"introduction:{introduction.Id}";
private async Task ReadLastChangeAsync()
{