@page "/"
@inject LinksClient Links

<Title Value="Liens publiés" />

<h1>Liens publiés</h1>

@if (_error)
{
  <p>Oups!</p>
}
else if (_links == null)
{
  <p>Chargement en cours</p>
}
else if (_links.Length == 0)
{
  <p>Aucun lien pour le moment :'(</p>
}
else
{
  <ul>
    @foreach (var link in _links)
    {
        <li @key="link.Id">
          <LinkItem Item="@link" />
        </li>
    }
  </ul>
}

@code {
  private LinkDto[] _links;
  private bool _error = false;

  protected override async Task OnInitializedAsync()
  {
    try {
      _links = (await Links.GetLinksAsync()).ToArray();
    } catch {
      _error = true;
    }
  }
}