Fixed scrolling issue after send to chat call

This commit is contained in:
Thorsten Sommer 2024-09-05 20:06:58 +02:00
parent 6fbf32d8a2
commit dfc69e28db
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -44,6 +44,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
private bool workspacesVisible; private bool workspacesVisible;
private Workspaces? workspaces; private Workspaces? workspaces;
private bool mustScrollToBottomAfterRender; private bool mustScrollToBottomAfterRender;
private byte scrollRenderCountdown;
// Unfortunately, we need the input field reference to clear it after sending a message. // Unfortunately, we need the input field reference to clear it after sending a message.
// This is necessary because we have to handle the key events ourselves. Otherwise, // This is necessary because we have to handle the key events ourselves. Otherwise,
@ -76,6 +77,13 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
}; };
} }
} }
if (this.SettingsManager.ConfigurationData.Chat.ShowLatestMessageAfterLoading)
{
this.mustScrollToBottomAfterRender = true;
this.scrollRenderCountdown = 2;
this.StateHasChanged();
}
} }
await base.OnInitializedAsync(); await base.OnInitializedAsync();
@ -85,8 +93,15 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
{ {
if(this.mustScrollToBottomAfterRender) if(this.mustScrollToBottomAfterRender)
{ {
await this.scrollingArea.ScrollToBottom(); if (--this.scrollRenderCountdown == 0)
this.mustScrollToBottomAfterRender = false; {
await this.scrollingArea.ScrollToBottom();
this.mustScrollToBottomAfterRender = false;
}
else
{
this.StateHasChanged();
}
} }
await base.OnAfterRenderAsync(firstRender); await base.OnAfterRenderAsync(firstRender);
@ -384,6 +399,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
if (this.SettingsManager.ConfigurationData.Chat.ShowLatestMessageAfterLoading) if (this.SettingsManager.ConfigurationData.Chat.ShowLatestMessageAfterLoading)
{ {
this.mustScrollToBottomAfterRender = true; this.mustScrollToBottomAfterRender = true;
this.scrollRenderCountdown = 2;
this.StateHasChanged(); this.StateHasChanged();
} }
} }