From 9c21ee022de40bb252377fcf704950f2f04b98ab Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Wed, 14 Dec 2022 12:55:03 +1300 Subject: [PATCH] Add display of old values when mass editing sets --- EditSets.tsx | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/EditSets.tsx b/EditSets.tsx index 8e14db5..88edb7c 100644 --- a/EditSets.tsx +++ b/EditSets.tsx @@ -4,10 +4,11 @@ import { useNavigation, useRoute, } from '@react-navigation/native' -import {useCallback, useRef, useState} from 'react' -import {TextInput, View} from 'react-native' +import {useCallback, useState} from 'react' +import {View} from 'react-native' import DocumentPicker from 'react-native-document-picker' import {Button, Card, TouchableRipple} from 'react-native-paper' +import {In} from 'typeorm' import ConfirmDialog from './ConfirmDialog' import {MARGIN, PADDING} from './constants' import {setRepo, settingsRepo} from './db' @@ -28,9 +29,10 @@ export default function EditSets() { const [newImage, setNewImage] = useState('') const [unit, setUnit] = useState('') const [showRemove, setShowRemove] = useState(false) - const weightRef = useRef(null) - const repsRef = useRef(null) - const unitRef = useRef(null) + const [names, setNames] = useState('') + const [oldReps, setOldReps] = useState('') + const [weights, setWeights] = useState('') + const [units, setUnits] = useState('') const [selection, setSelection] = useState({ start: 0, @@ -40,7 +42,13 @@ export default function EditSets() { useFocusEffect( useCallback(() => { 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 () => { @@ -74,33 +82,29 @@ export default function EditSets() { repsRef.current?.focus()} /> weightRef.current?.focus()} selection={selection} onSelectionChange={e => setSelection(e.nativeEvent.selection)} autoFocus={!!name} - innerRef={repsRef} /> {settings.showUnit && ( @@ -109,7 +113,6 @@ export default function EditSets() { label="Unit" value={unit} onChangeText={setUnit} - innerRef={unitRef} /> )}