62 lines
1.5 KiB
Text
62 lines
1.5 KiB
Text
@page "/editNow"
|
|
@inject NavigationManager Nav
|
|
@inject RestService api
|
|
@inject State State
|
|
|
|
|
|
<div class="max markdown-editor">
|
|
<MarkdownEditor @ref="Editor"
|
|
@bind-Value="@markdownValue"
|
|
Theme="material-darker"
|
|
MaxHeight="100%"
|
|
/>
|
|
</div>
|
|
|
|
<nav>
|
|
<label class="checkbox">
|
|
<InputCheckbox @bind-Value="listed"></InputCheckbox>
|
|
<span>Include my page in the Now Garden</span>
|
|
</label>
|
|
<div class="max"></div>
|
|
<button class="transparent link" onclick="history.back();">Cancel</button>
|
|
<button @onclick="Save">
|
|
<i class="fa-solid fa-floppy-disk"></i> <span>Save</span>
|
|
</button>
|
|
</nav>
|
|
|
|
@code {
|
|
private MarkdownEditor Editor;
|
|
private bool listed;
|
|
private string markdownValue;
|
|
|
|
private bool loading = false;
|
|
|
|
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;
|
|
await Editor.SetValueAsync(markdownValue);
|
|
}
|
|
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, listed);
|
|
if (result != null) {
|
|
await State.RefreshNow();
|
|
await InvokeAsync(StateHasChanged);
|
|
Nav.NavigateTo($"/person/{State.SelectedAddressName}#now");
|
|
}
|
|
|
|
loading = false;
|
|
}
|
|
}
|