Improved news system
This commit is contained in:
@@ -39,6 +39,11 @@
|
||||
<TL>Discord bot</TL>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item mt-2">
|
||||
<a class="nav-link text-active-primary ms-0 me-10 py-5 @(Index == 7 ? "active" : "")" href="/admin/system/news">
|
||||
<TL>News</TL>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
@using Moonlight.App.Services
|
||||
@using Moonlight.App.Database.Entities
|
||||
@using BlazorMonaco
|
||||
|
||||
@inject SmartTranslateService SmartTranslateService
|
||||
@inject IJSRuntime JsRuntime
|
||||
|
||||
<div class="card mb-6">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title w-75">
|
||||
<input type="text" @bind="Model.Title" placeholder="@SmartTranslateService.Translate("Title...")" class="form-control form-control-flush"/>
|
||||
</h3>
|
||||
<div class="card-toolbar">
|
||||
@{
|
||||
string dateInt(int i) => i.ToString().Length < 2 ? "0" + i : i.ToString();
|
||||
var date = Model.Date == default ? DateTime.Now : Model.Date;
|
||||
}
|
||||
<span class="text-gray-600 fw-semibold">@dateInt(date.Day).@dateInt(date.Month).@date.Year</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<MonacoEditor CssClass="h-50" @ref="Editor" Id="vseditor" ConstructionOptions="(x) => EditorOptions"/>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<WButton CssClasses="btn btn-primary float-end" OnClick="DoSave" Text="@SmartTranslateService.Translate("Save")" WorkingText="@SmartTranslateService.Translate("Saving...")"></WButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
// Monaco Editor
|
||||
private MonacoEditor Editor;
|
||||
private StandaloneEditorConstructionOptions EditorOptions;
|
||||
|
||||
[Parameter]
|
||||
public NewsEntry Model { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<NewsEntry, Task> Save { get; set; }
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
EditorOptions = new()
|
||||
{
|
||||
AutomaticLayout = true,
|
||||
Language = "plaintext",
|
||||
Value = "Loading content",
|
||||
Theme = "moonlight-theme",
|
||||
Contextmenu = false,
|
||||
Minimap = new()
|
||||
{
|
||||
Enabled = false
|
||||
},
|
||||
AutoIndent = true
|
||||
};
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await JsRuntime.InvokeVoidAsync("initMonacoTheme");
|
||||
|
||||
Editor.OnDidInit = new EventCallback<MonacoEditorBase>(this, async () =>
|
||||
{
|
||||
EditorOptions.Language = "markdown";
|
||||
|
||||
var model = await Editor.GetModel();
|
||||
await MonacoEditorBase.SetModelLanguage(model, EditorOptions.Language);
|
||||
await Editor.SetPosition(new Position()
|
||||
{
|
||||
Column = 0,
|
||||
LineNumber = 1
|
||||
});
|
||||
|
||||
await Editor.SetValue(string.IsNullOrWhiteSpace(Model.Markdown) ? "*enter your markdown here*" : Model.Markdown);
|
||||
|
||||
await Editor.Layout(new Dimension()
|
||||
{
|
||||
Height = 500,
|
||||
Width = 1000
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DoSave()
|
||||
{
|
||||
Model.Date = Model.Date == default ? DateTime.Now : Model.Date;
|
||||
Model.Markdown = await Editor.GetValue();
|
||||
|
||||
Save?.Invoke(Model);
|
||||
}
|
||||
|
||||
public async Task UpdateMonacoText()
|
||||
{
|
||||
await Editor.SetValue(Model.Markdown);
|
||||
}
|
||||
}
|
||||
@@ -68,14 +68,6 @@ else
|
||||
<span class="menu-title"><TL>Changelog</TL></span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="menu-item">
|
||||
<a class="menu-link" href="/news">
|
||||
<span class="menu-icon">
|
||||
<i class="bx bx-news"></i>
|
||||
</span>
|
||||
<span class="menu-title"><TL>News</TL></span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
if (User.Admin)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user