diff --git a/LiftLog.Ui/Pages/History/HistoryPage.razor b/LiftLog.Ui/Pages/History/HistoryPage.razor index f72da759..16947807 100644 --- a/LiftLog.Ui/Pages/History/HistoryPage.razor +++ b/LiftLog.Ui/Pages/History/HistoryPage.razor @@ -8,6 +8,7 @@ @inject SessionService SessionService @inject NavigationManager NavigationManager @inject IState CurrentSessionState +@inject IState AppState @inject IState ProgramState @inject IDispatcher Dispatcher @inject ILogger Logger @@ -25,26 +26,25 @@ else { {_selectedSession = session; _deleteDialog?.Open();}) /> - - - + + } @@ -87,6 +87,7 @@ else { currentMonth = date; filteredToMonthSessions = _latestSessions.Where(s => s.Date.Month == date.Month && s.Date.Year == date.Year).ToList(); + Dispatcher.Dispatch(new SetHistoryYearMonthAction(date.Year, date.Month)); } private void CreateSessionAtDate(DateOnly date) @@ -105,7 +106,15 @@ else this._latestSessions = await SessionService .GetLatestSessionsAsync() .ToListAsync(); - HandleMonthChange(DateOnly.FromDateTime(DateTime.Now)); + + if (AppState.Value.HistoryYearMonth is (int year, int month)) + { + HandleMonthChange(new DateOnly(year, month, 1)); + } + else + { + HandleMonthChange(DateOnly.FromDateTime(DateTime.Now)); + } await base.OnInitializedAsync(); sw.Stop(); Logger.LogInformation($"History page initialized in {sw.ElapsedMilliseconds} ms"); diff --git a/LiftLog.Ui/Shared/Presentation/Card.razor b/LiftLog.Ui/Shared/Presentation/Card.razor index ae38f367..f7304af4 100644 --- a/LiftLog.Ui/Shared/Presentation/Card.razor +++ b/LiftLog.Ui/Shared/Presentation/Card.razor @@ -2,7 +2,10 @@
+ @onclick="HandleOnClick" + @oncontextmenu=OnContextMenu @oncontextmenu:preventDefault=@(OnContextMenu.HasDelegate) + > + @if (OnClick != null) { @@ -20,6 +23,8 @@ [Parameter] public Action? OnClick { get; set; } + [Parameter] public EventCallback OnContextMenu { get; set; } + [Parameter] public bool IsHighlighted { get; set; } [Parameter] public CardType Type { get; set; } = CardType.Outlined; diff --git a/LiftLog.Ui/Shared/Presentation/CardList.razor b/LiftLog.Ui/Shared/Presentation/CardList.razor index f7df211c..46a50e5d 100644 --- a/LiftLog.Ui/Shared/Presentation/CardList.razor +++ b/LiftLog.Ui/Shared/Presentation/CardList.razor @@ -2,7 +2,12 @@
@foreach (var item in Items) { - OnClick(item) : null)> + OnContextMenu.InvokeAsync(item)) + IsHighlighted="ShouldHighlight?.Invoke(item) ?? false" + OnClick=@(OnClick != null ? _ => OnClick(item) : null)> @ChildContent?.Invoke(item) } @@ -16,6 +21,8 @@ [Parameter] public Action? OnClick { get; set; } + [Parameter] public EventCallback OnContextMenu { get; set; } + [Parameter] public Func? ShouldHighlight { get; set; } [Parameter] public string? CardClass { get; set; } diff --git a/LiftLog.Ui/Shared/Presentation/HistoryCalendar.razor b/LiftLog.Ui/Shared/Presentation/HistoryCalendar.razor index f0ca8528..639b61a1 100644 --- a/LiftLog.Ui/Shared/Presentation/HistoryCalendar.razor +++ b/LiftLog.Ui/Shared/Presentation/HistoryCalendar.razor @@ -2,7 +2,7 @@ @{ - var firstDayOfMonth = new DateOnly(_currentYear, _currentMonth, 1); + var firstDayOfMonth = new DateOnly(CurrentYear, CurrentMonth, 1); var firstDayOfWeek = (int)firstDayOfMonth.DayOfWeek; var lastDayOfPreviousMonth = firstDayOfMonth.AddDays(-1); var index = 0; @@ -12,7 +12,7 @@
-

@DateTimeFormatInfo.CurrentInfo.GetMonthName(_currentMonth) @_currentYear

+

@DateTimeFormatInfo.CurrentInfo.GetMonthName(CurrentMonth) @CurrentYear

@@ -28,24 +28,31 @@ @for (int i = 0; i < firstDayOfWeek; i++) { var date = lastDayOfPreviousMonth.AddDays(-i); - HandleDayClick(date)) OnDayLongPress=@(()=>HandleDayLongPress(date)) /> + HandleDayClick(date)) OnDayLongPress=@(()=>HandleDayLongPress(date)) /> } - @for (int i = 1; i <= DateTime.DaysInMonth(_currentYear, _currentMonth); i++) + @for (int i = 1; i <= DateTime.DaysInMonth(CurrentYear, CurrentMonth); i++) { - var date = new DateOnly(_currentYear, _currentMonth, i); + var date = new DateOnly(CurrentYear, CurrentMonth, i); HandleDayClick(date)) OnDayLongPress=@(()=>HandleDayLongPress(date)) /> } +@{var extraDay =0;} + @while(index % 7 != 0) + { + var date =new DateOnly(CurrentYear, CurrentMonth, DateTime.DaysInMonth(CurrentYear, CurrentMonth)).AddDays(++extraDay); + HandleDayClick(date)) OnDayLongPress=@(()=>HandleDayLongPress(date)) /> + } +
@code { - private int _currentMonth = DateTime.Now.Month; - private int _currentYear = DateTime.Now.Year; + [Parameter][EditorRequired] public int CurrentMonth {get;set;} + [Parameter][EditorRequired] public int CurrentYear {get;set;} private ILookup _sessionsByDate = null!; - private bool DisableNext => _currentYear == DateTime.Now.Year && _currentMonth == DateTime.Now.Month; + private bool DisableNext => CurrentYear == DateTime.Now.Year && CurrentMonth == DateTime.Now.Month; [Parameter] [EditorRequired] @@ -76,37 +83,37 @@ if(DisableNext){ return; } - if (_currentMonth == 12) + if (CurrentMonth == 12) { - _currentMonth = 1; - _currentYear++; + CurrentMonth = 1; + CurrentYear++; } else { - _currentMonth++; + CurrentMonth++; } - OnMonthChange.InvokeAsync(new DateOnly(_currentYear, _currentMonth, 1)); + OnMonthChange.InvokeAsync(new DateOnly(CurrentYear, CurrentMonth, 1)); } private void PreviousMonth() { - if (_currentMonth == 1) + if (CurrentMonth == 1) { - _currentMonth = 12; - _currentYear--; + CurrentMonth = 12; + CurrentYear--; } else { - _currentMonth--; + CurrentMonth--; } - OnMonthChange.InvokeAsync(new DateOnly(_currentYear, _currentMonth, 1)); + OnMonthChange.InvokeAsync(new DateOnly(CurrentYear, CurrentMonth, 1)); } private void GoToToday() { - _currentMonth = DateTime.Now.Month; - _currentYear = DateTime.Now.Year; + CurrentMonth = DateTime.Now.Month; + CurrentYear = DateTime.Now.Year; } private async Task HandleDayLongPress(DateOnly date) diff --git a/LiftLog.Ui/Shared/Presentation/HistoryCalendarDay.razor b/LiftLog.Ui/Shared/Presentation/HistoryCalendarDay.razor index b6e9e4f2..90d50cd1 100644 --- a/LiftLog.Ui/Shared/Presentation/HistoryCalendarDay.razor +++ b/LiftLog.Ui/Shared/Presentation/HistoryCalendarDay.razor @@ -44,6 +44,9 @@ [EditorRequired] public EventCallback OnDayLongPress {get;set;} + [Parameter] + public bool ForOtherMonth { get;set; } + string AnimationClass = "scale-0 animate-zoom-in"; bool isHolding = false; diff --git a/LiftLog.Ui/Shared/Presentation/SessionSummary.razor b/LiftLog.Ui/Shared/Presentation/SessionSummary.razor index cdce71fc..f82f0a6c 100644 --- a/LiftLog.Ui/Shared/Presentation/SessionSummary.razor +++ b/LiftLog.Ui/Shared/Presentation/SessionSummary.razor @@ -1,47 +1,50 @@ -
+
@foreach (var exercise in Session.RecordedExercises) { var splitWeights = exercise.PerSetWeight && !exercise.PotentialSets.All(s => s.Weight == exercise.Weight); - - @exercise.Blueprint.Name - @if(ShowSets || ShowWeight) - { - - @if (ShowSets && !splitWeights) + + @exercise.Blueprint.Name + @if(ShowSets || ShowWeight) + { + @if(!splitWeights) { - - @(exercise.Blueprint.Sets)x@(exercise.Blueprint.RepsPerSet) - - @if(ShowWeight) + + + @if (ShowSets) { - @@ + + @(exercise.Blueprint.Sets)x@(exercise.Blueprint.RepsPerSet) + + @if(ShowWeight) + { + @@ + } } - } - @if (ShowWeight && !splitWeights) - { - + @if (ShowWeight) + { + + } + } @if (ShowWeight && splitWeights) { - + @foreach(var set in exercise.PotentialSets) { - + @if (ShowSets){ @(set.Set?.RepsCompleted ?? exercise.Blueprint.RepsPerSet)@@ } - } } - - } + } }
diff --git a/LiftLog.Ui/Store/App/AppActions.cs b/LiftLog.Ui/Store/App/AppActions.cs index 8ec8d06a..65db138c 100644 --- a/LiftLog.Ui/Store/App/AppActions.cs +++ b/LiftLog.Ui/Store/App/AppActions.cs @@ -14,6 +14,8 @@ public record ToastAction(string Message); public record SetBackNavigationUrlAction(string? BackNavigationUrl); +public record SetHistoryYearMonthAction(int Year, int Month); + public record NavigateAction( string Path, bool ClearPageStack = true, diff --git a/LiftLog.Ui/Store/App/AppFeature.cs b/LiftLog.Ui/Store/App/AppFeature.cs index 9ca20d7b..71a2ba0d 100644 --- a/LiftLog.Ui/Store/App/AppFeature.cs +++ b/LiftLog.Ui/Store/App/AppFeature.cs @@ -21,6 +21,7 @@ protected override AppState GetInitialState() => HasRequestedNotificationPermission: false, ColorScheme: new AppColorScheme(), AppLaunchCount: 0, - AppRatingResult: AppRatingResult.NotRated + AppRatingResult: AppRatingResult.NotRated, + HistoryYearMonth: null ); } diff --git a/LiftLog.Ui/Store/App/AppReducers.cs b/LiftLog.Ui/Store/App/AppReducers.cs index a667ed16..44fb4571 100644 --- a/LiftLog.Ui/Store/App/AppReducers.cs +++ b/LiftLog.Ui/Store/App/AppReducers.cs @@ -18,6 +18,13 @@ state with ProState = new(action.ProToken) }; + [ReducerMethod] + public static AppState SetHistoryYearMonth(AppState state, SetHistoryYearMonthAction action) => + state with + { + HistoryYearMonth = (action.Year, action.Month) + }; + [ReducerMethod] public static AppState SetThemeColor(AppState state, ThemeColorUpdatedAction action) => state with diff --git a/LiftLog.Ui/Store/App/AppState.cs b/LiftLog.Ui/Store/App/AppState.cs index 432bba35..7eadffbc 100644 --- a/LiftLog.Ui/Store/App/AppState.cs +++ b/LiftLog.Ui/Store/App/AppState.cs @@ -15,7 +15,8 @@ public record AppState( bool HasRequestedNotificationPermission, AppColorScheme ColorScheme, int AppLaunchCount, - AppRatingResult AppRatingResult + AppRatingResult AppRatingResult, + (int Year, int Month)? HistoryYearMonth ); public enum AppRatingResult