diff --git a/ShoppingAssistantWebClient.Web/Pages/Cards.razor.cs b/ShoppingAssistantWebClient.Web/Pages/Cards.razor.cs index 993eddd..f1f000b 100644 --- a/ShoppingAssistantWebClient.Web/Pages/Cards.razor.cs +++ b/ShoppingAssistantWebClient.Web/Pages/Cards.razor.cs @@ -4,6 +4,7 @@ using ShoppingAssistantWebClient.Web.Network; using GraphQL; using Newtonsoft.Json; using Microsoft.JSInterop; +using ShoppingAssistantWebClient.Web.Services; namespace ShoppingAssistantWebClient.Web.Pages; @@ -12,6 +13,9 @@ public partial class Cards [Inject] private ApiClient _apiClient { get; set; } + [Inject] + SearchService _searchService { get; set; } + private int currentIndex = 0; private int currentProduct = 0; @@ -37,6 +41,7 @@ public partial class Cards //}; public List Products {get; set;} + public List productsNames {get; set;} protected override async Task OnInitializedAsync() { @@ -44,6 +49,7 @@ public partial class Cards currentImage = Products[currentProduct].ImagesUrls[currentIndex]; } else { + productsNames = _searchService.Products; currentImage = ""; isProductsNull = true; } diff --git a/ShoppingAssistantWebClient.Web/Pages/Cart.razor b/ShoppingAssistantWebClient.Web/Pages/Cart.razor index e77a6f0..678e702 100644 --- a/ShoppingAssistantWebClient.Web/Pages/Cart.razor +++ b/ShoppingAssistantWebClient.Web/Pages/Cart.razor @@ -1,4 +1,4 @@ -@page "/cart/{chatId}/{currentWishlistId}" +@page "/cart/{currentWishlistId}" @inject NavigationManager navigationManager; diff --git a/ShoppingAssistantWebClient.Web/Pages/Chat.razor.cs b/ShoppingAssistantWebClient.Web/Pages/Chat.razor.cs index d361622..0590f6f 100644 --- a/ShoppingAssistantWebClient.Web/Pages/Chat.razor.cs +++ b/ShoppingAssistantWebClient.Web/Pages/Chat.razor.cs @@ -6,6 +6,7 @@ using ShoppingAssistantWebClient.Web.Network; using ShoppingAssistantWebClient.Web.Models.Input; using ShoppingAssistantWebClient.Web.Models.Enums; using System.Text.RegularExpressions; +using ShoppingAssistantWebClient.Web.Services; namespace ShoppingAssistantWebClient.Web.Pages; public partial class Chat : ComponentBase @@ -15,8 +16,12 @@ public partial class Chat : ComponentBase private ApiClient _apiClient { get; set; } [Inject] private NavigationManager Navigation { get; set; } + [Inject] + private SearchService _searchServise { get; set; } public List Messages { get; set; } + + public List Products { get; set; } = new List(); public List Suggestion { get; set; } = new List(); public Messages Message { get; set; } @@ -118,52 +123,52 @@ public partial class Chat : ComponentBase { Console.WriteLine($"Received SSE Event: {sseEvent.Event}, Data: {sseEvent.Data}"); + string input = sseEvent.Data; + Regex regex = new Regex("\"(.*?)\""); + Match match = regex.Match(input); + string result = match.Groups[1].Value; if(sseEvent.Event == SearchEventType.Message){ - string input = sseEvent.Data; - Regex regex = new Regex("\"(.*?)\""); - Match match = regex.Match(input); - string result = match.Groups[1].Value; - + Message = new Messages(); + Message.Text = result; + Message.Role = "bot"; + Message.Id = ""; + Message.CreatedById = ""; + if (first) + { + Messages.Add(Message); + first = false; + } + else + { + var lengt = Messages.Count(); + Messages[lengt-1].Text += Message.Text; + } - Message = new Messages(); - Message.Text = result; - Message.Role = "bot"; - Message.Id = ""; - Message.CreatedById = ""; - - if (first) - { - Messages.Add(Message); - first = false; - } - else - { - var lengt = Messages.Count(); - Messages[lengt-1].Text += Message.Text; - } - - StateHasChanged(); + StateHasChanged(); - }else if(sseEvent.Event == SearchEventType.Product){ + } else if(sseEvent.Event == SearchEventType.Product){ - var url = $"/chat/{chatId}/product"; - Navigation.NavigateTo(url); + Products.Add(result); - }else if(sseEvent.Event == SearchEventType.Suggestion){ + } else if(sseEvent.Event == SearchEventType.Suggestion){ - Suggestion.Add(sseEvent.Data); + Suggestion.Add(sseEvent.Data); } } - - }catch(Exception ex){ - Console.WriteLine($"Error : {ex.Message}"); + if(Products != null) { + string n = name; + _searchServise.SetProducts(Products); + var url = $"/cards/{name}/{chatId}"; + Navigation.NavigateTo(url); } - + } catch(Exception ex){ + Console.WriteLine($"Error : {ex.Message}"); + } } } diff --git a/ShoppingAssistantWebClient.Web/Program.cs b/ShoppingAssistantWebClient.Web/Program.cs index d8ea416..4809cc6 100644 --- a/ShoppingAssistantWebClient.Web/Program.cs +++ b/ShoppingAssistantWebClient.Web/Program.cs @@ -1,7 +1,8 @@ using GraphQL.Client.Http; using ShoppingAssistantWebClient.Web.Configurations; using ShoppingAssistantWebClient.Web.Data; -using ShoppingAssistantWebClient.Web.Network; +using ShoppingAssistantWebClient.Web.Network; +using ShoppingAssistantWebClient.Web.Services; var builder = WebApplication.CreateBuilder(args); @@ -11,6 +12,7 @@ builder.Services.AddServerSideBlazor(); builder.Services.AddServerSideBlazor().AddCircuitOptions(options => { options.DetailedErrors = true; }); builder.Services.AddSingleton(); builder.Services.AddApiClient(builder.Configuration); +builder.Services.AddSingleton(); var app = builder.Build(); diff --git a/ShoppingAssistantWebClient.Web/Services/SearchService.cs b/ShoppingAssistantWebClient.Web/Services/SearchService.cs new file mode 100644 index 0000000..aee9aea --- /dev/null +++ b/ShoppingAssistantWebClient.Web/Services/SearchService.cs @@ -0,0 +1,17 @@ + +namespace ShoppingAssistantWebClient.Web.Services; + +public class SearchService +{ + public List Products { get; set; } + + public string firstMassage { get; set; } + + public void SetProducts(List products) { + Products = products; + } + + public void SetFirstMassage(string massage) { + firstMassage = massage; + } +} \ No newline at end of file diff --git a/ShoppingAssistantWebClient.Web/Shared/MainLayout.razor.css b/ShoppingAssistantWebClient.Web/Shared/MainLayout.razor.css deleted file mode 100644 index 0f1cc15..0000000 --- a/ShoppingAssistantWebClient.Web/Shared/MainLayout.razor.css +++ /dev/null @@ -1,24 +0,0 @@ -.page { - position: relative; - width: 100%; - height: 100vh; - padding: 1.25em; -} - -.sidebar-menu { - position: absolute; - width: 20em; - top: 1.25em; - bottom: 1.25em; - margin-right: 1.5em; - transition: 1s; -} - -.right-frame { - position: absolute; - right: 1.25em; - left: 23.25em; - top: 1.25em; - bottom: 1.25em; - transition: 1s; -} \ No newline at end of file diff --git a/ShoppingAssistantWebClient.Web/Shared/NavMenu.razor b/ShoppingAssistantWebClient.Web/Shared/NavMenu.razor index 222f245..2c856d7 100644 --- a/ShoppingAssistantWebClient.Web/Shared/NavMenu.razor +++ b/ShoppingAssistantWebClient.Web/Shared/NavMenu.razor @@ -40,7 +40,7 @@
@item.Name
Delete wishlist - Card open + Card open
} } @@ -149,8 +149,8 @@ var url = $"/"; Navigation.NavigateTo(url); } - private void RedirectToCard(string itemId) { - var url = $"/chat/{itemId}/cart"; + private void RedirectToCart(string itemId) { + var url = $"/cart/{itemId}"; Navigation.NavigateTo(url); } private async void DeleteWishlist(string itemId) { diff --git a/ShoppingAssistantWebClient.Web/Shared/NavMenu.razor.cs b/ShoppingAssistantWebClient.Web/Shared/NavMenu.razor.cs index ec220ab..5bc3986 100644 --- a/ShoppingAssistantWebClient.Web/Shared/NavMenu.razor.cs +++ b/ShoppingAssistantWebClient.Web/Shared/NavMenu.razor.cs @@ -17,17 +17,7 @@ namespace ShoppingAssistantWebClient.Web.Shared public int pageSize { get; set; } public int currentPage { get; set; } - private readonly ApiClient _apiClient; - - public NavMenu() - { - } - - public NavMenu(ApiClient apiClient) - { - _apiClient = apiClient; - } - public async Task OnGetAsync() + protected override async Task OnInitializedAsync() { pageSize = 200; currentPage = 1; @@ -35,6 +25,7 @@ namespace ShoppingAssistantWebClient.Web.Shared await LoadMenus(currentPage, pageSize); } + public async Task LoadMenus(int pageNumber, int pageSize ) { try{ diff --git a/ShoppingAssistantWebClient.Web/wwwroot/css/MainLayout.css b/ShoppingAssistantWebClient.Web/wwwroot/css/MainLayout.css index 32b38d9..a111657 100644 --- a/ShoppingAssistantWebClient.Web/wwwroot/css/MainLayout.css +++ b/ShoppingAssistantWebClient.Web/wwwroot/css/MainLayout.css @@ -3,7 +3,6 @@ width: 100%; height: 100vh; border: 1.5% solid; - border-color: #edf106; padding: 1.25em; } @@ -23,4 +22,4 @@ top: 1.25em; bottom: 1.25em; transition: 1s; -} +} \ No newline at end of file