mirror of
				https://github.com/MindWorkAI/AI-Studio.git
				synced 2025-11-04 08:00:21 +00:00 
			
		
		
		
	Added option to create a workspace
This commit is contained in:
		
							parent
							
								
									72fa028d47
								
							
						
					
					
						commit
						50da92ee29
					
				@ -1,3 +1,3 @@
 | 
				
			|||||||
namespace AIStudio.Components.Blocks;
 | 
					namespace AIStudio.Components.Blocks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public readonly record struct TreeButton(WorkspaceBranch Branch, int Depth, string Text, string Icon) : ITreeItem;
 | 
					public readonly record struct TreeButton(WorkspaceBranch Branch, int Depth, string Text, string Icon, Func<Task> Action) : ITreeItem;
 | 
				
			||||||
@ -44,7 +44,7 @@
 | 
				
			|||||||
                <li>
 | 
					                <li>
 | 
				
			||||||
                    <div class="mud-treeview-item-content" style="background-color: unset;">
 | 
					                    <div class="mud-treeview-item-content" style="background-color: unset;">
 | 
				
			||||||
                        <div class="mud-treeview-item-arrow"></div>
 | 
					                        <div class="mud-treeview-item-arrow"></div>
 | 
				
			||||||
                        <MudButton StartIcon="@treeButton.Icon" Variant="Variant.Filled">
 | 
					                        <MudButton StartIcon="@treeButton.Icon" Variant="Variant.Filled" OnClick="treeButton.Action">
 | 
				
			||||||
                            @treeButton.Text
 | 
					                            @treeButton.Text
 | 
				
			||||||
                        </MudButton>
 | 
					                        </MudButton>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
 | 
				
			|||||||
@ -165,7 +165,7 @@ public partial class Workspaces : ComponentBase
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
                            
 | 
					                            
 | 
				
			||||||
        workspaces.Add(new TreeButton(WorkspaceBranch.WORKSPACES, 1, "Add workspace",Icons.Material.Filled.Add));
 | 
					        workspaces.Add(new TreeButton(WorkspaceBranch.WORKSPACES, 1, "Add workspace",Icons.Material.Filled.Add, this.AddWorkspace));
 | 
				
			||||||
        return workspaces;
 | 
					        return workspaces;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -192,7 +192,7 @@ public partial class Workspaces : ComponentBase
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
                            
 | 
					                            
 | 
				
			||||||
        workspaceChats.Add(new TreeButton(WorkspaceBranch.WORKSPACES, 2, "Add chat",Icons.Material.Filled.Add));
 | 
					        workspaceChats.Add(new TreeButton(WorkspaceBranch.WORKSPACES, 2, "Add chat",Icons.Material.Filled.Add, () => this.AddChat(workspacePath)));
 | 
				
			||||||
        return workspaceChats;
 | 
					        return workspaceChats;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -296,9 +296,10 @@ public partial class Workspaces : ComponentBase
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            { "Message", $"Please enter a new or edit the name for your chat '{chat.Name}':" },
 | 
					            { "Message", $"Please enter a new or edit the name for your chat '{chat.Name}':" },
 | 
				
			||||||
            { "UserInput", chat.Name },
 | 
					            { "UserInput", chat.Name },
 | 
				
			||||||
 | 
					            { "ConfirmText", "Rename" },
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        var dialogReference = await this.DialogService.ShowAsync<RenameDialog>("Rename Chat", dialogParameters, DialogOptions.FULLSCREEN);
 | 
					        var dialogReference = await this.DialogService.ShowAsync<SingleInputDialog>("Rename Chat", dialogParameters, DialogOptions.FULLSCREEN);
 | 
				
			||||||
        var dialogResult = await dialogReference.Result;
 | 
					        var dialogResult = await dialogReference.Result;
 | 
				
			||||||
        if (dialogResult.Canceled)
 | 
					        if (dialogResult.Canceled)
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
@ -307,4 +308,33 @@ public partial class Workspaces : ComponentBase
 | 
				
			|||||||
        await this.StoreChat(chat);
 | 
					        await this.StoreChat(chat);
 | 
				
			||||||
        await this.LoadTreeItems();
 | 
					        await this.LoadTreeItems();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private async Task AddWorkspace()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        var dialogParameters = new DialogParameters
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            { "Message", "Please name your workspace:" },
 | 
				
			||||||
 | 
					            { "UserInput", string.Empty },
 | 
				
			||||||
 | 
					            { "ConfirmText", "Add workspace" },
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        var dialogReference = await this.DialogService.ShowAsync<SingleInputDialog>("Add Workspace", dialogParameters, DialogOptions.FULLSCREEN);
 | 
				
			||||||
 | 
					        var dialogResult = await dialogReference.Result;
 | 
				
			||||||
 | 
					        if (dialogResult.Canceled)
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        var workspaceId = Guid.NewGuid();
 | 
				
			||||||
 | 
					        var workspacePath = Path.Join(SettingsManager.DataDirectory, "workspaces", workspaceId.ToString());
 | 
				
			||||||
 | 
					        Directory.CreateDirectory(workspacePath);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        var workspaceNamePath = Path.Join(workspacePath, "name");
 | 
				
			||||||
 | 
					        await File.WriteAllTextAsync(workspaceNamePath, (dialogResult.Data as string)!, Encoding.UTF8);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        await this.LoadTreeItems();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    private async Task AddChat(string workspacePath)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -5,6 +5,6 @@
 | 
				
			|||||||
    </DialogContent>
 | 
					    </DialogContent>
 | 
				
			||||||
    <DialogActions>
 | 
					    <DialogActions>
 | 
				
			||||||
        <MudButton OnClick="@this.Cancel" Variant="Variant.Filled">Cancel</MudButton>
 | 
					        <MudButton OnClick="@this.Cancel" Variant="Variant.Filled">Cancel</MudButton>
 | 
				
			||||||
        <MudButton OnClick="@this.Confirm" Variant="Variant.Filled" Color="Color.Error">Rename</MudButton>
 | 
					        <MudButton OnClick="@this.Confirm" Variant="Variant.Filled" Color="Color.Error">@this.ConfirmText</MudButton>
 | 
				
			||||||
    </DialogActions>
 | 
					    </DialogActions>
 | 
				
			||||||
</MudDialog>
 | 
					</MudDialog>
 | 
				
			||||||
@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Components;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace AIStudio.Components.CommonDialogs;
 | 
					namespace AIStudio.Components.CommonDialogs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public partial class RenameDialog : ComponentBase
 | 
					public partial class SingleInputDialog : ComponentBase
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    [CascadingParameter]
 | 
					    [CascadingParameter]
 | 
				
			||||||
    private MudDialogInstance MudDialog { get; set; } = null!;
 | 
					    private MudDialogInstance MudDialog { get; set; } = null!;
 | 
				
			||||||
@ -13,6 +13,9 @@ public partial class RenameDialog : ComponentBase
 | 
				
			|||||||
    [Parameter]
 | 
					    [Parameter]
 | 
				
			||||||
    public string UserInput { get; set; } = string.Empty;
 | 
					    public string UserInput { get; set; } = string.Empty;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    [Parameter]
 | 
				
			||||||
 | 
					    public string ConfirmText { get; set; } = "OK";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void Cancel() => this.MudDialog.Cancel();
 | 
					    private void Cancel() => this.MudDialog.Cancel();
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    private void Confirm() => this.MudDialog.Close(DialogResult.Ok(this.UserInput));
 | 
					    private void Confirm() => this.MudDialog.Close(DialogResult.Ok(this.UserInput));
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user