LANCommander/LANCommander.UI/Components/Chat/ChatThread.razor
Pat Hartl e1c1469614 Fix chat component rendering
- Load thread after creation
- Change thread list from DataList to Flex
- Move unread badge to right side of chat thread list item
- Fix avatar rerendering after another message is added to message group
- Add styling to thread list
- Change message input to support markdown and add markdown rendering for message contents
2025-12-30 18:08:20 -06:00

48 lines
No EOL
1.6 KiB
Text

@using System.Collections.Specialized
@using LANCommander.SDK.Services
@using Microsoft.AspNetCore.Components.Web.Virtualization
@inject IChatClient ChatClient
@namespace LANCommander.UI.Components
<Flex Direction="FlexDirection.Vertical">
<div style="flex-grow: 1;">
@if (_thread != null)
{
<Virtualize Items="_thread.MessageGroups" Context="messageGroup">
<ChatMessageGroup
@key="messageGroup.Id"
UserId="@messageGroup.UserId"
UserName="@messageGroup.UserName"
StartedOn="@messageGroup.StartedOn.LocalDateTime">
@foreach (var message in messageGroup.Messages)
{
<ChatMessage Id="@message.Id" Content="@message.Content" SentOn="@message.SentOn"/>
}
</ChatMessageGroup>
</Virtualize>
}
</div>
<ChatMessageInput ThreadId="@Id" />
</Flex>
@code {
[Parameter] public Guid Id { get; set; }
SDK.Models.ChatThread? _thread;
protected override async Task OnParametersSetAsync()
{
if (_thread == null || _thread.Id != Id)
{
_thread = await ChatClient.GetThreadAsync(Id);
_thread.MessageGroups.CollectionChanged += MessageGroupsOnCollectionChanged;
await ChatClient.GetMessagesAsync(Id);
}
}
void MessageGroupsOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
=> InvokeAsync(StateHasChanged);
}