Add workspaces & persistent chats (#23)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2024-07-13 10:37:57 +02:00
1 parent 29263660fc
commit 59d0321625
43 files changed
+1392 -66

No files matched your search

@@ -10,8 +10,8 @@
<MudTooltip Text="Home" Placement="Placement.Right">
<MudNavLink Href="/" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Home">Home</MudNavLink>
</MudTooltip>
<MudTooltip Text="Chats" Placement="Placement.Right">
<MudNavLink Href="/chat" Icon="@Icons.Material.Filled.Chat">Chats</MudNavLink>
<MudTooltip Text="Chat" Placement="Placement.Right">
<MudNavLink Href="/chat" Icon="@Icons.Material.Filled.Chat">Chat</MudNavLink>
</MudTooltip>
<MudTooltip Text="Supporters" Placement="Placement.Right">
<MudNavLink Href="/supporters" Icon="@Icons.Material.Filled.Favorite" IconColor="Color.Error">Supporters</MudNavLink>
@@ -3,6 +3,7 @@ using AIStudio.Settings;
using AIStudio.Tools;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Routing;
using DialogOptions = AIStudio.Components.CommonDialogs.DialogOptions;
@@ -27,6 +28,9 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver
[Inject]
private ISnackbar Snackbar { get; init; } = null!;
[Inject]
private NavigationManager NavigationManager { get; init; } = null!;
public string AdditionalHeight { get; private set; } = "0em";
@@ -40,6 +44,8 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver
protected override async Task OnInitializedAsync()
{
this.NavigationManager.RegisterLocationChangingHandler(this.OnLocationChanging);
//
// We use the Tauri API (Rust) to get the data and config directories
// for this app.
@@ -49,7 +55,8 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver
// Store the directories in the settings manager:
SettingsManager.ConfigDirectory = configDir;
SettingsManager.DataDirectory = dataDir;
SettingsManager.DataDirectory = Path.Join(dataDir, "data");
Directory.CreateDirectory(SettingsManager.DataDirectory);
// Ensure that all settings are loaded:
await this.SettingsManager.LoadSettings();
@@ -60,6 +67,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver
// Set the js runtime for the update service:
UpdateService.SetBlazorDependencies(this.JsRuntime, this.Snackbar);
TemporaryChatService.Initialize();
await base.OnInitializedAsync();
}
@@ -91,6 +99,11 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver
}
}
public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
{
return Task.FromResult<TResult?>(default);
}
#endregion
private async Task DismissUpdate()
@@ -145,4 +158,26 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver
this.StateHasChanged();
await this.Rust.InstallUpdate(this.JsRuntime);
}
private async ValueTask OnLocationChanging(LocationChangingContext context)
{
if (await MessageBus.INSTANCE.SendMessageUseFirstResult<bool, bool>(this, Event.HAS_CHAT_UNSAVED_CHANGES))
{
var dialogParameters = new DialogParameters
{
{ "Message", "Are you sure you want to leave the chat page? All unsaved changes will be lost." },
};
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Leave Chat Page", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult.Canceled)
{
context.PreventNavigation();
return;
}
// User accepted to leave the chat page, reset the chat state:
await MessageBus.INSTANCE.SendMessage<bool>(this, Event.RESET_CHAT_STATE);
}
}
}