shopping-assistant-web-client/ShoppingAssistantWebClient.Web/Pages/Chat.razor
2023-11-20 09:03:32 +00:00

148 lines
3.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@page "/chat/{chatId}"
@inject IHttpClientFactory ClientFactory
@inject IJSRuntime JSRuntime
<PageTitle>@name</PageTitle>
<div class="right_frame" id="rightFrame">
<div id="button_open" class="open_menu">
<a class="button_open_menu">
<span></span>
<span></span>
<span></span>
</a>
</div>
<div class="new_chat">
<div class="title_one_frame">@name</div>
<div class="chat_message" @ref="chatMessageRef">
<ul class="chat_box">
@if (!isLoading && Messages != null)
{
@foreach (var item in Messages)
{
if (item.Role != "User")
{
<li class=" chat_incoming">
<p>@item.Text</p>
</li>
}
else
{
<li class="chat_outgoing">
<p>@item.Text</p>
</li>
}
}
}
</ul>
</div>
<div class="possible_options">
@if (Suggestion.Count != 0)
{
<div class="tite_options">Several possible options</div>
<div class="options">
@foreach (var item in Suggestion)
{
<div @onclick="() => ClickOption(item)" class="topic_options">
@item
</div>
}
</div>
}
</div>
<div class="chat_input">
<input @onkeydown="Enter" @oninput="InputChanged" class="input_messages" type="text" id="chatInput"
placeholder="Describe what you are looking for...." autocomplete="off">
<img @onclick="AddNewMessage" class="button_sende" src="/images/send.svg" alt="Send message">
</div>
</div>
</div>
<script>
window.scrollToBottom = function (element) {
if (element) {
element.scrollTop = 9999;
}
};
window.clearInput = () => {
// Отримати елемент вводу за його ідентифікатором і обнулити його значення
document.getElementById('chatInput').value = '';
};
document.getElementById('button_open').addEventListener('click', changetyle);
</script>
@code {
[Parameter] public string chatId { get; set; }
protected override async Task OnParametersSetAsync()
{
await LoadMessages();
}
private void InputChanged(ChangeEventArgs e)
{
inputValue = e.Value.ToString();
}
public void Enter(KeyboardEventArgs e)
{
if (e.Code == "Enter" || e.Code == "NumpadEnter")
{
AddNewMessage();
}
}
private ElementReference chatMessageRef;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await JSRuntime.InvokeVoidAsync("scrollToBottom", chatMessageRef);
}
private void ClickOption(string item)
{
inputValue = item;
}
}