mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 11:39:48 +00:00
Check unsaved changes from the workspace component
This commit is contained in:
parent
562276ed3f
commit
4f8a6533c3
@ -5,6 +5,7 @@ using System.Text.Json.Serialization;
|
|||||||
using AIStudio.Chat;
|
using AIStudio.Chat;
|
||||||
using AIStudio.Components.CommonDialogs;
|
using AIStudio.Components.CommonDialogs;
|
||||||
using AIStudio.Settings;
|
using AIStudio.Settings;
|
||||||
|
using AIStudio.Tools;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
@ -235,6 +236,20 @@ public partial class Workspaces : ComponentBase
|
|||||||
|
|
||||||
if(!Directory.Exists(chatPath))
|
if(!Directory.Exists(chatPath))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
// Check if the chat has unsaved changes:
|
||||||
|
if (switchToChat && await MessageBus.INSTANCE.SendMessageUseFirstResult<bool, bool>(this, Event.HAS_CHAT_UNSAVED_CHANGES))
|
||||||
|
{
|
||||||
|
var dialogParameters = new DialogParameters
|
||||||
|
{
|
||||||
|
{ "Message", "Are you sure you want to load another chat? All unsaved changes will be lost." },
|
||||||
|
};
|
||||||
|
|
||||||
|
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Load Chat", dialogParameters, DialogOptions.FULLSCREEN);
|
||||||
|
var dialogResult = await dialogReference.Result;
|
||||||
|
if (dialogResult.Canceled)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -450,6 +465,20 @@ public partial class Workspaces : ComponentBase
|
|||||||
|
|
||||||
private async Task AddChat(string workspacePath)
|
private async Task AddChat(string workspacePath)
|
||||||
{
|
{
|
||||||
|
// Check if the chat has unsaved changes:
|
||||||
|
if (await MessageBus.INSTANCE.SendMessageUseFirstResult<bool, bool>(this, Event.HAS_CHAT_UNSAVED_CHANGES))
|
||||||
|
{
|
||||||
|
var dialogParameters = new DialogParameters
|
||||||
|
{
|
||||||
|
{ "Message", "Are you sure you want to create a another chat? All unsaved changes will be lost." },
|
||||||
|
};
|
||||||
|
|
||||||
|
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Create Chat", dialogParameters, DialogOptions.FULLSCREEN);
|
||||||
|
var dialogResult = await dialogReference.Result;
|
||||||
|
if (dialogResult.Canceled)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var workspaceId = Guid.Parse(Path.GetFileName(workspacePath));
|
var workspaceId = Guid.Parse(Path.GetFileName(workspacePath));
|
||||||
var chat = new ChatThread
|
var chat = new ChatThread
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
@using AIStudio.Chat
|
@using AIStudio.Chat
|
||||||
@using AIStudio.Settings
|
@using AIStudio.Settings
|
||||||
|
|
||||||
|
@inherits AIStudio.Tools.MSGComponentBase
|
||||||
|
|
||||||
<MudText Typo="Typo.h3" Class="mb-2 mr-3">
|
<MudText Typo="Typo.h3" Class="mb-2 mr-3">
|
||||||
@if (this.chatThread is not null && this.chatThread.WorkspaceId != Guid.Empty)
|
@if (this.chatThread is not null && this.chatThread.WorkspaceId != Guid.Empty)
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@ using AIStudio.Components.Blocks;
|
|||||||
using AIStudio.Components.CommonDialogs;
|
using AIStudio.Components.CommonDialogs;
|
||||||
using AIStudio.Provider;
|
using AIStudio.Provider;
|
||||||
using AIStudio.Settings;
|
using AIStudio.Settings;
|
||||||
|
using AIStudio.Tools;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Web;
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
@ -14,7 +15,7 @@ namespace AIStudio.Components.Pages;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The chat page.
|
/// The chat page.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class Chat : ComponentBase, IAsyncDisposable
|
public partial class Chat : MSGComponentBase, IAsyncDisposable
|
||||||
{
|
{
|
||||||
[Inject]
|
[Inject]
|
||||||
private SettingsManager SettingsManager { get; set; } = null!;
|
private SettingsManager SettingsManager { get; set; } = null!;
|
||||||
@ -50,6 +51,8 @@ public partial class Chat : ComponentBase, IAsyncDisposable
|
|||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
|
this.ApplyFilters([], [ Event.HAS_CHAT_UNSAVED_CHANGES ]);
|
||||||
|
|
||||||
// Configure the spellchecking for the user input:
|
// Configure the spellchecking for the user input:
|
||||||
this.SettingsManager.InjectSpellchecking(USER_INPUT_ATTRIBUTES);
|
this.SettingsManager.InjectSpellchecking(USER_INPUT_ATTRIBUTES);
|
||||||
|
|
||||||
@ -332,6 +335,29 @@ public partial class Chat : ComponentBase, IAsyncDisposable
|
|||||||
await this.inputField.Clear();
|
await this.inputField.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Overrides of MSGComponentBase
|
||||||
|
|
||||||
|
public override Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data) where TResult : default where TPayload : default
|
||||||
|
{
|
||||||
|
switch (triggeredEvent)
|
||||||
|
{
|
||||||
|
case Event.HAS_CHAT_UNSAVED_CHANGES:
|
||||||
|
if(this.SettingsManager.ConfigurationData.WorkspaceStorageBehavior is WorkspaceStorageBehavior.STORE_CHATS_AUTOMATICALLY)
|
||||||
|
return Task.FromResult((TResult?) (object) false);
|
||||||
|
|
||||||
|
return Task.FromResult((TResult?)(object)this.hasUnsavedChanges);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult(default(TResult));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Implementation of IAsyncDisposable
|
#region Implementation of IAsyncDisposable
|
||||||
|
|
||||||
public async ValueTask DisposeAsync()
|
public async ValueTask DisposeAsync()
|
||||||
|
Loading…
Reference in New Issue
Block a user