| | | 1 | | using Microsoft.AspNetCore.Components; |
| | | 2 | | using Microsoft.AspNetCore.Components.Web; |
| | | 3 | | using Pomodoro.Web.Models; |
| | | 4 | | |
| | | 5 | | namespace Pomodoro.Web.Components; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Code-behind for TaskItem component |
| | | 9 | | /// Separates business logic from view |
| | | 10 | | /// </summary> |
| | | 11 | | public class TaskItemBase : ComponentBase |
| | | 12 | | { |
| | | 13 | | #region Parameters (Model) |
| | | 14 | | |
| | | 15 | | [Parameter] |
| | 642 | 16 | | public TaskItem Item { get; set; } = default!; |
| | | 17 | | |
| | | 18 | | [Parameter] |
| | 167 | 19 | | public bool IsSelected { get; set; } |
| | | 20 | | |
| | | 21 | | [Parameter] |
| | 38 | 22 | | public EventCallback<Guid> OnSelect { get; set; } |
| | | 23 | | |
| | | 24 | | [Parameter] |
| | 34 | 25 | | public EventCallback<Guid> OnComplete { get; set; } |
| | | 26 | | |
| | | 27 | | [Parameter] |
| | 34 | 28 | | public EventCallback<Guid> OnDelete { get; set; } |
| | | 29 | | |
| | | 30 | | [Parameter] |
| | 34 | 31 | | public EventCallback<Guid> OnUncomplete { get; set; } |
| | | 32 | | |
| | | 33 | | #endregion |
| | | 34 | | |
| | | 35 | | #region Business Logic Methods |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Formats minutes into human-readable time format |
| | | 39 | | /// </summary> |
| | | 40 | | protected string FormatTime(int minutes) |
| | 66 | 41 | | { |
| | 66 | 42 | | if (minutes < Constants.TimeConversion.MinutesPerHour) |
| | 64 | 43 | | return string.Format(Constants.TimeFormats.MinutesFormat, minutes); |
| | 2 | 44 | | var hours = minutes / Constants.TimeConversion.MinutesPerHour; |
| | 2 | 45 | | var mins = minutes % Constants.TimeConversion.MinutesPerHour; |
| | 2 | 46 | | return string.Format(Constants.TimeFormats.HoursMinutesFormat, hours, mins); |
| | 66 | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Gets the CSS class for the task item |
| | | 51 | | /// </summary> |
| | | 52 | | protected string GetTaskClass() |
| | 66 | 53 | | { |
| | 66 | 54 | | var classes = new List<string>(); |
| | 72 | 55 | | if (IsSelected) classes.Add(Constants.Tasks.SelectedClass); |
| | 79 | 56 | | if (Item.IsCompleted) classes.Add(Constants.Tasks.CompletedClass); |
| | 66 | 57 | | return string.Join(" ", classes); |
| | 66 | 58 | | } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Gets the status icon for the task |
| | | 62 | | /// </summary> |
| | | 63 | | protected string GetStatusIcon() |
| | 66 | 64 | | { |
| | 79 | 65 | | if (Item.IsCompleted) return Constants.Tasks.CompletedEmoji; |
| | 81 | 66 | | if (Item.PomodoroCount > 0) return Constants.Tasks.HasPomodorosEmoji; |
| | 25 | 67 | | return Constants.Tasks.DefaultEmoji; |
| | 66 | 68 | | } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Handles task selection click |
| | | 72 | | /// </summary> |
| | | 73 | | protected async Task HandleSelect() |
| | 4 | 74 | | { |
| | 4 | 75 | | if (!Item.IsCompleted) |
| | 3 | 76 | | { |
| | 3 | 77 | | await OnSelect.InvokeAsync(Item.Id); |
| | 3 | 78 | | } |
| | 4 | 79 | | } |
| | | 80 | | |
| | | 81 | | /// <summary> |
| | | 82 | | /// Handles task completion click |
| | | 83 | | /// </summary> |
| | | 84 | | protected async Task HandleComplete() |
| | 2 | 85 | | { |
| | 2 | 86 | | await OnComplete.InvokeAsync(Item.Id); |
| | 2 | 87 | | } |
| | | 88 | | |
| | | 89 | | /// <summary> |
| | | 90 | | /// Handles task deletion click |
| | | 91 | | /// </summary> |
| | | 92 | | protected async Task HandleDelete() |
| | 2 | 93 | | { |
| | 2 | 94 | | await OnDelete.InvokeAsync(Item.Id); |
| | 2 | 95 | | } |
| | | 96 | | |
| | | 97 | | /// <summary> |
| | | 98 | | /// Handles task uncomplete click (undo completion) |
| | | 99 | | /// </summary> |
| | | 100 | | protected async Task HandleUncomplete() |
| | 2 | 101 | | { |
| | 2 | 102 | | await OnUncomplete.InvokeAsync(Item.Id); |
| | 2 | 103 | | } |
| | | 104 | | |
| | | 105 | | protected async Task HandleKeyDown(KeyboardEventArgs e) |
| | 4 | 106 | | { |
| | 4 | 107 | | if (e.Key == "Enter" || e.Key == " ") |
| | 3 | 108 | | { |
| | 3 | 109 | | await HandleSelect(); |
| | 3 | 110 | | } |
| | 4 | 111 | | } |
| | | 112 | | |
| | | 113 | | #endregion |
| | | 114 | | } |