SeemGen/Components/Partials/EditContentItem.razor

94 lines
2.9 KiB
Plaintext

@using BLAIzor.Models
@using BLAIzor.Services
@inject ContentEditorService contentEditorService
@inject CacheService cache
@if (isLoading)
{
<p>Loading content item...</p>
}
else if (contentItem == null)
{
<p class="text-danger">Content item not found.</p>
}
else
{
<EditForm Model="@contentItem" OnValidSubmit="HandleSave">
<div class="rounded p-3 bg-panel">
<label>
Title
<InputText class="form-control my-2" @bind-Value="contentItem.Title" />
</label>
<label>
Description
<InputTextArea class="form-control my-2" style="height: 60px;" @bind-Value="contentItem.Description" Rows="3" />
</label>
<label>
Content
<InputTextArea class="form-control my-2" style="height: 200px;" @bind-Value="contentItem.Content" Rows="10" />
</label>
<label>
Language
<InputText class="form-control my-2" @bind-Value="contentItem.Language" />
</label>
<label>
Tags (comma-separated)
<InputText class="form-control my-2" @bind-Value="contentItem.Tags" />
</label>
<div class="form-check my-2">
<InputCheckbox class="form-check-input" id="isPublished" @bind-Value="contentItem.IsPublished" />
<label class="form-check-label" for="isPublished">Published</label>
</div>
<div class="d-flex flex-row-reverse">
<button class="btn btn-primary" type="submit">Save</button>
<button class="btn btn-secondary" type="button" @onclick="CancelEdit">Cancel</button>
</div>
</div>
</EditForm>
}
@code {
[Parameter] public int ContentItemId { get; set; }
[Parameter] public Func<ContentItem, Task> OnContentUpdated { get; set; }
[Parameter] public Func<ContentItem, Task> OnSaved { get; set; }
[Parameter] public Func<Task> OnCancelled { get; set; }
private ContentItem? contentItem;
private bool isLoading = true;
protected override async Task OnInitializedAsync()
{
isLoading = true;
contentItem = await contentEditorService.GetContentItemByIdAsync(ContentItemId);
isLoading = false;
}
private async Task HandleSave()
{
contentItem!.LastUpdated = DateTime.UtcNow;
await contentEditorService.SaveAndSyncContentItemAsync(contentItem, contentItem.ContentGroup.SiteInfo.VectorCollectionName, false);
if (OnSaved != null)
await OnSaved.Invoke(contentItem);
}
private async Task CancelEdit()
{
if (OnCancelled != null)
await OnCancelled.Invoke();
}
private async Task OnUpdated()
{
if (OnContentUpdated != null)
await OnContentUpdated.Invoke(contentItem);
}
}