SeemGen/Components/Partials/TemplateSnippetEditor.razor

89 lines
2.5 KiB
Plaintext

@using BLAIzor.Models
@using BLAIzor.Services
@using Microsoft.AspNetCore.Components.Authorization
@inject ContentEditorService ContentEditorService
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject CustomAuthenticationStateProvider CustomAuthProvider
<div class="menu-item-editor">
<div class="form-group">
<label>Template Name</label>
<InputText class="form-control" @bind-Value="Snippet.Name" />
</div>
<div class="form-group">
<label>Description</label>
<InputTextArea class="form-control" @bind-Value="Snippet.Description" />
</div>
<div class="form-group">
<label>Tags (comma-separated)</label>
<InputText class="form-control" @bind-Value="Snippet.Type" />
</div>
<RadzenHtmlEditor @bind-Value=@Snippet.Html style="height: 450px; color:#000; background-color: rgba(255,255,255,0.4)" Input=@OnInput Change=@OnChange Paste=@OnPaste UploadComplete=@OnUploadComplete Execute=@OnExecute UploadUrl="upload/image">
<RadzenHtmlEditorUndo />
<RadzenHtmlEditorRedo />
<RadzenHtmlEditorSource />
</RadzenHtmlEditor>
<EventConsole @ref=@console />
@if (IsLoading)
{
<p>Loading content...</p>
}
</div>
@code {
[Parameter] public HtmlSnippet Snippet { get; set; } = new HtmlSnippet();
[Parameter] public EventCallback<HtmlSnippet> OnContentUpdated { get; set; }
private bool IsLoading = false;
private string? userId;
private string? userName;
private AuthenticationState? authState;
EventConsole console;
protected override async Task OnParametersSetAsync()
{
authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState.User.Identity?.IsAuthenticated == true)
{
userId = CustomAuthProvider.GetUserId();
userName = CustomAuthProvider.GetUserName();
}
}
async Task OnPaste(HtmlEditorPasteEventArgs args)
{
console.Log($"Paste: {args.Html}");
// await OnContentUpdated.InvokeAsync(MenuItem);
}
async Task OnChange(string html)
{
console.Log($"Change: {html}");
}
async Task OnInput(string html)
{
console.Log($"Input: {html}");
}
void OnExecute(HtmlEditorExecuteEventArgs args)
{
console.Log($"Execute: {args.CommandName}");
}
void OnUploadComplete(UploadCompleteEventArgs args)
{
console.Log($"Upload complete: {args.RawResponse}");
}
}