...
This commit is contained in:
114
Presentation/HushianWebApp/Pages/Chat.razor
Normal file
114
Presentation/HushianWebApp/Pages/Chat.razor
Normal file
@@ -0,0 +1,114 @@
|
||||
@page "/Chant"
|
||||
@using Common.Dtos.Conversation
|
||||
@using Common.Dtos.Group
|
||||
@using HushianWebApp.Service
|
||||
@inject ChatService chatService
|
||||
@inject GroupService groupService
|
||||
@inject UserService userService
|
||||
@inject IJSRuntime JS
|
||||
@code {
|
||||
public Common.Dtos.CurrentUserInfo CurrentUser { get; set; }
|
||||
List<Read_GroupDto> _Group = new List<Read_GroupDto>();
|
||||
//-------------------------------------
|
||||
bool isSelectedInbox1 = false;
|
||||
public List<ChatItemDto> Inbox1Items { get; set; } = new();
|
||||
bool isSelectedInbox2 = true;
|
||||
public List<ChatItemDto> Inbox2Items { get; set; } = new();
|
||||
bool isSelectedInbox3 = false;
|
||||
public List<ChatItemDto> Inbox3Items { get; set; } = new();
|
||||
/////////////
|
||||
public ChatItemDto? ChatCurrent { get; set; } = null;
|
||||
public string MsgInput { get; set; }
|
||||
}
|
||||
@functions {
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
CurrentUser =await userService.GetCurrentUserInfo();
|
||||
_Group = await groupService.GetGroups();
|
||||
Inbox1Items = await chatService.ChatAwaitingOurResponse();
|
||||
Inbox2Items = await chatService.MyChatsIsInProgress();
|
||||
Inbox3Items = await chatService.MyChatsIsFinished();
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
async Task OnclickInbox(int ID)
|
||||
{
|
||||
switch (ID)
|
||||
{
|
||||
case 1:
|
||||
isSelectedInbox1 = true;
|
||||
isSelectedInbox2 = false;
|
||||
isSelectedInbox3 = false;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
isSelectedInbox2 = true;
|
||||
isSelectedInbox1 = false;
|
||||
isSelectedInbox3 = false;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
isSelectedInbox3 = true;
|
||||
isSelectedInbox2 = false;
|
||||
isSelectedInbox1 = false;
|
||||
break;
|
||||
}
|
||||
ChatCurrent = null;
|
||||
|
||||
}
|
||||
async Task SendMsg()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(MsgInput) && ChatCurrent != null)
|
||||
{
|
||||
Common.Enums.ConversationType type = CurrentUser.Role == "Company" ? Common.Enums.ConversationType.CU : Common.Enums.ConversationType.EU;
|
||||
await chatService.ADDChatResponse(ChatCurrent.ID, MsgInput, type);
|
||||
ChatCurrent?.Responses.Add(new() { text = MsgInput, Type = type });
|
||||
ChatCurrent.LastText = MsgInput;
|
||||
await Task.Yield();
|
||||
await JS.InvokeVoidAsync("scrollToBottom", "B1");
|
||||
MsgInput = string.Empty;
|
||||
}
|
||||
}
|
||||
async Task onClickSelectedCon(int InboxID, Read_ConversationDto conversationDto)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
<style>
|
||||
|
||||
.input-group-text-chat {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: .375rem .75rem;
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
color: var(--bs-body-color);
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
border-radius: var(--bs-border-radius);
|
||||
}
|
||||
|
||||
</style>
|
||||
<script>
|
||||
window.getWindowSize = () => {
|
||||
return {
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight
|
||||
};
|
||||
};
|
||||
|
||||
window.registerResizeCallback = (dotNetHelper) => {
|
||||
window.onresize = () => {
|
||||
dotNetHelper.invokeMethodAsync("OnResize");
|
||||
};
|
||||
};
|
||||
|
||||
window.scrollToBottom = (elementId) => {
|
||||
const el = document.getElementById(elementId);
|
||||
if (el) {
|
||||
el.scrollTop = el.scrollHeight;
|
||||
}
|
||||
};
|
||||
</script>
|
62
Presentation/HushianWebApp/Service/ChatService.cs
Normal file
62
Presentation/HushianWebApp/Service/ChatService.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Common.Dtos.Conversation;
|
||||
using Common.Enums;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace HushianWebApp.Service
|
||||
{
|
||||
public class ChatService
|
||||
{
|
||||
private readonly BaseController _baseController;
|
||||
const string BaseRoute = "v1/Chat/";
|
||||
|
||||
//Inbox1
|
||||
public async Task<List<ChatItemDto>> ChatAwaitingOurResponse()
|
||||
{
|
||||
var response = await _baseController.Get($"{BaseRoute}ChatsAwaitingOurResponse");
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.Content.ReadFromJsonAsync<List<ChatItemDto>>();
|
||||
|
||||
return new();
|
||||
}
|
||||
//Inbox2
|
||||
public async Task<List<ChatItemDto>> MyChatsIsInProgress()
|
||||
{
|
||||
var response = await _baseController.Post($"{BaseRoute}MyChats", ConversationStatus.InProgress);
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.Content.ReadFromJsonAsync<List<ChatItemDto>>();
|
||||
|
||||
return new();
|
||||
}
|
||||
//Inbox3
|
||||
public async Task<List<ChatItemDto>> MyChatsIsFinished()
|
||||
{
|
||||
var response = await _baseController.Post($"{BaseRoute}MyChats", ConversationStatus.Finished);
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.Content.ReadFromJsonAsync<List<ChatItemDto>>();
|
||||
|
||||
return new();
|
||||
}
|
||||
public async Task<ChatItemDto> NewChatFromCurrentUser(ADD_ConversationDto conversation)
|
||||
{
|
||||
var response = await _baseController.Post($"{BaseRoute}NewChatFromCurrentUser", conversation);
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.Content.ReadFromJsonAsync<ChatItemDto>();
|
||||
|
||||
return null;
|
||||
}
|
||||
public async Task<ChatItemResponseDto?> ADDChatResponse(int ConversationID, string text, ConversationType type)
|
||||
{
|
||||
var response = await _baseController.Post($"{BaseRoute}ADDChatResponse", new ADD_ConversationResponseDto()
|
||||
{
|
||||
ConversationID = ConversationID,
|
||||
Text = text,
|
||||
Type = type
|
||||
});
|
||||
if (response.IsSuccessStatusCode)
|
||||
return await response.Content.ReadFromJsonAsync<ChatItemResponseDto>();
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -39,6 +39,15 @@ namespace HushianWebApp.Service
|
||||
var response = await _baseController.Delete ($"{BaseRoute}DeleteGroup/{GroupID}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
public async Task<List<Read_GroupDto>?> GetGroups()
|
||||
{
|
||||
var response = await _baseController.Get($"{BaseRoute}GetGroups");
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadFromJsonAsync<List<Read_GroupDto>>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public async Task<List<Read_GroupDto>?> GetGroupsCompany()
|
||||
{
|
||||
var response = await _baseController.Get($"{BaseRoute}GetGroupsCompany");
|
||||
|
@@ -92,6 +92,15 @@ namespace HushianWebApp.Service
|
||||
var response = await _baseController.Delete($"{BaseRoute}DeleteExperFromManager/{ExperID}");
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
public async Task<CurrentUserInfo> GetCurrentUserInfo()
|
||||
{
|
||||
var response = await _baseController.Get($"{BaseRoute}GetCurrentUserInfo");
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadFromJsonAsync<CurrentUserInfo>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user