diff --git a/app/MindWork AI Studio/Components/Blocks/TreeItemData.cs b/app/MindWork AI Studio/Components/Blocks/TreeItemData.cs index 2ddedaf..1eaa7d5 100644 --- a/app/MindWork AI Studio/Components/Blocks/TreeItemData.cs +++ b/app/MindWork AI Studio/Components/Blocks/TreeItemData.cs @@ -18,5 +18,7 @@ public class TreeItemData : ITreeItem public bool Expandable { get; init; } = true; + public DateTimeOffset LastEditTime { get; init; } + public IReadOnlyCollection> Children { get; init; } = []; } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs index 19802ef..964e3ed 100644 --- a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs +++ b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs @@ -109,42 +109,44 @@ public partial class Workspaces : ComponentBase private async Task>> LoadTemporaryChats() { - var tempChildren = new List>(); - - // - // Search for workspace folders in the data directory: - // - - // Get the workspace root directory: + var tempChildren = new List(); + + // Get the temp root directory: var temporaryDirectories = Path.Join(SettingsManager.DataDirectory, "tempChats"); // Ensure the directory exists: Directory.CreateDirectory(temporaryDirectories); - // Enumerate the workspace directories: + // Enumerate the chat directories: foreach (var tempChatDirPath in Directory.EnumerateDirectories(temporaryDirectories)) { // Read the `name` file: var chatNamePath = Path.Join(tempChatDirPath, "name"); var chatName = await File.ReadAllTextAsync(chatNamePath, Encoding.UTF8); - - tempChildren.Add(new TreeItemData + + // Read the last change time of the chat: + var chatThreadPath = Path.Join(tempChatDirPath, "thread.json"); + var lastEditTime = File.GetLastWriteTimeUtc(chatThreadPath); + + tempChildren.Add(new TreeItemData { + Type = TreeItemType.CHAT, + Depth = 1, + Branch = WorkspaceBranch.TEMPORARY_CHATS, + Text = chatName, + Icon = Icons.Material.Filled.Timer, Expandable = false, - Value = new TreeItemData - { - Type = TreeItemType.CHAT, - Depth = 1, - Branch = WorkspaceBranch.TEMPORARY_CHATS, - Text = chatName, - Icon = Icons.Material.Filled.Timer, - Expandable = false, - Path = tempChatDirPath, - }, + Path = tempChatDirPath, + LastEditTime = lastEditTime, }); } - - return tempChildren; + + var result = new List>(tempChildren.OrderByDescending(n => n.LastEditTime).Select(n => new TreeItemData + { + Expandable = false, + Value = n, + })); + return result; } public async Task LoadWorkspaceName(Guid workspaceId) @@ -205,7 +207,7 @@ public partial class Workspaces : ComponentBase private async Task>> LoadWorkspaceChats(string workspacePath) { - var workspaceChats = new List>(); + var workspaceChats = new List(); // Enumerate the workspace directory: foreach (var chatPath in Directory.EnumerateDirectories(workspacePath)) @@ -213,30 +215,37 @@ public partial class Workspaces : ComponentBase // Read the `name` file: var chatNamePath = Path.Join(chatPath, "name"); var chatName = await File.ReadAllTextAsync(chatNamePath, Encoding.UTF8); + + // Read the last change time of the chat: + var chatThreadPath = Path.Join(chatPath, "thread.json"); + var lastEditTime = File.GetLastWriteTimeUtc(chatThreadPath); - workspaceChats.Add(new TreeItemData + workspaceChats.Add(new TreeItemData { + Type = TreeItemType.CHAT, + Depth = 2, + Branch = WorkspaceBranch.WORKSPACES, + Text = chatName, + Icon = Icons.Material.Filled.Chat, Expandable = false, - Value = new TreeItemData - { - Type = TreeItemType.CHAT, - Depth = 2, - Branch = WorkspaceBranch.WORKSPACES, - Text = chatName, - Icon = Icons.Material.Filled.Chat, - Expandable = false, - Path = chatPath, - }, + Path = chatPath, + LastEditTime = lastEditTime, }); } - - workspaceChats.Add(new TreeItemData + + var result = new List>(workspaceChats.OrderByDescending(n => n.LastEditTime).Select(n => new TreeItemData + { + Expandable = false, + Value = n, + })); + + result.Add(new() { Expandable = false, Value = new TreeButton(WorkspaceBranch.WORKSPACES, 2, "Add chat",Icons.Material.Filled.AddComment, () => this.AddChat(workspacePath)), }); - return workspaceChats; + return result; } public async Task StoreChat(ChatThread chat) diff --git a/app/MindWork AI Studio/wwwroot/changelog/v0.8.11.md b/app/MindWork AI Studio/wwwroot/changelog/v0.8.11.md new file mode 100644 index 0000000..4b068c2 --- /dev/null +++ b/app/MindWork AI Studio/wwwroot/changelog/v0.8.11.md @@ -0,0 +1,2 @@ +# v0.8.11, build 173 +- Fixed a bug where the chats in the workspace component were not sorted by date. \ No newline at end of file