2024-03-02 05:30:15 +00:00
|
|
|
@using System.Text.Json
|
2024-03-02 01:04:42 +00:00
|
|
|
@using OliverBooth.Common.Data.Blog
|
|
|
|
@using OliverBooth.Common.Services
|
2024-02-28 16:04:56 +00:00
|
|
|
@implements IDisposable
|
|
|
|
@inject IBlogPostService BlogPostService
|
|
|
|
@inject IJSRuntime JsRuntime
|
|
|
|
|
|
|
|
@code {
|
|
|
|
private DotNetObjectReference<MarkdownEditor>? _dotNetHelper;
|
|
|
|
|
2024-03-02 05:30:15 +00:00
|
|
|
[JSInvokable]
|
|
|
|
public string GetEditorObject(Guid id)
|
|
|
|
{
|
|
|
|
if (!BlogPostService.TryGetPost(id, out IBlogPost? post))
|
|
|
|
{
|
|
|
|
return JsonSerializer.Serialize(new { blocks = Array.Empty<object>() });
|
|
|
|
}
|
|
|
|
|
|
|
|
return BlogPostService.GetBlogPostEditorObject(post);
|
|
|
|
}
|
|
|
|
|
2024-02-28 16:04:56 +00:00
|
|
|
[JSInvokable]
|
|
|
|
public void Save(Guid id, string content)
|
|
|
|
{
|
|
|
|
if (!BlogPostService.TryGetPost(id, out IBlogPost? post))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
post.Body = content;
|
|
|
|
BlogPostService.UpdatePost(post);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
_dotNetHelper?.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
{
|
|
|
|
if (firstRender)
|
|
|
|
{
|
|
|
|
_dotNetHelper = DotNetObjectReference.Create(this);
|
|
|
|
await JsRuntime.InvokeVoidAsync("Interop.setDotNetHelper", _dotNetHelper);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|