diff --git a/app/MindWork AI Studio/Components/Blocks/TreeItemData.cs b/app/MindWork AI Studio/Components/Blocks/TreeItemData.cs index aef9e065..f0f1f617 100644 --- a/app/MindWork AI Studio/Components/Blocks/TreeItemData.cs +++ b/app/MindWork AI Studio/Components/Blocks/TreeItemData.cs @@ -10,7 +10,7 @@ public class TreeItemData : ITreeItem public string Icon { get; init; } = string.Empty; - public bool IsChat { get; init; } + public TreeItemType Type { get; init; } public string Path { get; init; } = string.Empty; diff --git a/app/MindWork AI Studio/Components/Blocks/TreeItemType.cs b/app/MindWork AI Studio/Components/Blocks/TreeItemType.cs new file mode 100644 index 00000000..de860ab9 --- /dev/null +++ b/app/MindWork AI Studio/Components/Blocks/TreeItemType.cs @@ -0,0 +1,9 @@ +namespace AIStudio.Components.Blocks; + +public enum TreeItemType +{ + NONE, + + CHAT, + WORKSPACE, +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor index 36b702eb..eeaaed5a 100644 --- a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor +++ b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor @@ -9,9 +9,9 @@ break; case TreeItemData treeItem: - @if (treeItem.IsChat) + @if (treeItem.Type is TreeItemType.CHAT) { - +
@treeItem.Text @@ -28,9 +28,28 @@ } + else if (treeItem.Type is TreeItemType.WORKSPACE) + { + + +
+ @treeItem.Text +
+ + + + + + + +
+
+
+
+ } else { - +
@treeItem.Text diff --git a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs index fce9295a..63c77a5c 100644 --- a/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs +++ b/app/MindWork AI Studio/Components/Blocks/Workspaces.razor.cs @@ -108,7 +108,7 @@ public partial class Workspaces : ComponentBase tempChildren.Add(new TreeItemData { - IsChat = true, + Type = TreeItemType.CHAT, Depth = 1, Branch = WorkspaceBranch.TEMPORARY_CHATS, Text = chatName, @@ -154,7 +154,7 @@ public partial class Workspaces : ComponentBase workspaces.Add(new TreeItemData { - IsChat = false, + Type = TreeItemType.WORKSPACE, Depth = 1, Branch = WorkspaceBranch.WORKSPACES, Text = workspaceName, @@ -182,7 +182,7 @@ public partial class Workspaces : ComponentBase workspaceChats.Add(new TreeItemData { - IsChat = true, + Type = TreeItemType.CHAT, Depth = 2, Branch = WorkspaceBranch.WORKSPACES, Text = chatName, @@ -308,6 +308,31 @@ public partial class Workspaces : ComponentBase await this.StoreChat(chat); await this.LoadTreeItems(); } + + private async Task RenameWorkspace(string? workspacePath) + { + if(workspacePath is null) + return; + + var workspaceId = Guid.Parse(Path.GetFileName(workspacePath)); + var workspaceName = await this.LoadWorkspaceName(workspaceId); + var dialogParameters = new DialogParameters + { + { "Message", $"Please enter a new or edit the name for your workspace '{workspaceName}':" }, + { "UserInput", workspaceName }, + { "ConfirmText", "Rename" }, + }; + + var dialogReference = await this.DialogService.ShowAsync("Rename Workspace", dialogParameters, DialogOptions.FULLSCREEN); + var dialogResult = await dialogReference.Result; + if (dialogResult.Canceled) + return; + + var alteredWorkspaceName = (dialogResult.Data as string)!; + var workspaceNamePath = Path.Join(workspacePath, "name"); + await File.WriteAllTextAsync(workspaceNamePath, alteredWorkspaceName, Encoding.UTF8); + await this.LoadTreeItems(); + } private async Task AddWorkspace() { @@ -333,6 +358,31 @@ public partial class Workspaces : ComponentBase await this.LoadTreeItems(); } + private async Task DeleteWorkspace(string? workspacePath) + { + if(workspacePath is null) + return; + + var workspaceId = Guid.Parse(Path.GetFileName(workspacePath)); + var workspaceName = await this.LoadWorkspaceName(workspaceId); + + // Determine how many chats are in the workspace: + var chatCount = Directory.EnumerateDirectories(workspacePath).Count(); + + var dialogParameters = new DialogParameters + { + { "Message", $"Are you sure you want to delete the workspace '{workspaceName}'? This will also delete {chatCount} chat(s) in this workspace." }, + }; + + var dialogReference = await this.DialogService.ShowAsync("Delete Workspace", dialogParameters, DialogOptions.FULLSCREEN); + var dialogResult = await dialogReference.Result; + if (dialogResult.Canceled) + return; + + Directory.Delete(workspacePath, true); + await this.LoadTreeItems(); + } + private async Task AddChat(string workspacePath) {