@using LinkDotNet.Blog.Domain @using LinkDotNet.Blog.Infrastructure.Persistence @using LinkDotNet.Blog.Web.Features.Services @inject IRepository Repository @inject ISortOrderCalculator SortOrderCalculator
@ProfileInformation.Name
@ProfileInformation.Heading
Profile Picture
@code { [Parameter] public bool ShowAdminActions { get; set; } [Parameter, EditorRequired] public required ProfileInformation ProfileInformation { get; set; } private List profileInformationEntries = []; private ConfirmDialog Dialog { get; set; } = default!; private string? currentDeleteKey; private ProfileInformationEntry? currentDragItem; protected override async Task OnInitializedAsync() { profileInformationEntries = (await Repository.GetAllAsync(orderBy: d => d.SortOrder, descending: false)).ToList(); } private void ShowDeleteDialog(string key) { currentDeleteKey = key; Dialog.Open(); } private async Task DeleteItem() { var entryToDelete = profileInformationEntries.Single(p => p.Content == currentDeleteKey); profileInformationEntries.Remove(entryToDelete); await Repository.DeleteAsync(entryToDelete.Id); } private async Task AddValue(string toAdd) { var sortOrder = GetSortOrder(); var newEntry = ProfileInformationEntry.Create(toAdd, sortOrder); profileInformationEntries.Add(newEntry); await Repository.StoreAsync(newEntry); } private int GetSortOrder() { if (profileInformationEntries.Any()) { return profileInformationEntries.Max(p => p.SortOrder) + 1000; } return 1000; } private async Task HandleDrop(ProfileInformationEntry dropTarget) { if (currentDragItem is null || dropTarget == currentDragItem) { return; } var newSortOrder = SortOrderCalculator.GetSortOrder(dropTarget, profileInformationEntries); currentDragItem.SortOrder = newSortOrder; await Repository.StoreAsync(currentDragItem); currentDragItem = null; profileInformationEntries.Sort((a, b) => a.SortOrder.CompareTo(b.SortOrder)); StateHasChanged(); } }