Show list of current workouts when adding set

This commit is contained in:
Brandon Presley 2022-08-24 15:36:49 +12:00
parent 24a44056f9
commit bc3a39c4b6
4 changed files with 19 additions and 10 deletions

View File

@ -78,7 +78,7 @@ export default function EditSet() {
return (
<View style={{padding: 10}}>
<SetForm save={save} set={params.set} next={params.next} />
<SetForm save={save} set={params.set} workouts={params.workouts} />
</View>
);
}

View File

@ -13,7 +13,7 @@ export type HomePageParams = {
Sets: {};
EditSet: {
set: Set;
next?: string;
workouts?: string[];
};
};

View File

@ -6,11 +6,11 @@ import Set from './set';
export default function SetForm({
save,
set,
next,
workouts,
}: {
set: Set;
save: (set: Set) => void;
next?: string;
workouts?: string[];
}) {
const [name, setName] = useState(set.name);
const [reps, setReps] = useState(set.reps.toString());
@ -81,10 +81,19 @@ export default function SetForm({
/>
{set.created && (
<Text style={{marginBottom: 10}}>
Created: {set.created?.replace('T', ' ')}
{set.created.replace('T', ' ')}
</Text>
)}
{next && <Text>Next: {next}</Text>}
<Text>
{workouts?.map((workout, index) => (
<Text
key={workout}
style={{fontWeight: workout === name ? 'bold' : 'normal'}}>
{workout}
{index === workouts.length - 1 ? '.' : ', '}
</Text>
))}
</Text>
</ScrollView>
<Button
disabled={!name}

View File

@ -27,7 +27,7 @@ const defaultSet = {
export default function SetList() {
const [sets, setSets] = useState<Set[]>();
const [set, setSet] = useState<Set>();
const [nextWorkout, setNextWorkout] = useState<string>();
const [workouts, setWorkouts] = useState<string[]>([]);
const [offset, setOffset] = useState(0);
const [search, setSearch] = useState('');
const [refreshing, setRefreshing] = useState(false);
@ -125,7 +125,7 @@ export default function SetList() {
}
const best = await getBest(workout);
setSet({...best});
setNextWorkout(todaysWorkouts[todaysWorkouts.indexOf(workout) + 1]);
setWorkouts(todaysWorkouts);
}, [getTodaysSets, getTodaysPlan, getBest, db]);
useFocusEffect(
@ -171,9 +171,9 @@ export default function SetList() {
const onAdd = useCallback(async () => {
navigation.navigate('EditSet', {
set: set || {...defaultSet},
next: nextWorkout,
workouts,
});
}, [navigation, set, nextWorkout]);
}, [navigation, set, workouts]);
return (
<View style={styles.container}>