Retrieve last set when running a plan - 1.145

Closes #162

We should just keep it simple and get the most recent set instead of
trying to figure out what the best kind of maximum would be.
This commit is contained in:
Brandon Presley 2023-07-23 13:56:12 +12:00
parent 9833752bab
commit 85915b9aa0
6 changed files with 18 additions and 23 deletions

View File

@ -7,7 +7,6 @@ import {
import { useCallback, useEffect, useState } from 'react'
import { ScrollView, StyleSheet, View } from 'react-native'
import { Button, IconButton, Text } from 'react-native-paper'
import { getLast } from './best.service'
import { MARGIN, PADDING } from './constants'
import { planRepo, setRepo } from './db'
import { defaultSet } from './gym-set'
@ -80,7 +79,10 @@ export default function EditPlan() {
{typeof plan.id === 'number' && (
<IconButton
onPress={async () => {
let first = await getLast(workouts[0])
let first = await setRepo.findOne({
where: { name: workouts[0] },
order: { created: 'desc' },
})
if (!first) first = { ...defaultSet, name: workouts[0] }
delete first.id
navigation.navigate('StartPlan', { plan: params.plan, first })

View File

@ -6,8 +6,8 @@ import {
import { useCallback, useMemo, useState } from 'react'
import { Text } from 'react-native'
import { List } from 'react-native-paper'
import { getLast } from './best.service'
import { DARK_RIPPLE, LIGHT_RIPPLE } from './constants'
import { setRepo } from './db'
import { defaultSet } from './gym-set'
import { Plan } from './plan'
import { PlanPageParams } from './plan-page-params'
@ -37,7 +37,10 @@ export default function PlanItem({
const start = useCallback(async () => {
const workout = item.workouts.split(',')[0]
let first = await getLast(workout)
let first = await setRepo.findOne({
where: { name: workout },
order: { created: 'desc' },
})
if (!first) first = { ...defaultSet, name: workout }
delete first.id
if (ids.length === 0) {

View File

@ -9,7 +9,7 @@ import { useCallback, useMemo, useRef, useState } from 'react'
import { FlatList, NativeModules, TextInput, View } from 'react-native'
import { Button, IconButton, ProgressBar } from 'react-native-paper'
import AppInput from './AppInput'
import { getBestSet, getLast } from './best.service'
import { getBestSet } from './best.service'
import { PADDING } from './constants'
import CountMany from './count-many'
import { AppDataSource } from './data-source'
@ -66,7 +66,11 @@ export default function StartPlan() {
if (!counts && !newCounts) return
const workout = counts ? counts[index] : newCounts[index]
console.log(`${StartPlan.name}.next:`, { workout })
const last = await getLast(workout.name)
const last = await setRepo.findOne({
where: { name: workout.name },
order: { created: 'desc' },
})
console.log({ last })
if (!last) return
delete last.id
console.log(`${StartPlan.name}.select:`, { last })

View File

@ -85,8 +85,8 @@ android {
applicationId "com.massive"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 36170
versionName "1.144"
versionCode 36171
versionName "1.145"
}
signingConfigs {
release {

View File

@ -13,17 +13,3 @@ export const getBestSet = async (name: string): Promise<GymSet> => {
.addOrderBy('reps', 'DESC')
.getOne()
}
export const getLast = async (name: string): Promise<GymSet> => {
return setRepo
.createQueryBuilder()
.where('name = :name', { name })
.andWhere('reps >= 5')
.andWhere('strftime(\'%Y-%m-%d\', \'now\', \'localtime\') > created')
.groupBy('STRFTIME(\'%Y-%m-%d\', created)')
.orderBy('created', 'DESC')
.select('reps')
.addSelect('MAX(weight) as weight')
.addSelect('unit')
.getRawOne()
}

View File

@ -1,6 +1,6 @@
{
"name": "massive",
"version": "1.144",
"version": "1.145",
"private": true,
"license": "GPL-3.0-only",
"scripts": {