3900-MyRecipes-backup / Client / Pages / LikedRecipes.razor
LikedRecipes.razor
Raw
@page "/LikedRecipes"
@using Microsoft.AspNetCore.Authorization;
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
@using MyRecipes2.Shared;
@attribute [Authorize];
@inject HttpClient Http;
@inject AuthenticationStateProvider AuthenticationStateProvider;
@inject NavigationManager NavManager;
@using MyRecipes2.Client.Services;
@inject UtilityService UtilityService;

<h1>Liked Recipes</h1>

@if (recipes == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <div class="row">

        @foreach (var recipe in recipes)
        {
            <RecipeDisplayCard recipe="recipe"></RecipeDisplayCard>
        }
    </div>
}

@code{
    List<RecipeDto> recipes;
    protected override async Task OnInitializedAsync()
    {
        string userId = await UtilityService.GetUserId();
        recipes = await Http.GetFromJsonAsync<List<RecipeDto>>("Recipe/LikedRecipes/" + userId);
    }

    protected void ClickView(RecipeDto recipe)
    {
        NavManager.NavigateTo($"ViewRecipe/{recipe.Id}");
    }
}