Fix default new sets

This commit is contained in:
Brandon Presley 2022-11-04 16:02:06 +13:00
parent ba61e79808
commit f9449a9860
3 changed files with 19 additions and 18 deletions

View File

@ -11,6 +11,7 @@ import {Button, Card, TouchableRipple} from 'react-native-paper'
import ConfirmDialog from './ConfirmDialog'
import {MARGIN, PADDING} from './constants'
import {getNow, planRepo, setRepo, settingsRepo} from './db'
import {defaultSet} from './gym-set'
import MassiveInput from './MassiveInput'
import Settings from './settings'
import StackHeader from './StackHeader'
@ -68,9 +69,8 @@ export default function EditWorkout() {
const add = async () => {
const [{now}] = await getNow()
await setRepo.save({
...defaultSet,
name,
reps: 0,
weight: 0,
hidden: true,
image: uri,
minutes: minutes ? +minutes : 3,

View File

@ -3,13 +3,13 @@ import {
useFocusEffect,
useNavigation,
} from '@react-navigation/native'
import {useCallback, useEffect, useState} from 'react'
import {useCallback, useState} from 'react'
import {FlatList} from 'react-native'
import {List} from 'react-native-paper'
import {Like} from 'typeorm'
import {getNow, setRepo, settingsRepo} from './db'
import DrawerHeader from './DrawerHeader'
import GymSet from './gym-set'
import GymSet, {defaultSet} from './gym-set'
import {HomePageParams} from './home-page-params'
import Page from './Page'
import SetItem from './SetItem'
@ -19,17 +19,13 @@ const limit = 15
export default function SetList() {
const [sets, setSets] = useState<GymSet[]>([])
const [set, setSet] = useState<GymSet>(new GymSet())
const [set, setSet] = useState<GymSet>(defaultSet)
const [offset, setOffset] = useState(0)
const [term, setTerm] = useState('')
const [end, setEnd] = useState(false)
const [settings, setSettings] = useState<Settings>()
const navigation = useNavigation<NavigationProp<HomePageParams>>()
useEffect(() => {
console.log({sets, set})
}, [sets, set])
const refresh = useCallback(async (value: string) => {
const newSets = await setRepo.find({
where: {name: Like(`%${value}%`), hidden: 0 as any},
@ -88,16 +84,8 @@ export default function SetList() {
console.log(`${SetList.name}.onAdd`, {set})
const [{now}] = await getNow()
const newSet: GymSet = set || {
...defaultSet,
created: now,
hidden: false,
image: '',
minutes: 3,
seconds: 30,
name: '',
reps: 0,
sets: 0,
unit: 'kg',
weight: 0,
}
newSet.created = now
navigation.navigate('EditSet', {set: newSet})

View File

@ -38,3 +38,16 @@ export default class GymSet {
@Column('text')
steps?: string
}
export const defaultSet: GymSet = {
created: '',
name: '',
image: '',
hidden: false,
minutes: 3,
seconds: 30,
reps: 0,
sets: 0,
unit: 'kg',
weight: 0,
}