@page "/editNow"
@inject NavigationManager Nav
@inject RestService api
@inject State State
@inject IJSRuntime JS
@if (markdownValue != null)
{
}
@code {
private MarkdownEditor? Editor;
private bool listed;
private string? markdownValue;
private bool loading = true;
protected override async Task OnInitializedAsync() {
await base.OnInitializedAsync();
NowContentData? data = await api.GetNowPage(State.SelectedAddressName!);
if (data != null)
{
listed = data.Listed == 1;
markdownValue = data.Content;
loading = false;
await InvokeAsync(StateHasChanged);
await Editor!.SetValueAsync(markdownValue);
}
loading = false;
await InvokeAsync(StateHasChanged);
}
Task OnMarkdownValueChanged(string value) {
return Task.CompletedTask;
}
public async Task Save() {
loading = true;
await InvokeAsync(StateHasChanged);
var result = await api.PostNowPage(State.SelectedAddressName!, markdownValue ?? string.Empty, listed);
if (result != null) {
await State.RefreshNow();
await InvokeAsync(StateHasChanged);
Nav.NavigateTo($"/person/{State.SelectedAddressName}#now");
}
loading = false;
}
public async Task OnCustomButtonClicked(MarkdownButtonEventArgs eventArgs) {
if (eventArgs.Name == "Help") {
await JS.InvokeVoidAsync("open", "https://home.omg.lol/info/editor", "_blank");
}
}
}