diff --git a/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor b/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor
index 86433c7..f45ebba 100644
--- a/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor
+++ b/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor
@@ -76,7 +76,20 @@
}
-
@msg.text
+
+ @if (msg.FileContent != null && msg.FileContent.Length > 0 && !string.IsNullOrWhiteSpace(msg.FileType) && msg.FileType.StartsWith("image/"))
+ {
+

+ @if (!string.IsNullOrWhiteSpace(msg.text))
+ {
+
@msg.text
+ }
+ }
+ else
+ {
+ @msg.text
+ }
+
@if (msg.Type == Common.Enums.ConversationType.UE)
{
if (msg.IsRead)
@@ -140,10 +153,18 @@
}
@@ -185,6 +206,9 @@
List
CompanyGroups = new();
ChatItemDto? LastOpenChat = new();
string MsgInput = string.Empty;
+ IBrowserFile? SelectedImageFile = null;
+ byte[]? SelectedImageBytes = null;
+ string? SelectedImagePreview = null;
bool chatloading = false;
public bool IsLogin { get; set; } = false;
public bool IsEndFirstProcess { get; set; } = false;
@@ -218,12 +242,27 @@
@functions {
async Task OnClickSendMsg()
{
- if (!string.IsNullOrEmpty(MsgInput))
+ if (!string.IsNullOrEmpty(MsgInput) || SelectedImageFile != null)
{
if (LastOpenChat != null)
{
Common.Enums.ConversationType type = Common.Enums.ConversationType.UE;
- var model = await chatService.ADDChatResponse(LastOpenChat.ID, MsgInput, type);
+ ChatItemResponseDto? model;
+ if (SelectedImageFile != null)
+ {
+ var bytes = SelectedImageBytes ?? Array.Empty();
+ model = await chatService.ADDChatResponse(
+ LastOpenChat.ID,
+ MsgInput,
+ type,
+ SelectedImageFile.Name,
+ SelectedImageFile.ContentType,
+ bytes);
+ }
+ else
+ {
+ model = await chatService.ADDChatResponse(LastOpenChat.ID, MsgInput, type);
+ }
LastOpenChat?.Responses.Add(model);
LastOpenChat.LastText = MsgInput;
@@ -250,6 +289,9 @@
// Scroll to bottom for user's own messages
await JS.InvokeVoidAsync("scrollToBottom", "B1");
MsgInput = string.Empty;
+ SelectedImageFile = null;
+ SelectedImageBytes = null;
+ SelectedImagePreview = null;
}
}
@@ -439,6 +481,33 @@
}
}
+@functions {
+ private async Task OnImageSelected(InputFileChangeEventArgs e)
+ {
+ var file = e.File;
+ if (file is null)
+ {
+ SelectedImageFile = null;
+ SelectedImageBytes = null;
+ SelectedImagePreview = null;
+ return;
+ }
+
+ SelectedImageFile = file;
+ using var memoryStream = new MemoryStream();
+ await file.OpenReadStream().CopyToAsync(memoryStream);
+ SelectedImageBytes = memoryStream.ToArray();
+ SelectedImagePreview = $"data:{file.ContentType};base64,{Convert.ToBase64String(SelectedImageBytes)}";
+ }
+
+ private Task ClearSelectedImage()
+ {
+ SelectedImageFile = null;
+ SelectedImageBytes = null;
+ SelectedImagePreview = null;
+ return Task.CompletedTask;
+ }
+}