hn-20-2/Apps/Client/Pages/Detail.razor
2021-04-28 15:03:29 +02:00

58 lines
1.1 KiB
Plaintext

@page "/links/{id:guid}"
@inject LinksClient Links
@inject CommentsClient Comments
@inject NotificationManager Notification
@if (_link == null)
{
<Title Value="Loading link detail..." />
<p>Loading link detail...</p>
}
else
{
<Title Value="@($"Viewing link {_link.Url}")" />
<h1>Viewing link @_link.Url</h1>
@if(_comments == null)
{
<p>Loading link comments...</p>
}
else if (_comments.Count == 0)
{
<p>No comments yet.</p>
}
else
{
<ul>
@foreach (var comment in _comments)
{
<li>@comment.Content</li>
}
</ul>
}
<CommentForm OnSubmit="PublishComment" />
}
@code {
[Parameter]
public Guid Id { get; set; }
private LinkDTO _link;
private ICollection<CommentDTO> _comments;
protected override async Task OnInitializedAsync()
{
_link = await Links.GetByIdAsync(Id);
_comments = await Links.CommentsAsync(Id);
}
private async Task PublishComment(PublishCommentCommand cmd)
{
cmd.LinkId = Id;
await Comments.CreateAsync(cmd);
Notification.Add("Your comment was published!");
_comments = await Links.CommentsAsync(Id);
}
}