diff --git a/app/MindWork AI Studio/Components/ChatComponent.razor.cs b/app/MindWork AI Studio/Components/ChatComponent.razor.cs index ded3427f..62caf008 100644 --- a/app/MindWork AI Studio/Components/ChatComponent.razor.cs +++ b/app/MindWork AI Studio/Components/ChatComponent.razor.cs @@ -101,7 +101,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable protected override async Task OnInitializedAsync() { // Apply the filters for the message bus: - this.ApplyFilters([], [ Event.HAS_CHAT_UNSAVED_CHANGES, Event.RESET_CHAT_STATE, Event.CHAT_STREAMING_DONE, Event.AI_JOB_CHANGED, Event.AI_JOB_FINISHED, Event.CHAT_GENERATION_CHANGED ]); + this.ApplyFilters([], [ Event.HAS_CHAT_UNSAVED_CHANGES, Event.RESET_CHAT_STATE, Event.CHAT_STREAMING_DONE, Event.AI_JOB_CHANGED, Event.AI_JOB_FINISHED, Event.CHAT_GENERATION_CHANGED, Event.WORKSPACE_RENAMED ]); // Configure the spellchecking for the user input: this.SettingsManager.InjectSpellchecking(USER_INPUT_ATTRIBUTES); @@ -377,6 +377,29 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable this.WorkspaceName(this.currentWorkspaceName); } + private async Task RefreshRenamedWorkspaceHeaderAsync(Guid workspaceId) + { + var currentChatThread = this.ChatThread; + if (currentChatThread is null || currentChatThread.WorkspaceId != workspaceId) + return; + + var syncVersion = Interlocked.Increment(ref this.workspaceHeaderSyncVersion); + var chatThreadId = currentChatThread.ChatId; + var loadedWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceNameAsync(workspaceId); + + if (syncVersion != this.workspaceHeaderSyncVersion) + return; + + if (this.ChatThread is null + || this.ChatThread.ChatId != chatThreadId + || this.ChatThread.WorkspaceId != workspaceId) + return; + + this.currentChatThreadId = chatThreadId; + this.currentWorkspaceId = workspaceId; + this.PublishWorkspaceNameIfChanged(loadedWorkspaceName); + } + private async Task SyncForegroundChatAsync() { var nextForegroundChatId = this.ChatThread?.ChatId ?? Guid.Empty; @@ -864,7 +887,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable { x => x.ConfirmText, T("Move chat") }, }; - var dialogReference = await this.DialogService.ShowAsync(T("Move Chat to Workspace"), dialogParameters, DialogOptions.FULLSCREEN); + var dialogReference = await this.DialogService.ShowAsync(T("Move Chat to Workspace"), dialogParameters, DialogOptions.FULLSCREEN_MANUAL_ESCAPE); var dialogResult = await dialogReference.Result; if (dialogResult is null || dialogResult.Canceled) return; @@ -1046,6 +1069,11 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable if(this.autoSaveEnabled) await this.SaveThread(); break; + + case Event.WORKSPACE_RENAMED: + if (data is Guid workspaceId) + await this.RefreshRenamedWorkspaceHeaderAsync(workspaceId); + break; case Event.AI_JOB_CHANGED: case Event.AI_JOB_FINISHED: diff --git a/app/MindWork AI Studio/Components/Workspaces.razor.cs b/app/MindWork AI Studio/Components/Workspaces.razor.cs index 49b99b2d..2a2164ba 100644 --- a/app/MindWork AI Studio/Components/Workspaces.razor.cs +++ b/app/MindWork AI Studio/Components/Workspaces.razor.cs @@ -752,6 +752,7 @@ public partial class Workspaces : MSGComponentBase if (!await WorkspaceBehaviour.RenameWorkspaceAsync(workspaceId, alteredWorkspaceName)) return; + await this.SendMessage(Event.WORKSPACE_RENAMED, workspaceId); await this.LoadTreeItemsAsync(startPrefetch: false); } @@ -822,7 +823,7 @@ public partial class Workspaces : MSGComponentBase { x => x.ConfirmText, T("Move chat") }, }; - var dialogReference = await this.DialogService.ShowAsync(T("Move Chat to Workspace"), dialogParameters, DialogOptions.FULLSCREEN); + var dialogReference = await this.DialogService.ShowAsync(T("Move Chat to Workspace"), dialogParameters, DialogOptions.FULLSCREEN_MANUAL_ESCAPE); var dialogResult = await dialogReference.Result; if (dialogResult is null || dialogResult.Canceled) return; diff --git a/app/MindWork AI Studio/Dialogs/DialogOptions.cs b/app/MindWork AI Studio/Dialogs/DialogOptions.cs index e2373824..ddb1d090 100644 --- a/app/MindWork AI Studio/Dialogs/DialogOptions.cs +++ b/app/MindWork AI Studio/Dialogs/DialogOptions.cs @@ -7,6 +7,12 @@ public static class DialogOptions CloseOnEscapeKey = true, FullWidth = true, MaxWidth = MaxWidth.Medium, }; + + public static readonly MudBlazor.DialogOptions FULLSCREEN_MANUAL_ESCAPE = new() + { + CloseOnEscapeKey = false, + FullWidth = true, MaxWidth = MaxWidth.Medium, + }; public static readonly MudBlazor.DialogOptions FULLSCREEN_NO_HEADER = new() { diff --git a/app/MindWork AI Studio/Dialogs/WorkspaceSelectionDialog.razor b/app/MindWork AI Studio/Dialogs/WorkspaceSelectionDialog.razor index 3e0cee72..33522b55 100644 --- a/app/MindWork AI Studio/Dialogs/WorkspaceSelectionDialog.razor +++ b/app/MindWork AI Studio/Dialogs/WorkspaceSelectionDialog.razor @@ -1,59 +1,63 @@ @inherits MSGComponentBase - - @this.Message - - - @foreach (var workspace in this.workspaces) - { - - } - +
+ + @this.Message + + + @foreach (var workspace in this.workspaces) + { + + } + +
- - +
+ + - @if (this.showCreateWorkspaceForm) - { - - - - } - else - { - - @T("Create new workspace") - - } - - - - @T("Cancel") - @if (this.showCreateWorkspaceForm) { - - @T("Add workspace") - + + + } else { - - @this.ConfirmText + + @T("Create new workspace") } + + + + @T("Cancel") + + @if (this.showCreateWorkspaceForm) + { + + @T("Add workspace") + + } + else + { + + @this.ConfirmText + + } + - +
\ No newline at end of file diff --git a/app/MindWork AI Studio/Dialogs/WorkspaceSelectionDialog.razor.cs b/app/MindWork AI Studio/Dialogs/WorkspaceSelectionDialog.razor.cs index 50ca9106..b5020325 100644 --- a/app/MindWork AI Studio/Dialogs/WorkspaceSelectionDialog.razor.cs +++ b/app/MindWork AI Studio/Dialogs/WorkspaceSelectionDialog.razor.cs @@ -80,6 +80,16 @@ public partial class WorkspaceSelectionDialog : MSGComponentBase await this.CreateWorkspaceAsync(); } + private void HandleDialogKeyDown(KeyboardEventArgs keyEvent) + { + var key = keyEvent.Key.ToLowerInvariant(); + var code = keyEvent.Code.ToLowerInvariant(); + if (key is not "escape" && code is not "escape") + return; + + this.Cancel(); + } + private void ShowCreateWorkspaceForm() { this.createWorkspaceError = null; diff --git a/app/MindWork AI Studio/Tools/Event.cs b/app/MindWork AI Studio/Tools/Event.cs index 8d5f465a..9b21ed87 100644 --- a/app/MindWork AI Studio/Tools/Event.cs +++ b/app/MindWork AI Studio/Tools/Event.cs @@ -155,6 +155,11 @@ public enum Event /// Requests the chat workspace overlay to be toggled. /// WORKSPACE_TOGGLE_OVERLAY, + + /// + /// Notifies receivers that a workspace was renamed. + /// + WORKSPACE_RENAMED,