mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-13 11:22:27 +00:00
Improved dialog handling
This commit is contained in:
parent
3918d7d674
commit
6d8b59bb02
@ -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<WorkspaceSelectionDialog>(T("Move Chat to Workspace"), dialogParameters, DialogOptions.FULLSCREEN);
|
||||
var dialogReference = await this.DialogService.ShowAsync<WorkspaceSelectionDialog>(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:
|
||||
|
||||
@ -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<WorkspaceSelectionDialog>(T("Move Chat to Workspace"), dialogParameters, DialogOptions.FULLSCREEN);
|
||||
var dialogReference = await this.DialogService.ShowAsync<WorkspaceSelectionDialog>(T("Move Chat to Workspace"), dialogParameters, DialogOptions.FULLSCREEN_MANUAL_ESCAPE);
|
||||
var dialogResult = await dialogReference.Result;
|
||||
if (dialogResult is null || dialogResult.Canceled)
|
||||
return;
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
||||
@ -1,59 +1,63 @@
|
||||
@inherits MSGComponentBase
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudText Typo="Typo.body1">
|
||||
@this.Message
|
||||
</MudText>
|
||||
<MudList T="Guid" @bind-SelectedValue="@this.selectedWorkspace">
|
||||
@foreach (var workspace in this.workspaces)
|
||||
{
|
||||
<MudListItem Text="@workspace.Name" Icon="@Icons.Material.Filled.Description" Value="@workspace.WorkspaceId" />
|
||||
}
|
||||
</MudList>
|
||||
<div @onkeydown="@this.HandleDialogKeyDown">
|
||||
<MudText Typo="Typo.body1">
|
||||
@this.Message
|
||||
</MudText>
|
||||
<MudList T="Guid" @bind-SelectedValue="@this.selectedWorkspace">
|
||||
@foreach (var workspace in this.workspaces)
|
||||
{
|
||||
<MudListItem Text="@workspace.Name" Icon="@Icons.Material.Filled.Description" Value="@workspace.WorkspaceId" />
|
||||
}
|
||||
</MudList>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudStack Style="width: 100%;" Spacing="2">
|
||||
<MudDivider/>
|
||||
<div style="width: 100%;" @onkeydown="@this.HandleDialogKeyDown">
|
||||
<MudStack Style="width: 100%;" Spacing="2">
|
||||
<MudDivider/>
|
||||
|
||||
@if (this.showCreateWorkspaceForm)
|
||||
{
|
||||
<MudForm @ref="this.createWorkspaceForm">
|
||||
<MudTextField T="string"
|
||||
@bind-Text="@this.newWorkspaceName"
|
||||
Variant="Variant.Outlined"
|
||||
AutoGrow="@false"
|
||||
Lines="1"
|
||||
Label="@T("Workspace name")"
|
||||
Immediate="@true"
|
||||
Disabled="@this.isCreatingWorkspace"
|
||||
OnKeyDown="@this.HandleNewWorkspaceNameKeyDown"
|
||||
Validation="@this.ValidateNewWorkspaceName" />
|
||||
</MudForm>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton StartIcon="@Icons.Material.Filled.LibraryAdd" Variant="Variant.Filled" OnClick="@this.ShowCreateWorkspaceForm">
|
||||
@T("Create new workspace")
|
||||
</MudButton>
|
||||
}
|
||||
|
||||
<MudStack Row="@true" Justify="Justify.FlexEnd" AlignItems="AlignItems.Center" Wrap="Wrap.NoWrap" Spacing="2">
|
||||
<MudButton OnClick="@this.Cancel" Variant="Variant.Filled">
|
||||
@T("Cancel")
|
||||
</MudButton>
|
||||
@if (this.showCreateWorkspaceForm)
|
||||
{
|
||||
<MudButton OnClick="@this.CreateWorkspaceAsync" Variant="Variant.Filled" Color="Color.Info" Disabled="@this.isCreatingWorkspace">
|
||||
@T("Add workspace")
|
||||
</MudButton>
|
||||
<MudForm @ref="this.createWorkspaceForm">
|
||||
<MudTextField T="string"
|
||||
@bind-Text="@this.newWorkspaceName"
|
||||
Variant="Variant.Outlined"
|
||||
AutoGrow="@false"
|
||||
Lines="1"
|
||||
Label="@T("Workspace name")"
|
||||
Immediate="@true"
|
||||
Disabled="@this.isCreatingWorkspace"
|
||||
OnKeyDown="@this.HandleNewWorkspaceNameKeyDown"
|
||||
Validation="@this.ValidateNewWorkspaceName" />
|
||||
</MudForm>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton OnClick="@this.Confirm" Variant="Variant.Filled" Color="Color.Info" Disabled="@(this.selectedWorkspace == Guid.Empty)">
|
||||
@this.ConfirmText
|
||||
<MudButton StartIcon="@Icons.Material.Filled.LibraryAdd" Variant="Variant.Filled" OnClick="@this.ShowCreateWorkspaceForm">
|
||||
@T("Create new workspace")
|
||||
</MudButton>
|
||||
}
|
||||
|
||||
<MudStack Row="@true" Justify="Justify.FlexEnd" AlignItems="AlignItems.Center" Wrap="Wrap.NoWrap" Spacing="2">
|
||||
<MudButton OnClick="@this.Cancel" Variant="Variant.Filled">
|
||||
@T("Cancel")
|
||||
</MudButton>
|
||||
@if (this.showCreateWorkspaceForm)
|
||||
{
|
||||
<MudButton OnClick="@this.CreateWorkspaceAsync" Variant="Variant.Filled" Color="Color.Info" Disabled="@this.isCreatingWorkspace">
|
||||
@T("Add workspace")
|
||||
</MudButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton OnClick="@this.Confirm" Variant="Variant.Filled" Color="Color.Info" Disabled="@(this.selectedWorkspace == Guid.Empty)">
|
||||
@this.ConfirmText
|
||||
</MudButton>
|
||||
}
|
||||
</MudStack>
|
||||
</MudStack>
|
||||
</MudStack>
|
||||
</div>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
@ -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;
|
||||
|
||||
@ -155,6 +155,11 @@ public enum Event
|
||||
/// Requests the chat workspace overlay to be toggled.
|
||||
/// </summary>
|
||||
WORKSPACE_TOGGLE_OVERLAY,
|
||||
|
||||
/// <summary>
|
||||
/// Notifies receivers that a workspace was renamed.
|
||||
/// </summary>
|
||||
WORKSPACE_RENAMED,
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user