@page "/post/{BlogPostId}"
@inject IBlogApi _api
@inject NavigationManager _navman
@using Components.Interfaces
@inject IBlogNotificationService notificationService
@implements IDisposable
@using Markdig
@if (BlogPost != null)
{
@BlogPost.Title
@BlogPost.Title
@((MarkupString)Markdig.Markdown.ToHtml(BlogPost.Text, pipeline))
}
@code {
[Parameter]
public string BlogPostId { get; set; } = default!;
public BlogPost? BlogPost { get; set; }
protected async override Task OnParametersSetAsync()
{
BlogPost = await _api.GetBlogPostAsync(BlogPostId);
await base.OnParametersSetAsync();
}
MarkdownPipeline pipeline;
protected override Task OnInitializedAsync()
{
notificationService.BlogPostChanged += PostChanged;
pipeline = new MarkdownPipelineBuilder()
.UseEmojiAndSmiley()
.Build();
return base.OnInitializedAsync();
}
private async void PostChanged(BlogPost post)
{
if (BlogPost?.Id == post.Id)
{
BlogPost = post;
await InvokeAsync(() => this.StateHasChanged());
}
}
void IDisposable.Dispose()
{
notificationService.BlogPostChanged -= PostChanged;
}
}