| | | 1 | | using Microsoft.AspNetCore.Components; |
| | | 2 | | |
| | | 3 | | namespace Pomodoro.Web.Components.History; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Code-behind for WeekNavigator component |
| | | 7 | | /// Provides week navigation controls (Saturday to Friday week) |
| | | 8 | | /// </summary> |
| | | 9 | | public class WeekNavigatorBase : ComponentBase |
| | | 10 | | { |
| | | 11 | | #region Parameters |
| | | 12 | | |
| | | 13 | | [Parameter] |
| | 163 | 14 | | public DateTime SelectedWeekStart { get; set; } |
| | | 15 | | |
| | | 16 | | [Parameter] |
| | 33 | 17 | | public EventCallback<DateTime> OnWeekChanged { get; set; } |
| | | 18 | | |
| | | 19 | | #endregion |
| | | 20 | | |
| | | 21 | | #region Properties |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Check if the selected week is the current week |
| | | 25 | | /// </summary> |
| | | 26 | | protected bool IsThisWeek |
| | | 27 | | { |
| | | 28 | | get |
| | 82 | 29 | | { |
| | 82 | 30 | | var thisWeekStart = GetWeekStart(DateTime.Now.Date); |
| | 82 | 31 | | return SelectedWeekStart.Date == thisWeekStart.Date; |
| | 82 | 32 | | } |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | #endregion |
| | | 36 | | |
| | | 37 | | #region Actions |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Navigate to the previous week (Saturday to Friday) |
| | | 41 | | /// </summary> |
| | | 42 | | protected async Task GoToPreviousWeek() |
| | 2 | 43 | | { |
| | 2 | 44 | | var newWeekStart = SelectedWeekStart.AddDays(-Constants.Charts.DaysPerWeek); |
| | 2 | 45 | | await OnWeekChanged.InvokeAsync(newWeekStart); |
| | 2 | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Navigate to the next week (Saturday to Friday) |
| | | 50 | | /// </summary> |
| | | 51 | | protected async Task GoToNextWeek() |
| | 3 | 52 | | { |
| | 3 | 53 | | var newWeekStart = SelectedWeekStart.AddDays(Constants.Charts.DaysPerWeek); |
| | 3 | 54 | | await OnWeekChanged.InvokeAsync(newWeekStart); |
| | 3 | 55 | | } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Navigate to the current week |
| | | 59 | | /// </summary> |
| | | 60 | | protected async Task GoToThisWeek() |
| | 1 | 61 | | { |
| | 1 | 62 | | var thisWeekStart = GetWeekStart(DateTime.Now.Date); |
| | 1 | 63 | | await OnWeekChanged.InvokeAsync(thisWeekStart); |
| | 1 | 64 | | } |
| | | 65 | | |
| | | 66 | | #endregion |
| | | 67 | | |
| | | 68 | | #region Helper Methods |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Get the Saturday start of the week containing the given date |
| | | 72 | | /// DayOfWeek: Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, Sat=6 |
| | | 73 | | /// </summary> |
| | | 74 | | public static DateTime GetWeekStart(DateTime date) |
| | 245 | 75 | | { |
| | 245 | 76 | | int dayOfWeek = (int)date.DayOfWeek; |
| | 245 | 77 | | int daysSinceSaturday = (dayOfWeek + Constants.TimeConversion.SaturdayBasedWeekOffset) % Constants.TimeConversio |
| | 245 | 78 | | return date.AddDays(-daysSinceSaturday).Date; |
| | 245 | 79 | | } |
| | | 80 | | |
| | | 81 | | /// <summary> |
| | | 82 | | /// Format the week range for display (e.g., "Jan 20 - Jan 26, 2026") |
| | | 83 | | /// </summary> |
| | | 84 | | protected string FormatWeekRange(DateTime weekStart) |
| | 41 | 85 | | { |
| | 41 | 86 | | var weekEnd = weekStart.AddDays(Constants.TimeConversion.WeeklyLookbackDays); |
| | 41 | 87 | | return string.Format(Constants.History.WeekRangeFormat, weekStart, weekEnd); |
| | 41 | 88 | | } |
| | | 89 | | |
| | | 90 | | #endregion |
| | | 91 | | } |