diff --git a/EditPlan.tsx b/EditPlan.tsx index 86edf1a..43ca8d8 100644 --- a/EditPlan.tsx +++ b/EditPlan.tsx @@ -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' && ( { - 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 }) diff --git a/PlanItem.tsx b/PlanItem.tsx index 5631af1..067a9ee 100644 --- a/PlanItem.tsx +++ b/PlanItem.tsx @@ -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) { diff --git a/StartPlan.tsx b/StartPlan.tsx index 7608fc7..dc38790 100644 --- a/StartPlan.tsx +++ b/StartPlan.tsx @@ -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 }) diff --git a/android/app/build.gradle b/android/app/build.gradle index dd6e7d1..6898c20 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -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 { diff --git a/best.service.ts b/best.service.ts index 882b0c1..457a9d2 100644 --- a/best.service.ts +++ b/best.service.ts @@ -13,17 +13,3 @@ export const getBestSet = async (name: string): Promise => { .addOrderBy('reps', 'DESC') .getOne() } - -export const getLast = async (name: string): Promise => { - 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() -} diff --git a/package.json b/package.json index 30cde4e..a358360 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "massive", - "version": "1.144", + "version": "1.145", "private": true, "license": "GPL-3.0-only", "scripts": {