Add display of old values when mass editing sets
This commit is contained in:
parent
cf68b51fef
commit
9c21ee022d
31
EditSets.tsx
31
EditSets.tsx
|
@ -4,10 +4,11 @@ import {
|
||||||
useNavigation,
|
useNavigation,
|
||||||
useRoute,
|
useRoute,
|
||||||
} from '@react-navigation/native'
|
} from '@react-navigation/native'
|
||||||
import {useCallback, useRef, useState} from 'react'
|
import {useCallback, useState} from 'react'
|
||||||
import {TextInput, View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import DocumentPicker from 'react-native-document-picker'
|
import DocumentPicker from 'react-native-document-picker'
|
||||||
import {Button, Card, TouchableRipple} from 'react-native-paper'
|
import {Button, Card, TouchableRipple} from 'react-native-paper'
|
||||||
|
import {In} from 'typeorm'
|
||||||
import ConfirmDialog from './ConfirmDialog'
|
import ConfirmDialog from './ConfirmDialog'
|
||||||
import {MARGIN, PADDING} from './constants'
|
import {MARGIN, PADDING} from './constants'
|
||||||
import {setRepo, settingsRepo} from './db'
|
import {setRepo, settingsRepo} from './db'
|
||||||
|
@ -28,9 +29,10 @@ export default function EditSets() {
|
||||||
const [newImage, setNewImage] = useState('')
|
const [newImage, setNewImage] = useState('')
|
||||||
const [unit, setUnit] = useState('')
|
const [unit, setUnit] = useState('')
|
||||||
const [showRemove, setShowRemove] = useState(false)
|
const [showRemove, setShowRemove] = useState(false)
|
||||||
const weightRef = useRef<TextInput>(null)
|
const [names, setNames] = useState('')
|
||||||
const repsRef = useRef<TextInput>(null)
|
const [oldReps, setOldReps] = useState('')
|
||||||
const unitRef = useRef<TextInput>(null)
|
const [weights, setWeights] = useState('')
|
||||||
|
const [units, setUnits] = useState('')
|
||||||
|
|
||||||
const [selection, setSelection] = useState({
|
const [selection, setSelection] = useState({
|
||||||
start: 0,
|
start: 0,
|
||||||
|
@ -40,7 +42,13 @@ export default function EditSets() {
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
settingsRepo.findOne({where: {}}).then(setSettings)
|
settingsRepo.findOne({where: {}}).then(setSettings)
|
||||||
}, []),
|
setRepo.find({where: {id: In(ids)}}).then(sets => {
|
||||||
|
setNames(sets.map(set => set.name).join(', '))
|
||||||
|
setOldReps(sets.map(set => set.reps).join(', '))
|
||||||
|
setWeights(sets.map(set => set.weight).join(', '))
|
||||||
|
setUnits(sets.map(set => set.unit).join(', '))
|
||||||
|
})
|
||||||
|
}, [ids]),
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
|
@ -74,33 +82,29 @@ export default function EditSets() {
|
||||||
|
|
||||||
<View style={{padding: PADDING, flex: 1}}>
|
<View style={{padding: PADDING, flex: 1}}>
|
||||||
<MassiveInput
|
<MassiveInput
|
||||||
label="Name"
|
label={`Names: ${names}`}
|
||||||
value={name}
|
value={name}
|
||||||
onChangeText={setName}
|
onChangeText={setName}
|
||||||
autoCorrect={false}
|
autoCorrect={false}
|
||||||
autoFocus={!name}
|
autoFocus={!name}
|
||||||
onSubmitEditing={() => repsRef.current?.focus()}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<MassiveInput
|
<MassiveInput
|
||||||
label="Reps"
|
label={`Reps: ${oldReps}`}
|
||||||
keyboardType="numeric"
|
keyboardType="numeric"
|
||||||
value={reps}
|
value={reps}
|
||||||
onChangeText={setReps}
|
onChangeText={setReps}
|
||||||
onSubmitEditing={() => weightRef.current?.focus()}
|
|
||||||
selection={selection}
|
selection={selection}
|
||||||
onSelectionChange={e => setSelection(e.nativeEvent.selection)}
|
onSelectionChange={e => setSelection(e.nativeEvent.selection)}
|
||||||
autoFocus={!!name}
|
autoFocus={!!name}
|
||||||
innerRef={repsRef}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<MassiveInput
|
<MassiveInput
|
||||||
label="Weight"
|
label={`Weights: ${weights}`}
|
||||||
keyboardType="numeric"
|
keyboardType="numeric"
|
||||||
value={weight}
|
value={weight}
|
||||||
onChangeText={setWeight}
|
onChangeText={setWeight}
|
||||||
onSubmitEditing={handleSubmit}
|
onSubmitEditing={handleSubmit}
|
||||||
innerRef={weightRef}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{settings.showUnit && (
|
{settings.showUnit && (
|
||||||
|
@ -109,7 +113,6 @@ export default function EditSets() {
|
||||||
label="Unit"
|
label="Unit"
|
||||||
value={unit}
|
value={unit}
|
||||||
onChangeText={setUnit}
|
onChangeText={setUnit}
|
||||||
innerRef={unitRef}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user