Improve readability of SetForm

This commit is contained in:
Brandon Presley 2022-10-02 17:59:08 +13:00
parent 76a3584dbb
commit 6f41f87dc1

View File

@ -22,7 +22,7 @@ export default function SetForm({
const [name, setName] = useState(set.name); const [name, setName] = useState(set.name);
const [reps, setReps] = useState(set.reps.toString()); const [reps, setReps] = useState(set.reps.toString());
const [weight, setWeight] = useState(set.weight.toString()); const [weight, setWeight] = useState(set.weight.toString());
const [uri, setUri] = useState(set.image); const [newImage, setNewImage] = useState(set.image);
const [unit, setUnit] = useState(set.unit); const [unit, setUnit] = useState(set.unit);
const [showRemove, setShowRemove] = useState(false); const [showRemove, setShowRemove] = useState(false);
const [selection, setSelection] = useState({ const [selection, setSelection] = useState({
@ -37,12 +37,12 @@ export default function SetForm({
const unitRef = useRef<TextInput>(null); const unitRef = useRef<TextInput>(null);
const handleSubmit = async () => { const handleSubmit = async () => {
console.log(`${SetForm.name}.handleSubmit:`, {set, uri, name}); console.log(`${SetForm.name}.handleSubmit:`, {set, uri: newImage, name});
if (!name) return; if (!name) return;
let image = uri; let image = newImage;
if (!uri && !set.image && !removeImage) if (!newImage && !removeImage)
image = await getSets({search: name, limit: 1, offset: 0}).then( image = await getSets({search: name, limit: 1, offset: 0}).then(
([s]) => s?.image, ([gotSet]) => gotSet?.image,
); );
console.log(`${SetForm.name}.handleSubmit:`, {image}); console.log(`${SetForm.name}.handleSubmit:`, {image});
save({ save({
@ -75,11 +75,11 @@ export default function SetForm({
type: 'image/*', type: 'image/*',
copyTo: 'documentDirectory', copyTo: 'documentDirectory',
}); });
if (fileCopyUri) setUri(fileCopyUri); if (fileCopyUri) setNewImage(fileCopyUri);
}, []); }, []);
const handleRemove = useCallback(async () => { const handleRemove = useCallback(async () => {
setUri(''); setNewImage('');
setRemoveImage(true); setRemoveImage(true);
setShowRemove(false); setShowRemove(false);
}, []); }, []);
@ -140,15 +140,15 @@ export default function SetForm({
))} ))}
</View> </View>
)} )}
{!!settings.images && uri && ( {!!settings.images && newImage && (
<TouchableRipple <TouchableRipple
style={{marginBottom: MARGIN}} style={{marginBottom: MARGIN}}
onPress={changeImage} onPress={changeImage}
onLongPress={() => setShowRemove(true)}> onLongPress={() => setShowRemove(true)}>
<Card.Cover source={{uri}} /> <Card.Cover source={{uri: newImage}} />
</TouchableRipple> </TouchableRipple>
)} )}
{!!settings.images && !uri && ( {!!settings.images && !newImage && (
<Button <Button
style={{marginBottom: MARGIN}} style={{marginBottom: MARGIN}}
onPress={changeImage} onPress={changeImage}