@page "/links/{id:guid}"
@inject LinksClient Links
@inject CommentsClient Comments
@inject NotificationManager Notification
@if (_link == null)
{
Loading link detail...
}
else
{
Viewing link @_link.Url
@if(_comments == null)
{
Loading link comments...
}
else if (_comments.Count == 0)
{
No comments yet.
}
else
{
@foreach (var comment in _comments)
{
- @comment.Content
}
}
}
@code {
[Parameter]
public Guid Id { get; set; }
private LinkDTO _link;
private ICollection _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);
}
}