@using Indotalent.ConfigBackEnd.Extensions @using Indotalent.Features.Utilities.Todo @using Indotalent.Features.Utilities.Todo.Cqrs @using MudBlazor @using Indotalent.Features.Root.Shared @inject TodoService TodoService @inject IDialogService DialogService @inject ISnackbar Snackbar
Todo Items @if (!ReadOnly) { Add Item }
Name Start Time Status Description @if (!ReadOnly) { Actions } @context.Name @DateTimeExtensions.ToString(context.StartTime) @if (context.IsCompleted) { COMPLETED } else { PENDING } @context.Description @if (!ReadOnly) { }
@code { [Parameter] public string TodoId { get; set; } = string.Empty; [Parameter] public List Items { get; set; } = new(); [Parameter] public bool ReadOnly { get; set; } = false; [Parameter] public EventCallback OnChanged { get; set; } private async Task OnAddClick() { var parameters = new DialogParameters { ["TodoId"] = TodoId }; var options = new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true, CloseButton = true }; var dialog = await DialogService.ShowAsync<_TodoItemCreateForm>("Add Todo Item", parameters, options); var result = await dialog.Result; if (result != null && !result.Canceled) await OnChanged.InvokeAsync(); } private async Task OnEditClick(TodoItemResponse item) { var parameters = new DialogParameters { ["Data"] = item }; var options = new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true, CloseButton = true }; var dialog = await DialogService.ShowAsync<_TodoItemUpdateForm>("Edit Todo Item", parameters, options); var result = await dialog.Result; if (result != null && !result.Canceled) await OnChanged.InvokeAsync(); } private async Task OnDeleteClick(TodoItemResponse item) { var parameters = new DialogParameters { ["ContentText"] = $"Are you sure you want to remove {item.Name}?" }; var dialog = await DialogService.ShowAsync<_DeleteConfirmation>("Delete Confirmation", parameters, new DialogOptions { MaxWidth = MaxWidth.ExtraSmall, FullWidth = true }); var result = await dialog.Result; if (result != null && !result.Canceled) { var success = await TodoService.DeleteTodoItemAsync(item.Id!); if (success) { Snackbar.Add("Item removed successfully", Severity.Success); await OnChanged.InvokeAsync(); } } } }