mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-02-05 12:49:07 +00:00
Fixed a bug where the chats in the workspace component were not sorted (#79)
This commit is contained in:
parent
f8e06faea5
commit
a18cb22263
@ -18,5 +18,7 @@ public class TreeItemData : ITreeItem
|
|||||||
|
|
||||||
public bool Expandable { get; init; } = true;
|
public bool Expandable { get; init; } = true;
|
||||||
|
|
||||||
|
public DateTimeOffset LastEditTime { get; init; }
|
||||||
|
|
||||||
public IReadOnlyCollection<TreeItemData<ITreeItem>> Children { get; init; } = [];
|
public IReadOnlyCollection<TreeItemData<ITreeItem>> Children { get; init; } = [];
|
||||||
}
|
}
|
@ -109,42 +109,44 @@ public partial class Workspaces : ComponentBase
|
|||||||
|
|
||||||
private async Task<IReadOnlyCollection<TreeItemData<ITreeItem>>> LoadTemporaryChats()
|
private async Task<IReadOnlyCollection<TreeItemData<ITreeItem>>> LoadTemporaryChats()
|
||||||
{
|
{
|
||||||
var tempChildren = new List<TreeItemData<ITreeItem>>();
|
var tempChildren = new List<TreeItemData>();
|
||||||
|
|
||||||
//
|
// Get the temp root directory:
|
||||||
// Search for workspace folders in the data directory:
|
|
||||||
//
|
|
||||||
|
|
||||||
// Get the workspace root directory:
|
|
||||||
var temporaryDirectories = Path.Join(SettingsManager.DataDirectory, "tempChats");
|
var temporaryDirectories = Path.Join(SettingsManager.DataDirectory, "tempChats");
|
||||||
|
|
||||||
// Ensure the directory exists:
|
// Ensure the directory exists:
|
||||||
Directory.CreateDirectory(temporaryDirectories);
|
Directory.CreateDirectory(temporaryDirectories);
|
||||||
|
|
||||||
// Enumerate the workspace directories:
|
// Enumerate the chat directories:
|
||||||
foreach (var tempChatDirPath in Directory.EnumerateDirectories(temporaryDirectories))
|
foreach (var tempChatDirPath in Directory.EnumerateDirectories(temporaryDirectories))
|
||||||
{
|
{
|
||||||
// Read the `name` file:
|
// Read the `name` file:
|
||||||
var chatNamePath = Path.Join(tempChatDirPath, "name");
|
var chatNamePath = Path.Join(tempChatDirPath, "name");
|
||||||
var chatName = await File.ReadAllTextAsync(chatNamePath, Encoding.UTF8);
|
var chatName = await File.ReadAllTextAsync(chatNamePath, Encoding.UTF8);
|
||||||
|
|
||||||
tempChildren.Add(new TreeItemData<ITreeItem>
|
// 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,
|
Expandable = false,
|
||||||
Value = new TreeItemData
|
Path = tempChatDirPath,
|
||||||
{
|
LastEditTime = lastEditTime,
|
||||||
Type = TreeItemType.CHAT,
|
|
||||||
Depth = 1,
|
|
||||||
Branch = WorkspaceBranch.TEMPORARY_CHATS,
|
|
||||||
Text = chatName,
|
|
||||||
Icon = Icons.Material.Filled.Timer,
|
|
||||||
Expandable = false,
|
|
||||||
Path = tempChatDirPath,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return tempChildren;
|
var result = new List<TreeItemData<ITreeItem>>(tempChildren.OrderByDescending(n => n.LastEditTime).Select(n => new TreeItemData<ITreeItem>
|
||||||
|
{
|
||||||
|
Expandable = false,
|
||||||
|
Value = n,
|
||||||
|
}));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> LoadWorkspaceName(Guid workspaceId)
|
public async Task<string> LoadWorkspaceName(Guid workspaceId)
|
||||||
@ -205,7 +207,7 @@ public partial class Workspaces : ComponentBase
|
|||||||
|
|
||||||
private async Task<IReadOnlyCollection<TreeItemData<ITreeItem>>> LoadWorkspaceChats(string workspacePath)
|
private async Task<IReadOnlyCollection<TreeItemData<ITreeItem>>> LoadWorkspaceChats(string workspacePath)
|
||||||
{
|
{
|
||||||
var workspaceChats = new List<TreeItemData<ITreeItem>>();
|
var workspaceChats = new List<TreeItemData>();
|
||||||
|
|
||||||
// Enumerate the workspace directory:
|
// Enumerate the workspace directory:
|
||||||
foreach (var chatPath in Directory.EnumerateDirectories(workspacePath))
|
foreach (var chatPath in Directory.EnumerateDirectories(workspacePath))
|
||||||
@ -213,30 +215,37 @@ public partial class Workspaces : ComponentBase
|
|||||||
// Read the `name` file:
|
// Read the `name` file:
|
||||||
var chatNamePath = Path.Join(chatPath, "name");
|
var chatNamePath = Path.Join(chatPath, "name");
|
||||||
var chatName = await File.ReadAllTextAsync(chatNamePath, Encoding.UTF8);
|
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<ITreeItem>
|
workspaceChats.Add(new TreeItemData
|
||||||
{
|
{
|
||||||
|
Type = TreeItemType.CHAT,
|
||||||
|
Depth = 2,
|
||||||
|
Branch = WorkspaceBranch.WORKSPACES,
|
||||||
|
Text = chatName,
|
||||||
|
Icon = Icons.Material.Filled.Chat,
|
||||||
Expandable = false,
|
Expandable = false,
|
||||||
Value = new TreeItemData
|
Path = chatPath,
|
||||||
{
|
LastEditTime = lastEditTime,
|
||||||
Type = TreeItemType.CHAT,
|
|
||||||
Depth = 2,
|
|
||||||
Branch = WorkspaceBranch.WORKSPACES,
|
|
||||||
Text = chatName,
|
|
||||||
Icon = Icons.Material.Filled.Chat,
|
|
||||||
Expandable = false,
|
|
||||||
Path = chatPath,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
workspaceChats.Add(new TreeItemData<ITreeItem>
|
var result = new List<TreeItemData<ITreeItem>>(workspaceChats.OrderByDescending(n => n.LastEditTime).Select(n => new TreeItemData<ITreeItem>
|
||||||
|
{
|
||||||
|
Expandable = false,
|
||||||
|
Value = n,
|
||||||
|
}));
|
||||||
|
|
||||||
|
result.Add(new()
|
||||||
{
|
{
|
||||||
Expandable = false,
|
Expandable = false,
|
||||||
Value = new TreeButton(WorkspaceBranch.WORKSPACES, 2, "Add chat",Icons.Material.Filled.AddComment, () => this.AddChat(workspacePath)),
|
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)
|
public async Task StoreChat(ChatThread chat)
|
||||||
|
2
app/MindWork AI Studio/wwwroot/changelog/v0.8.11.md
Normal file
2
app/MindWork AI Studio/wwwroot/changelog/v0.8.11.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# v0.8.11, build 173
|
||||||
|
- Fixed a bug where the chats in the workspace component were not sorted by date.
|
Loading…
Reference in New Issue
Block a user