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

97 lines
3.6 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
2024-07-11 05:57:53 +00:00
@inject IJSRuntime JS
2024-06-21 06:26:11 +00:00
<div class="max markdown-editor">
2024-07-11 05:57:53 +00:00
@if (markdownValue != null)
{
<MarkdownEditor @ref="Editor"
@bind-Value="@markdownValue"
Theme="material-darker"
MaxHeight="100%"
CustomButtonClicked="@OnCustomButtonClicked">
<Toolbar>
<MarkdownToolbarButton Action="MarkdownAction.Bold" Icon="fa-solid fa-bold" Title="Bold" />
<MarkdownToolbarButton Action="MarkdownAction.Italic" Icon="fa-solid fa-italic" Title="Italic" />
<MarkdownToolbarButton Action="MarkdownAction.Heading" Icon="fa-solid fa-heading" Title="Heading" />
<MarkdownToolbarButton Action="MarkdownAction.Code" Icon="fa-solid fa-code" Title="Code" Separator="true" />
<MarkdownToolbarButton Action="MarkdownAction.Quote" Icon="fa-solid fa-quote-left" Title="Quote" />
<MarkdownToolbarButton Action="MarkdownAction.UnorderedList" Icon="fa-solid fa-list-ul" Title="Unordered List" />
<MarkdownToolbarButton Action="MarkdownAction.OrderedList" Icon="fa-solid fa-list-ol" Title="Ordered List" />
<MarkdownToolbarButton Action="MarkdownAction.Link" Icon="fa-solid fa-link" Title="Link" Separator="true" />
<MarkdownToolbarButton Action="MarkdownAction.Image" Icon="fa-solid fa-image" Title="Image" />
<MarkdownToolbarButton Action="MarkdownAction.HorizontalRule" Icon="fa-solid fa-horizontal-rule" Title="Horizontal Rule" />
<MarkdownToolbarButton Action="MarkdownAction.Guide" Icon="fa-solid fa-circle-question" Title="Guide" Separator="true" />
<MarkdownToolbarButton Action="MarkdownAction.Custom" Icon="omg-icon omg-prami" Title="Editor Information" Name="Help" />
</Toolbar>
</MarkdownEditor>
}
2024-06-21 06:26:11 +00:00
</div>
<nav>
2024-06-24 02:23:28 +00:00
<label class="checkbox" disabled="@loading">
<InputCheckbox @bind-Value="listed" disabled="@loading"></InputCheckbox>
2024-06-21 06:26:11 +00:00
<span>Include my page in the Now Garden</span>
</label>
<div class="max"></div>
2024-06-24 02:23:28 +00:00
<button class="transparent link" onclick="history.back();" disabled="@loading">Cancel</button>
<button @onclick="Save" disabled="@loading">
@if (loading) {
<span>Saving...</span>
}
else {
<i class="fa-solid fa-floppy-disk"></i> <span>Save</span>
}
2024-06-21 06:26:11 +00:00
</button>
</nav>
@code {
2024-07-02 00:13:52 +00:00
private MarkdownEditor? Editor;
2024-06-24 00:40:46 +00:00
private bool listed;
2024-07-02 00:13:52 +00:00
private string? markdownValue;
2024-06-24 00:40:46 +00:00
2024-07-11 05:57:53 +00:00
private bool loading = true;
2024-06-21 06:26:11 +00:00
protected override async Task OnInitializedAsync() {
await base.OnInitializedAsync();
2024-07-02 00:13:52 +00:00
NowContentData? data = await api.GetNowPage(State.SelectedAddressName!);
2024-06-21 06:26:11 +00:00
if (data != null)
{
listed = data.Listed == 1;
markdownValue = data.Content;
2024-07-11 05:57:53 +00:00
loading = false;
await InvokeAsync(StateHasChanged);
2024-07-02 00:13:52 +00:00
await Editor!.SetValueAsync(markdownValue);
2024-06-21 06:26:11 +00:00
}
2024-07-11 05:57:53 +00:00
loading = false;
2024-07-02 00:13:52 +00:00
await InvokeAsync(StateHasChanged);
2024-06-21 06:26:11 +00:00
}
Task OnMarkdownValueChanged(string value) {
return Task.CompletedTask;
}
public async Task Save() {
2024-06-24 00:40:46 +00:00
loading = true;
await InvokeAsync(StateHasChanged);
2024-07-02 00:13:52 +00:00
var result = await api.PostNowPage(State.SelectedAddressName!, markdownValue ?? string.Empty, listed);
2024-06-24 00:40:46 +00:00
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
}
2024-07-11 05:57:53 +00:00
public async Task OnCustomButtonClicked(MarkdownButtonEventArgs eventArgs) {
if (eventArgs.Name == "Help") {
await JS.InvokeVoidAsync("open", "https://home.omg.lol/info/editor", "_blank");
}
}
2024-06-21 06:26:11 +00:00
}