oliverbooth.dev/OliverBooth/Pages/Components/MarkdownEditor.razor
Oliver Booth 28c7f7ce78
refactor!: restructure the markdown editor
This change significantly impacts the organisation and structure of the markdown editor, starting to utilise Blazor (SignalR) to perform operations such as saving, removing the need for an API controller.

Much of the TypeScript source has been more coherently decoupled, for example UI vs business logic is now independent.
2024-02-28 16:04:56 +00:00

37 lines
859 B
Plaintext

@using OliverBooth.Services
@using OliverBooth.Data.Blog
@implements IDisposable
@inject IBlogPostService BlogPostService
@inject IJSRuntime JsRuntime
@code {
private DotNetObjectReference<MarkdownEditor>? _dotNetHelper;
[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);
}
}
}