@page "/tasks" @using Tasks.Module.Models @using Tasks.Module.Services @using Tasks.Module.Components.Dialogs @inject ITodoService TodoService @inject IDialogService Dialog @inject IViewService ViewService
@* Header *@

My Tasks

Manage your tasks and sub-tasks

@* Search and Filters *@
@(_showFilters ? "Hide Filters" : "Show Filters") Add View
@if (_showFilters) {
All
Low
Medium
High
All
Pending
Completed
}
@* Quick Add Input *@
Add Add Task
@* Stats *@ @if (!isLoading && tasks.Any()) {
@tasks.Count task@(tasks.Count != 1 ? "s" : "") @{ var completed = tasks.Count(t => t.IsCompleted); var pending = tasks.Count - completed; } @if (pending > 0) { @pending pending } @if (completed > 0) { @completed completed }
} @* Tasks List *@ @if (isLoading) {
} else if (tasks.Count == 0) {

No tasks yet

Type a task above and press Enter to get started

} else {
@foreach (var task in tasks) { }
}
@code { private List tasks = new(); private List allTasks = new(); private bool isLoading = true; private int? selectedPriority; private bool? selectedCompleted; private CreateTodoItemDto editTask = new(); private string currentTaskId = string.Empty; private string quickAddTitle = string.Empty; private HashSet collapsedTasks = new(); private string searchText = string.Empty; private bool _showFilters = false; private void ToggleFilters() { _showFilters = !_showFilters; } protected override async Task OnInitializedAsync() { await LoadTasks(); } private async Task LoadTasks() { isLoading = true; try { var filter = new TodoFilterDto { Priority = selectedPriority, IsCompleted = selectedCompleted }; allTasks = await TodoService.GetAllTodosAsync(filter); ApplyFilters(); } finally { isLoading = false; } } private void ApplyFilters() { var filtered = allTasks.AsEnumerable(); if (!string.IsNullOrWhiteSpace(searchText)) { filtered = filtered.Where(t => t.Title.Contains(searchText, StringComparison.OrdinalIgnoreCase) || (t.Description?.Contains(searchText, StringComparison.OrdinalIgnoreCase) ?? false)); } tasks = filtered.ToList(); } private void OnSearchChanged(string value) { searchText = value; ApplyFilters(); } private async Task HandleQuickAdd(KeyboardEventArgs e) { if (e.Key == "Enter" && !string.IsNullOrWhiteSpace(quickAddTitle)) { await QuickAddTask(); } } private async Task QuickAddTask() { if (string.IsNullOrWhiteSpace(quickAddTitle)) return; var newTask = new CreateTodoItemDto { Title = quickAddTitle.Trim(), Priority = 0 }; await TodoService.CreateTodoAsync(newTask); quickAddTitle = string.Empty; await LoadTasks(); } private void ToggleCollapse(string taskId) { if (collapsedTasks.Contains(taskId)) collapsedTasks.Remove(taskId); else collapsedTasks.Add(taskId); } private async Task OnPriorityChanged(int? value) { selectedPriority = value; await LoadTasks(); } private async Task OnCompletedChanged(bool? value) { selectedCompleted = value; await LoadTasks(); } private async Task ToggleTask(string id) { await TodoService.ToggleCompleteAsync(id); await LoadTasks(); } private async Task DeleteTask(string id) { await TodoService.DeleteTodoAsync(id); await LoadTasks(); } private async Task OpenCreateDialog() { editTask = new CreateTodoItemDto(); var parameters = new DialogParameters { { x => x.Task, editTask }, { x => x.IsUpdate, false } }; var options = new DialogOptions { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Small, FullWidth = true }; var dialog = await Dialog.ShowAsync("Create Task", parameters, options); var result = await dialog.Result; if (result is { Canceled: false }) { await TodoService.CreateTodoAsync(editTask); await LoadTasks(); } } private async Task OpenAddChildDialog(TodoItemDto parentTask) { editTask = new CreateTodoItemDto { ParentId = parentTask.Id }; var parameters = new DialogParameters { { x => x.Task, editTask }, { x => x.IsUpdate, false }, { x => x.IsChild, true }, { x => x.ParentTitle, parentTask.Title } }; var options = new DialogOptions { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Small, FullWidth = true }; var dialog = await Dialog.ShowAsync("Add Sub-task", parameters, options); var result = await dialog.Result; if (result is { Canceled: false }) { await TodoService.CreateTodoAsync(editTask); await LoadTasks(); } } private async Task OpenUpdateDialog(TodoItemDto task) { currentTaskId = task.Id; editTask = new CreateTodoItemDto { Title = task.Title, Description = task.Description, Priority = task.Priority, DueDate = task.DueDate, ParentId = task.ParentId, CategoryId = task.CategoryId, TagIds = task.TagIds.ToList(), FileId = task.FileId }; var parameters = new DialogParameters { { x => x.Task, editTask }, { x => x.IsUpdate, true } }; var options = new DialogOptions { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Small, FullWidth = true }; var dialog = await Dialog.ShowAsync("Update Task", parameters, options); var result = await dialog.Result; if (result is { Canceled: false }) { await TodoService.UpdateTodoAsync(new UpdateTodoItemDto { Id = currentTaskId, Title = editTask.Title, Description = editTask.Description, Priority = editTask.Priority, DueDate = editTask.DueDate, IsCompleted = task.IsCompleted, ParentId = editTask.ParentId, CategoryId = editTask.CategoryId, TagIds = editTask.TagIds, FileId = editTask.FileId }); await LoadTasks(); } } private async Task CreateView() { var parameters = new DialogParameters(); var options = new DialogOptions { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Small, FullWidth = true }; var dialog = await Dialog.ShowAsync("Create View", parameters, options); var result = await dialog.Result; if (result is { Canceled: false } && result.Data is CreateTaskViewDto createDto) { await ViewService.CreateViewAsync(createDto); } } }