Reduce state in StartPlan
Fixes several issues related to old data.
This commit is contained in:
parent
86566fb54d
commit
1273b6a6d8
|
@ -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, {defaultSet} from './gym-set'
|
import GymSet 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'
|
||||||
|
@ -21,7 +21,6 @@ export default function StartPlan() {
|
||||||
const [reps, setReps] = useState(params.first?.reps.toString() || '0')
|
const [reps, setReps] = useState(params.first?.reps.toString() || '0')
|
||||||
const [weight, setWeight] = useState(params.first?.weight.toString() || '0')
|
const [weight, setWeight] = useState(params.first?.weight.toString() || '0')
|
||||||
const [unit, setUnit] = useState<string>(params.first?.unit || 'kg')
|
const [unit, setUnit] = useState<string>(params.first?.unit || 'kg')
|
||||||
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[]>()
|
||||||
|
@ -59,24 +58,18 @@ export default function StartPlan() {
|
||||||
const select = useCallback(
|
const select = useCallback(
|
||||||
async (index: number, newCounts?: CountMany[]) => {
|
async (index: number, newCounts?: CountMany[]) => {
|
||||||
setSelected(index)
|
setSelected(index)
|
||||||
console.log(`${StartPlan.name}.next:`, {best, index})
|
|
||||||
if (!counts && !newCounts) return
|
if (!counts && !newCounts) return
|
||||||
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)
|
if (!newBest) return
|
||||||
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())
|
||||||
setWeight(newBest.weight.toString())
|
setWeight(newBest.weight.toString())
|
||||||
setUnit(newBest.unit)
|
setUnit(newBest.unit)
|
||||||
setBest(newBest)
|
|
||||||
},
|
},
|
||||||
[counts, best],
|
[counts],
|
||||||
)
|
)
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
|
@ -88,6 +81,9 @@ export default function StartPlan() {
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
const [{now}] = await getNow()
|
const [{now}] = await getNow()
|
||||||
|
const workout = counts[selected]
|
||||||
|
const best = await getBestSet(workout.name)
|
||||||
|
delete best.id
|
||||||
const newSet: GymSet = {
|
const newSet: GymSet = {
|
||||||
...best,
|
...best,
|
||||||
weight: +weight,
|
weight: +weight,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user