General migration to MudBlazor v7.x.x

This commit is contained in:
Thorsten Sommer 2024-07-23 19:53:02 +02:00
parent 0a03ab0aed
commit f7dd6b3074
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
14 changed files with 118 additions and 87 deletions

View File

@ -20,7 +20,7 @@
{
<MudPaper Class="pr-2 mt-3" Outlined="@true">
<MudText Typo="Typo.h6">Issues</MudText>
<MudList Clickable="@true">
<MudList T="string">
@foreach (var issue in this.inputIssues)
{
<MudListItem Icon="@Icons.Material.Filled.Error" IconColor="Color.Error">

View File

@ -1,7 +1,7 @@
<MudList Clickable="@this.Clickable" Class="@this.Classes">
<MudList T="string" ReadOnly="@(!this.Clickable)" Class="@this.Classes">
@foreach(var item in this.Items)
{
<MudListItem Icon="@this.Icon" Style="display: flex; align-items: flex-start;">
<MudListItem T="string" Icon="@this.Icon" Style="display: flex; align-items: flex-start;">
<MudText Typo="Typo.body1" Style="text-align: justify; hyphens: auto;"><b>@item.Header:</b> @item.Text</MudText>
</MudListItem>
}

View File

@ -18,5 +18,5 @@ public class TreeItemData : ITreeItem
public bool Expandable { get; init; } = true;
public HashSet<ITreeItem> Children { get; init; } = [];
public IReadOnlyCollection<TreeItemData<ITreeItem>> Children { get; init; } = [];
}

View File

@ -1,6 +1,6 @@
<MudTreeView T="ITreeItem" Items="@this.treeItems" MultiSelection="@false" Hover="@true" ExpandOnClick="@true">
<ItemTemplate Context="item">
@switch (item)
@switch (item.Value)
{
case TreeDivider:
<li style="min-height: 1em;">
@ -11,7 +11,7 @@
case TreeItemData treeItem:
@if (treeItem.Type is TreeItemType.CHAT)
{
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item" CanExpand="@treeItem.Expandable" Items="@treeItem.Children" OnClick="() => this.LoadChat(treeItem.Path, true)">
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" CanExpand="@treeItem.Expandable" Items="@treeItem.Children" OnClick="() => this.LoadChat(treeItem.Path, true)">
<BodyContent>
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
<MudText Style="justify-self: start;">
@ -44,7 +44,7 @@
}
else if (treeItem.Type is TreeItemType.WORKSPACE)
{
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item" CanExpand="@treeItem.Expandable" Items="@treeItem.Children">
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" CanExpand="@treeItem.Expandable" Items="@treeItem.Children">
<BodyContent>
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
<MudText Style="justify-self: start;">@treeItem.Text</MudText>
@ -63,7 +63,7 @@
}
else
{
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item" CanExpand="@treeItem.Expandable" Items="@treeItem.Children">
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" CanExpand="@treeItem.Expandable" Items="@treeItem.Children">
<BodyContent>
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
<MudText Style="justify-self: start;">@treeItem.Text</MudText>

View File

@ -47,8 +47,8 @@ public partial class Workspaces : ComponentBase
new JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseUpper),
}
};
private readonly HashSet<ITreeItem> treeItems = new();
private readonly List<TreeItemData<ITreeItem>> treeItems = new();
#region Overrides of ComponentBase
@ -70,33 +70,46 @@ public partial class Workspaces : ComponentBase
private async Task LoadTreeItems()
{
this.treeItems.Clear();
this.treeItems.Add(new TreeItemData
this.treeItems.Add(new TreeItemData<ITreeItem>
{
Depth = 0,
Branch = WorkspaceBranch.WORKSPACES,
Text = "Workspaces",
Icon = Icons.Material.Filled.Folder,
Expandable = true,
Path = "root",
Children = await this.LoadWorkspaces(),
Value = new TreeItemData
{
Depth = 0,
Branch = WorkspaceBranch.WORKSPACES,
Text = "Workspaces",
Icon = Icons.Material.Filled.Folder,
Expandable = true,
Path = "root",
Children = await this.LoadWorkspaces(),
},
});
this.treeItems.Add(new TreeDivider());
this.treeItems.Add(new TreeItemData
this.treeItems.Add(new TreeItemData<ITreeItem>
{
Expandable = false,
Value = new TreeDivider(),
});
this.treeItems.Add(new TreeItemData<ITreeItem>
{
Depth = 0,
Branch = WorkspaceBranch.TEMPORARY_CHATS,
Text = "Temporary chats",
Icon = Icons.Material.Filled.Timer,
Expandable = true,
Path = "temp",
Children = await this.LoadTemporaryChats(),
Value = new TreeItemData
{
Depth = 0,
Branch = WorkspaceBranch.TEMPORARY_CHATS,
Text = "Temporary chats",
Icon = Icons.Material.Filled.Timer,
Expandable = true,
Path = "temp",
Children = await this.LoadTemporaryChats(),
},
});
}
private async Task<HashSet<ITreeItem>> LoadTemporaryChats()
private async Task<IReadOnlyCollection<TreeItemData<ITreeItem>>> LoadTemporaryChats()
{
var tempChildren = new HashSet<ITreeItem>();
var tempChildren = new List<TreeItemData<ITreeItem>>();
//
// Search for workspace folders in the data directory:
@ -115,15 +128,19 @@ public partial class Workspaces : ComponentBase
var chatNamePath = Path.Join(tempChatDirPath, "name");
var chatName = await File.ReadAllTextAsync(chatNamePath, Encoding.UTF8);
tempChildren.Add(new TreeItemData
tempChildren.Add(new TreeItemData<ITreeItem>
{
Type = TreeItemType.CHAT,
Depth = 1,
Branch = WorkspaceBranch.TEMPORARY_CHATS,
Text = chatName,
Icon = Icons.Material.Filled.Timer,
Expandable = false,
Path = tempChatDirPath,
Value = new TreeItemData
{
Type = TreeItemType.CHAT,
Depth = 1,
Branch = WorkspaceBranch.TEMPORARY_CHATS,
Text = chatName,
Icon = Icons.Material.Filled.Timer,
Expandable = false,
Path = tempChatDirPath,
},
});
}
@ -140,9 +157,9 @@ public partial class Workspaces : ComponentBase
return await File.ReadAllTextAsync(workspaceNamePath, Encoding.UTF8);
}
private async Task<HashSet<ITreeItem>> LoadWorkspaces()
private async Task<IReadOnlyCollection<TreeItemData<ITreeItem>>> LoadWorkspaces()
{
var workspaces = new HashSet<ITreeItem>();
var workspaces = new List<TreeItemData<ITreeItem>>();
//
// Search for workspace folders in the data directory:
@ -161,26 +178,34 @@ public partial class Workspaces : ComponentBase
var workspaceNamePath = Path.Join(workspaceDirPath, "name");
var workspaceName = await File.ReadAllTextAsync(workspaceNamePath, Encoding.UTF8);
workspaces.Add(new TreeItemData
workspaces.Add(new TreeItemData<ITreeItem>
{
Type = TreeItemType.WORKSPACE,
Depth = 1,
Branch = WorkspaceBranch.WORKSPACES,
Text = workspaceName,
Icon = Icons.Material.Filled.Description,
Expandable = true,
Path = workspaceDirPath,
Children = await this.LoadWorkspaceChats(workspaceDirPath),
Value = new TreeItemData
{
Type = TreeItemType.WORKSPACE,
Depth = 1,
Branch = WorkspaceBranch.WORKSPACES,
Text = workspaceName,
Icon = Icons.Material.Filled.Description,
Expandable = true,
Path = workspaceDirPath,
Children = await this.LoadWorkspaceChats(workspaceDirPath),
},
});
}
workspaces.Add(new TreeButton(WorkspaceBranch.WORKSPACES, 1, "Add workspace",Icons.Material.Filled.LibraryAdd, this.AddWorkspace));
workspaces.Add(new TreeItemData<ITreeItem>
{
Expandable = false,
Value = new TreeButton(WorkspaceBranch.WORKSPACES, 1, "Add workspace",Icons.Material.Filled.LibraryAdd, this.AddWorkspace),
});
return workspaces;
}
private async Task<HashSet<ITreeItem>> LoadWorkspaceChats(string workspacePath)
private async Task<IReadOnlyCollection<TreeItemData<ITreeItem>>> LoadWorkspaceChats(string workspacePath)
{
var workspaceChats = new HashSet<ITreeItem>();
var workspaceChats = new List<TreeItemData<ITreeItem>>();
// Enumerate the workspace directory:
foreach (var chatPath in Directory.EnumerateDirectories(workspacePath))
@ -189,19 +214,28 @@ public partial class Workspaces : ComponentBase
var chatNamePath = Path.Join(chatPath, "name");
var chatName = await File.ReadAllTextAsync(chatNamePath, Encoding.UTF8);
workspaceChats.Add(new TreeItemData
workspaceChats.Add(new TreeItemData<ITreeItem>
{
Type = TreeItemType.CHAT,
Depth = 2,
Branch = WorkspaceBranch.WORKSPACES,
Text = chatName,
Icon = Icons.Material.Filled.Chat,
Expandable = false,
Path = chatPath,
Value = new TreeItemData
{
Type = TreeItemType.CHAT,
Depth = 2,
Branch = WorkspaceBranch.WORKSPACES,
Text = chatName,
Icon = Icons.Material.Filled.Chat,
Expandable = false,
Path = chatPath,
},
});
}
workspaceChats.Add(new TreeButton(WorkspaceBranch.WORKSPACES, 2, "Add chat",Icons.Material.Filled.AddComment, () => this.AddChat(workspacePath)));
workspaceChats.Add(new TreeItemData<ITreeItem>
{
Expandable = false,
Value = new TreeButton(WorkspaceBranch.WORKSPACES, 2, "Add chat",Icons.Material.Filled.AddComment, () => this.AddChat(workspacePath)),
});
return workspaceChats;
}
@ -247,7 +281,7 @@ public partial class Workspaces : ComponentBase
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Load Chat", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return null;
}
@ -294,7 +328,7 @@ public partial class Workspaces : ComponentBase
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Delete Chat", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
}
@ -331,7 +365,7 @@ public partial class Workspaces : ComponentBase
var dialogReference = await this.DialogService.ShowAsync<SingleInputDialog>("Rename Chat", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
chat.Name = (dialogResult.Data as string)!;
@ -356,7 +390,7 @@ public partial class Workspaces : ComponentBase
var dialogReference = await this.DialogService.ShowAsync<SingleInputDialog>("Rename Workspace", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
var alteredWorkspaceName = (dialogResult.Data as string)!;
@ -377,7 +411,7 @@ public partial class Workspaces : ComponentBase
var dialogReference = await this.DialogService.ShowAsync<SingleInputDialog>("Add Workspace", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
var workspaceId = Guid.NewGuid();
@ -408,7 +442,7 @@ public partial class Workspaces : ComponentBase
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Delete Workspace", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
Directory.Delete(workspacePath, true);
@ -430,7 +464,7 @@ public partial class Workspaces : ComponentBase
var dialogReference = await this.DialogService.ShowAsync<WorkspaceSelectionDialog>("Move Chat to Workspace", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
var workspaceId = dialogResult.Data is Guid id ? id : default;
@ -475,7 +509,7 @@ public partial class Workspaces : ComponentBase
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Create Chat", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
}

View File

@ -151,7 +151,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver
var dialogReference = await this.DialogService.ShowAsync<UpdateDialog>("Update", dialogParameters, DialogOptions.FULLSCREEN_NO_HEADER);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
this.performingUpdate = true;
@ -170,7 +170,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Leave Chat Page", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
{
context.PreventNavigation();
return;

View File

@ -9,14 +9,14 @@
<MudText>
The following list shows the versions of the MindWork AI Studio, the used compilers, build time, etc.:
</MudText>
<MudList Clickable="@true">
<MudListItem Icon="@Icons.Material.Outlined.Chat" Text="@VersionApp"/>
<MudListItem Icon="@Icons.Material.Outlined.Timer" Text="@BuildTime"/>
<MudListItem Icon="@Icons.Material.Outlined.Build" Text="@VersionDotnetSdk"/>
<MudListItem Icon="@Icons.Material.Outlined.Memory" Text="@VersionDotnetRuntime"/>
<MudListItem Icon="@Icons.Material.Outlined.Build" Text="@VersionRust"/>
<MudListItem Icon="@Icons.Material.Outlined.Widgets" Text="@MudBlazorVersion"/>
<MudListItem Icon="@Icons.Material.Outlined.Memory" Text="@TauriVersion"/>
<MudList T="string">
<MudListItem T="string" Icon="@Icons.Material.Outlined.Chat" Text="@VersionApp"/>
<MudListItem T="string" Icon="@Icons.Material.Outlined.Timer" Text="@BuildTime"/>
<MudListItem T="string" Icon="@Icons.Material.Outlined.Build" Text="@VersionDotnetSdk"/>
<MudListItem T="string" Icon="@Icons.Material.Outlined.Memory" Text="@VersionDotnetRuntime"/>
<MudListItem T="string" Icon="@Icons.Material.Outlined.Build" Text="@VersionRust"/>
<MudListItem T="string" Icon="@Icons.Material.Outlined.Widgets" Text="@MudBlazorVersion"/>
<MudListItem T="string" Icon="@Icons.Material.Outlined.Memory" Text="@TauriVersion"/>
</MudList>
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Update" OnClick="() => this.CheckForUpdate()">
Check for updates

View File

@ -235,7 +235,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Delete Chat", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
}
@ -297,7 +297,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
var confirmationDialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Unsaved Changes", confirmationDialogParameters, DialogOptions.FULLSCREEN);
var confirmationDialogResult = await confirmationDialogReference.Result;
if (confirmationDialogResult.Canceled)
if (confirmationDialogResult is null || confirmationDialogResult.Canceled)
return;
}
@ -310,7 +310,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
var dialogReference = await this.DialogService.ShowAsync<WorkspaceSelectionDialog>("Move Chat to Workspace", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
var workspaceId = dialogResult.Data is Guid id ? id : default;

View File

@ -1,5 +1,3 @@
using AIStudio.Provider;
namespace AIStudio.Components.Pages.IconFinder;
public partial class AssistantIconFinder : AssistantBaseCore

View File

@ -31,10 +31,10 @@ public partial class Settings : ComponentBase
var dialogReference = await this.DialogService.ShowAsync<ProviderDialog>("Add Provider", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
var addedProvider = (AIStudio.Settings.Provider)dialogResult.Data;
var addedProvider = (AIStudio.Settings.Provider)dialogResult.Data!;
addedProvider = addedProvider with { Num = this.SettingsManager.ConfigurationData.NextProviderNum++ };
this.SettingsManager.ConfigurationData.Providers.Add(addedProvider);
@ -58,10 +58,10 @@ public partial class Settings : ComponentBase
var dialogReference = await this.DialogService.ShowAsync<ProviderDialog>("Edit Provider", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
var editedProvider = (AIStudio.Settings.Provider)dialogResult.Data;
var editedProvider = (AIStudio.Settings.Provider)dialogResult.Data!;
// Set the provider number if it's not set. This is important for providers
// added before we started saving the provider number.
@ -81,7 +81,7 @@ public partial class Settings : ComponentBase
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Delete Provider", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
if (dialogResult is null || dialogResult.Canceled)
return;
var providerInstance = provider.CreateProvider();

View File

@ -1,4 +1,3 @@
using AIStudio.Provider;
using AIStudio.Tools;
namespace AIStudio.Components.Pages.TextSummarizer;

View File

@ -1,4 +1,3 @@
using AIStudio.Provider;
using AIStudio.Tools;
namespace AIStudio.Components.Pages.Translator;

View File

@ -7,4 +7,5 @@
<MudThemeProvider />
<MudDialogProvider />
<MudPopoverProvider />
<MudSnackbarProvider />

View File

@ -79,10 +79,10 @@
{
<MudPaper Class="pa-2 mt-3">
<MudText Typo="Typo.h6">Issues</MudText>
<MudList Clickable="@true">
<MudList T="string">
@foreach (var issue in this.dataIssues)
{
<MudListItem Icon="@Icons.Material.Filled.Error" IconColor="Color.Error">
<MudListItem T="string" Icon="@Icons.Material.Filled.Error" IconColor="Color.Error">
@issue
</MudListItem>
}