shopping-assistant-web-client/ShoppingAssistantWebClient.Web/Pages/Index.razor.cs
2023-11-05 16:18:31 +00:00

58 lines
1.5 KiB
C#

using Microsoft.AspNetCore.Components;
using ShoppingAssistantWebClient.Web.Models;
using GraphQL;
using Newtonsoft.Json;
using ShoppingAssistantWebClient.Web.Network;
namespace ShoppingAssistantWebClient.Web.Pages
{
public partial class Index : ComponentBase
{
[Inject]
private ApiClient _apiClient { get; set; }
[Inject]
private NavigationManager Navigation { get; set; }
private string inputValue = "";
public bool isLoading = true;
private async Task CreateNewChat() {
if(inputValue!=""){
var type = selectedChoice;
var firstMessageText= inputValue;
var request = new GraphQLRequest
{
Query = @"mutation StartPersonalWishlist($type: String!, $firstMessageText: String!) {
startPersonalWishlist(dto: { type: $type, firstMessageText: $firstMessageText }) {
id
}
}
",
Variables = new
{
type,
firstMessageText
}
};
var response = await _apiClient.QueryAsync(request);
var responseData = response.Data;
var chat_id = responseData.startPersonalWishlist.id;
var url = $"/chat/{chat_id}";
Navigation.NavigateTo(url);
}
}
}
}