parent
6071957a40
commit
b14d20f1f4
|
@ -6,7 +6,9 @@ import {
|
||||||
import {useCallback, useMemo, useState} from 'react'
|
import {useCallback, useMemo, useState} from 'react'
|
||||||
import {GestureResponderEvent, Text} from 'react-native'
|
import {GestureResponderEvent, Text} from 'react-native'
|
||||||
import {Divider, List, Menu} from 'react-native-paper'
|
import {Divider, List, Menu} from 'react-native-paper'
|
||||||
|
import {getBestSet} from './best.service'
|
||||||
import {planRepo} from './db'
|
import {planRepo} from './db'
|
||||||
|
import {defaultSet} from './gym-set'
|
||||||
import {Plan} from './plan'
|
import {Plan} from './plan'
|
||||||
import {PlanPageParams} from './plan-page-params'
|
import {PlanPageParams} from './plan-page-params'
|
||||||
import {DAYS} from './time'
|
import {DAYS} from './time'
|
||||||
|
@ -40,7 +42,10 @@ export default function PlanItem({
|
||||||
const start = useCallback(async () => {
|
const start = useCallback(async () => {
|
||||||
console.log(`${PlanItem.name}.start:`, {item})
|
console.log(`${PlanItem.name}.start:`, {item})
|
||||||
setShow(false)
|
setShow(false)
|
||||||
navigation.navigate('StartPlan', {plan: item})
|
const workout = item.workouts.split(',')[0]
|
||||||
|
let first = await getBestSet(workout)
|
||||||
|
if (!first) first = {...defaultSet, name: workout}
|
||||||
|
navigation.navigate('StartPlan', {plan: item, first})
|
||||||
}, [item, navigation])
|
}, [item, navigation])
|
||||||
|
|
||||||
const longPress = useCallback(
|
const longPress = useCallback(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {RouteProp, useFocusEffect, useRoute} from '@react-navigation/native'
|
import {RouteProp, useFocusEffect, useRoute} from '@react-navigation/native'
|
||||||
import {useCallback, useEffect, useMemo, useRef, useState} from 'react'
|
import {useCallback, useMemo, useRef, useState} from 'react'
|
||||||
import {NativeModules, TextInput, View} from 'react-native'
|
import {NativeModules, TextInput, View} from 'react-native'
|
||||||
import {FlatList} from 'react-native-gesture-handler'
|
import {FlatList} from 'react-native-gesture-handler'
|
||||||
import {Button} from 'react-native-paper'
|
import {Button} from 'react-native-paper'
|
||||||
|
@ -8,7 +8,7 @@ import {PADDING} from './constants'
|
||||||
import CountMany from './count-many'
|
import CountMany from './count-many'
|
||||||
import {AppDataSource} from './data-source'
|
import {AppDataSource} from './data-source'
|
||||||
import {getNow, setRepo, settingsRepo} from './db'
|
import {getNow, setRepo, settingsRepo} from './db'
|
||||||
import GymSet from './gym-set'
|
import GymSet, {defaultSet} from './gym-set'
|
||||||
import MassiveInput from './MassiveInput'
|
import MassiveInput from './MassiveInput'
|
||||||
import {PlanPageParams} from './plan-page-params'
|
import {PlanPageParams} from './plan-page-params'
|
||||||
import Settings from './settings'
|
import Settings from './settings'
|
||||||
|
@ -18,10 +18,10 @@ import {toast} from './toast'
|
||||||
|
|
||||||
export default function StartPlan() {
|
export default function StartPlan() {
|
||||||
const {params} = useRoute<RouteProp<PlanPageParams, 'StartPlan'>>()
|
const {params} = useRoute<RouteProp<PlanPageParams, 'StartPlan'>>()
|
||||||
const [reps, setReps] = useState('')
|
const [reps, setReps] = useState(params.first?.reps.toString() || '0')
|
||||||
const [weight, setWeight] = useState('')
|
const [weight, setWeight] = useState(params.first?.weight.toString() || '0')
|
||||||
const [unit, setUnit] = useState<string>('kg')
|
const [unit, setUnit] = useState<string>(params.first?.unit || 'kg')
|
||||||
const [best, setBest] = useState<GymSet>()
|
const [best, setBest] = useState<GymSet>(params.first || defaultSet)
|
||||||
const [selected, setSelected] = useState(0)
|
const [selected, setSelected] = useState(0)
|
||||||
const [settings, setSettings] = useState<Settings>()
|
const [settings, setSettings] = useState<Settings>()
|
||||||
const [counts, setCounts] = useState<CountMany[]>()
|
const [counts, setCounts] = useState<CountMany[]>()
|
||||||
|
@ -54,7 +54,6 @@ export default function StartPlan() {
|
||||||
const newCounts = await AppDataSource.manager.query(select)
|
const newCounts = await AppDataSource.manager.query(select)
|
||||||
console.log(`${StartPlan.name}.focus:`, {newCounts})
|
console.log(`${StartPlan.name}.focus:`, {newCounts})
|
||||||
setCounts(newCounts)
|
setCounts(newCounts)
|
||||||
return newCounts
|
|
||||||
}, [workouts])
|
}, [workouts])
|
||||||
|
|
||||||
const select = useCallback(
|
const select = useCallback(
|
||||||
|
@ -65,6 +64,11 @@ export default function StartPlan() {
|
||||||
const workout = counts ? counts[index] : newCounts[index]
|
const workout = counts ? counts[index] : newCounts[index]
|
||||||
console.log(`${StartPlan.name}.next:`, {workout})
|
console.log(`${StartPlan.name}.next:`, {workout})
|
||||||
const newBest = await getBestSet(workout.name)
|
const newBest = await getBestSet(workout.name)
|
||||||
|
if (!newBest)
|
||||||
|
return setBest({
|
||||||
|
...best,
|
||||||
|
name: workout.name,
|
||||||
|
})
|
||||||
delete newBest.id
|
delete newBest.id
|
||||||
console.log(`${StartPlan.name}.next:`, {newBest})
|
console.log(`${StartPlan.name}.next:`, {newBest})
|
||||||
setReps(newBest.reps.toString())
|
setReps(newBest.reps.toString())
|
||||||
|
@ -78,25 +82,21 @@ export default function StartPlan() {
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
settingsRepo.findOne({where: {}}).then(setSettings)
|
settingsRepo.findOne({where: {}}).then(setSettings)
|
||||||
}, []),
|
refresh()
|
||||||
|
}, [refresh]),
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
refresh().then(newCounts => select(0, newCounts))
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [refresh])
|
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
console.log(`${StartPlan.name}.handleSubmit:`, {reps, weight, unit, best})
|
|
||||||
const [{now}] = await getNow()
|
const [{now}] = await getNow()
|
||||||
await setRepo.save({
|
const newSet: GymSet = {
|
||||||
...best,
|
...best,
|
||||||
weight: +weight,
|
weight: +weight,
|
||||||
reps: +reps,
|
reps: +reps,
|
||||||
unit,
|
unit,
|
||||||
created: now,
|
created: now,
|
||||||
hidden: false,
|
hidden: false,
|
||||||
})
|
}
|
||||||
|
await setRepo.save(newSet)
|
||||||
await refresh()
|
await refresh()
|
||||||
if (
|
if (
|
||||||
settings.notify &&
|
settings.notify &&
|
||||||
|
|
|
@ -8,6 +8,7 @@ export type PlanPageParams = {
|
||||||
}
|
}
|
||||||
StartPlan: {
|
StartPlan: {
|
||||||
plan: Plan
|
plan: Plan
|
||||||
|
first?: GymSet
|
||||||
}
|
}
|
||||||
EditSet: {
|
EditSet: {
|
||||||
set: GymSet
|
set: GymSet
|
||||||
|
|
Loading…
Reference in New Issue