@page "/SubscriptionList"
@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;
<div class="mb-5"><h3>List of recipe creator(s) that I have subscribed to</h3></div>
<div>
@if (subscriptions == null)
{
<p><em>Loading...</em></p>
}
else
{
<ul class="list-group col-md-4">
@foreach (var sub in subscriptions)
{
<li class="list-group-item border-left-0 border-right-0">
<div @onclick="() => ViewAuthorProfile(sub.subscribedAuthorId)" style="cursor: pointer;" class="text-primary btn btn-link p-0 m-0">
@sub.subscribedAuthorName
</div>
</li>
}
</ul>
}
</div>
@code {
List<SubscriptionItemDto> subscriptions;
private void ViewAuthorProfile(string authorId)
{
NavManager.NavigateTo($"/PublicProfile/{authorId}", true);
}
protected override async Task OnInitializedAsync()
{
string userId = await UtilityService.GetUserId();
subscriptions = await Http.GetFromJsonAsync<List<SubscriptionItemDto>>("Subscription/SubscriptionList/" + userId);
}
}