Neighbourhood.omg.lol/Components/Pages/EditNow.razor

53 lines
1.2 KiB
Text
Raw Normal View History

2024-06-21 06:26:11 +00:00
@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 {
MarkdownEditor Editor;
bool listed;
string markdownValue;
string markdownHtml;
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() {
await api.PostNowPage(State.SelectedAddressName, markdownValue, listed);
}
}