You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.5 KiB
83 lines
2.5 KiB
using FiveThreeOneCalculator.Models;
|
|
using FiveThreeOneCalculator.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Extensions.Logging;
|
|
using MudBlazor;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace FiveThreeOneCalculator.Components
|
|
{
|
|
/// <summary>
|
|
/// Show lifts for the specified week / lift combination.
|
|
/// </summary>
|
|
public partial class LiftsForWeek : ComponentBase, IDisposable
|
|
{
|
|
[Inject] private ILogger<LiftsForWeek> _logger { get; set; }
|
|
|
|
[Parameter] public string Title { get; set; }
|
|
|
|
[Inject]
|
|
protected AppState appState { get; set; }
|
|
|
|
[Inject]
|
|
protected Calculator calculator { get; set; }
|
|
|
|
[Inject]
|
|
protected User user { get; set; }
|
|
|
|
[Inject]
|
|
IDialogService DialogService { get; set; }
|
|
|
|
/// <summary>
|
|
/// ORM based on the current selected lift.
|
|
/// </summary>
|
|
public float OneRepMax
|
|
{
|
|
get => user.GetUserModel().GetLift(appState.SelectedLift);
|
|
}
|
|
|
|
// Basic Lifecycle Functions
|
|
// There are Async versions of these
|
|
protected override void OnInitialized()
|
|
{
|
|
base.OnInitialized();
|
|
Title = "LiftsForWeek";
|
|
appState.StateChanged += async (source, property) => await AppState_StateChanged(source, property);
|
|
}
|
|
|
|
protected IEnumerable<Lift> GetLifts()
|
|
{
|
|
var liftMax = user.GetUserModel().GetLift(appState.SelectedLift);
|
|
var lifts = calculator.Calculate(liftMax)[appState.SelectedWeek];
|
|
var weights = lifts.Weight;
|
|
var reps = lifts.Reps;
|
|
int set = 0;
|
|
return reps.Zip(weights, (r, w) => new Lift{ RepCount = r, Weight = w, Set = ++set });
|
|
}
|
|
|
|
private async Task AppState_StateChanged(ComponentBase component, string property)
|
|
{
|
|
if (component != this)
|
|
{
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
private void OnEditLifts()
|
|
{
|
|
DialogService.Show<UserEditDialog>("Edit Maxes", new DialogOptions
|
|
{
|
|
MaxWidth = MaxWidth.Medium,
|
|
FullWidth = true
|
|
});
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
appState.StateChanged -= async (Source, Property) => await AppState_StateChanged(Source, Property);
|
|
}
|
|
}
|
|
}
|
|
|