parent
9849ef6834
commit
86509eb211
|
@ -4,13 +4,14 @@ import {
|
|||
useNavigation,
|
||||
useRoute,
|
||||
} from '@react-navigation/native';
|
||||
import React, {useCallback, useState} from 'react';
|
||||
import React, {useCallback, useContext, useState} from 'react';
|
||||
import {ScrollView, View} from 'react-native';
|
||||
import DocumentPicker from 'react-native-document-picker';
|
||||
import {Button, Card, IconButton, TouchableRipple} from 'react-native-paper';
|
||||
import ConfirmDialog from './ConfirmDialog';
|
||||
import {MARGIN, PADDING} from './constants';
|
||||
import MassiveInput from './MassiveInput';
|
||||
import {SnackbarContext} from './MassiveSnack';
|
||||
import {updatePlanWorkouts} from './plan.service';
|
||||
import {addSet, updateManySet, updateSetImage} from './set.service';
|
||||
import {settings} from './settings.service';
|
||||
|
@ -26,6 +27,7 @@ export default function EditWorkout() {
|
|||
const [minutes, setMinutes] = useState(params.value.minutes?.toString());
|
||||
const [seconds, setSeconds] = useState(params.value.seconds?.toString());
|
||||
const [sets, setSets] = useState(params.value.sets?.toString());
|
||||
const {toast} = useContext(SnackbarContext);
|
||||
const navigation = useNavigation();
|
||||
|
||||
useFocusEffect(
|
||||
|
@ -89,6 +91,18 @@ export default function EditWorkout() {
|
|||
setShowRemove(false);
|
||||
}, []);
|
||||
|
||||
const handleName = (value: string) => {
|
||||
setName(value.replace(/,|'/g, ''));
|
||||
if (value.match(/,|'/))
|
||||
toast('Commas and single quotes would break CSV exports', 6000);
|
||||
};
|
||||
|
||||
const handleSteps = (value: string) => {
|
||||
setSteps(value.replace(/,|'/g, ''));
|
||||
if (value.match(/,|'/))
|
||||
toast('Commas and single quotes would break CSV exports', 6000);
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={{padding: PADDING}}>
|
||||
<ScrollView style={{height: '90%'}}>
|
||||
|
@ -96,13 +110,13 @@ export default function EditWorkout() {
|
|||
autoFocus
|
||||
label="Name"
|
||||
value={name}
|
||||
onChangeText={setName}
|
||||
onChangeText={handleName}
|
||||
/>
|
||||
{!!settings.steps && (
|
||||
<MassiveInput
|
||||
selectTextOnFocus={false}
|
||||
value={steps}
|
||||
onChangeText={setSteps}
|
||||
onChangeText={handleSteps}
|
||||
label="Steps"
|
||||
multiline
|
||||
/>
|
||||
|
|
20
SetForm.tsx
20
SetForm.tsx
|
@ -1,7 +1,8 @@
|
|||
import React, {useEffect, useRef, useState} from 'react';
|
||||
import React, {useContext, useEffect, useRef, useState} from 'react';
|
||||
import {ScrollView} from 'react-native';
|
||||
import {Button} from 'react-native-paper';
|
||||
import MassiveInput from './MassiveInput';
|
||||
import {SnackbarContext} from './MassiveSnack';
|
||||
import Set from './set';
|
||||
import {getSets} from './set.service';
|
||||
import {settings} from './settings.service';
|
||||
|
@ -24,6 +25,7 @@ export default function SetForm({
|
|||
start: 0,
|
||||
end: set.reps.toString().length,
|
||||
});
|
||||
const {toast} = useContext(SnackbarContext);
|
||||
const weightRef = useRef<any>(null);
|
||||
const repsRef = useRef<any>(null);
|
||||
const unitRef = useRef<any>(null);
|
||||
|
@ -51,13 +53,25 @@ export default function SetForm({
|
|||
});
|
||||
};
|
||||
|
||||
const handleName = (value: string) => {
|
||||
setName(value.replace(/,|'/g, ''));
|
||||
if (value.match(/,|'/))
|
||||
toast('Commas and single quotes would break CSV exports', 6000);
|
||||
};
|
||||
|
||||
const handleUnit = (value: string) => {
|
||||
setUnit(value.replace(/,|'/g, ''));
|
||||
if (value.match(/,|'/))
|
||||
toast('Commas and single quotes would break CSV exports', 6000);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<ScrollView style={{height: '90%'}}>
|
||||
<MassiveInput
|
||||
label="Name"
|
||||
value={name}
|
||||
onChangeText={setName}
|
||||
onChangeText={handleName}
|
||||
autoCorrect={false}
|
||||
autoFocus={!name}
|
||||
blurOnSubmit={false}
|
||||
|
@ -88,7 +102,7 @@ export default function SetForm({
|
|||
autoCapitalize="none"
|
||||
label="Unit"
|
||||
value={unit}
|
||||
onChangeText={setUnit}
|
||||
onChangeText={handleUnit}
|
||||
innerRef={unitRef}
|
||||
/>
|
||||
)}
|
||||
|
|
|
@ -41,7 +41,7 @@ export default function WorkoutItem({
|
|||
<List.Item
|
||||
onPress={() => navigation.navigate('EditWorkout', {value: item})}
|
||||
title={item.name}
|
||||
description={`${item.sets} sets with ${minutes}:${seconds} rest`}
|
||||
description={`${item.sets} sets ${minutes}:${seconds} rest`}
|
||||
onLongPress={longPress}
|
||||
left={() =>
|
||||
item.image && (
|
||||
|
|
Loading…
Reference in New Issue