diff --git a/Components/Pages/Chat.razor b/Components/Pages/Chat.razor
index 5c48253..797ad05 100644
--- a/Components/Pages/Chat.razor
+++ b/Components/Pages/Chat.razor
@@ -3,6 +3,7 @@
@rendermode InteractiveServer
@inject IChatSessionService ChatSessionService
@inject NavigationManager NavigationManager
+@inject IJSRuntime JSRuntime
@using Alchegos.HCI.Models
@using Alchegos.HCI.Services
@implements IAsyncDisposable
@@ -15,7 +16,10 @@
-
+
@if (!string.IsNullOrEmpty(activeSessionId))
{
Active Session: @activeSessionId
@@ -64,10 +68,26 @@ else if (sessionLoadAttempted)
private bool isLoading = false;
private bool sessionLoadAttempted = false;
private string externalWebhookUrl { get; set; } = string.Empty;
-
-
+ private const string WebhookUrlStorageKey = "chatPage_externalWebhookUrl";
+ private bool _hasLoadedFromLocalStorage = false;
private string? _previousSessionId = null;
+ protected override void OnInitialized()
+ {
+ if (!string.IsNullOrEmpty(InitialSessionId))
+ currentSessionIdInput = InitialSessionId;
+ }
+
+ /*protected override async Task OnInitializedAsync()
+ {
+ Console.WriteLine("--- OnInitializedAsync START ---");
+ externalWebhookUrl = await JSRuntime.InvokeAsync("localStorage.getItem", WebhookUrlStorageKey) ?? string.Empty;
+ Console.WriteLine($"Loaded externalWebhookUrl from localStorage: '{externalWebhookUrl}'");
+
+ if (!string.IsNullOrEmpty(InitialSessionId))
+ currentSessionIdInput = InitialSessionId;
+ Console.WriteLine("--- OnInitializedAsync END ---");
+ }*/
protected override async Task OnParametersSetAsync()
{
Console.WriteLine($"--- OnParametersSetAsync START. InitialSessionId: {InitialSessionId} ---");
@@ -97,8 +117,6 @@ else if (sessionLoadAttempted)
}
else
Console.WriteLine("!!! Failed to get/create session in OnParametersSetAsync!");
-
-
isLoading = false;
Console.WriteLine("--- OnParametersSetAsync END. isLoading set to false ---");
@@ -124,16 +142,39 @@ else if (sessionLoadAttempted)
}
}
- protected override void OnInitialized()
- {
- if (!string.IsNullOrEmpty(InitialSessionId))
- currentSessionIdInput = InitialSessionId;
- }
+
protected override async Task OnAfterRenderAsync(bool firstRender)
{
- if (firstRender && !string.IsNullOrEmpty(activeSessionId))
+ if (firstRender && !string.IsNullOrEmpty(activeSessionId) && !_hasLoadedFromLocalStorage)
+ {
await RegisterCallbacksAsync();
+ try
+ {
+ externalWebhookUrl = await JSRuntime.InvokeAsync("localStorage.getItem", WebhookUrlStorageKey) ?? string.Empty;
+ Console.WriteLine($"Loaded externalWebhookUrl from localStorage: '{externalWebhookUrl}'");
+ _hasLoadedFromLocalStorage = true;
+ StateHasChanged();
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Error loading from localStorage in OnAfterRenderAsync: {ex.Message}");
+ }
+
+ await base.OnAfterRenderAsync(firstRender);
+ }
+ }
+
+ private async Task SaveWebhookUrlToLocalStorage()
+ {
+ try
+ {
+ await JSRuntime.InvokeVoidAsync("localStorage.setItem", WebhookUrlStorageKey, externalWebhookUrl);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Error saving to localStorage: {ex.Message}");
+ }
}