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

63 lines
1.5 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 {
2024-06-24 00:40:46 +00:00
private MarkdownEditor Editor;
private bool listed;
private string markdownValue;
private bool loading = false;
2024-06-21 06:26:11 +00:00
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() {
2024-06-24 00:40:46 +00:00
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;
2024-06-21 06:26:11 +00:00
}
}