import React, {useRef, useState} from 'react'; import {ScrollView, Text} from 'react-native'; import {Button} from 'react-native-paper'; import MassiveInput from './MassiveInput'; import Set from './set'; export default function SetForm({ save, set, workouts, }: { set: Set; save: (set: Set) => void; workouts?: string[]; }) { const [name, setName] = useState(set.name); const [reps, setReps] = useState(set.reps.toString()); const [weight, setWeight] = useState(set.weight.toString()); const [unit, setUnit] = useState(set.unit); const [selection, setSelection] = useState({ start: 0, end: set.reps.toString().length, }); const weightRef = useRef(null); const repsRef = useRef(null); const handleSubmit = () => { if (!name) return; save({ name, reps: Number(reps), created: set.created, weight: Number(weight), id: set.id, unit, }); }; return ( <> repsRef.current?.focus()} /> weightRef.current?.focus()} selection={selection} onSelectionChange={e => setSelection(e.nativeEvent.selection)} autoFocus={!!name} blurOnSubmit={false} innerRef={repsRef} /> {set.created && ( {set.created.replace('T', ' ')} )} {workouts?.map((workout, index) => ( {workout} {index === workouts.length - 1 ? '.' : ', '} ))} ); }