🩹 💄 🛂 Fix Move Form Screen (#20)

Co-authored-by: Alexis DRAI <alexis.drai@etu.uca.fr>
Reviewed-on: #20
Alexis Drai 2 years ago
parent 04aab430fc
commit a2de887095

@ -1,6 +1,6 @@
// screens/moves/MoveFormScreen.tsx // screens/moves/MoveFormScreen.tsx
import React, { useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Button, StyleSheet, Text, TextInput } from 'react-native'; import { Button, StyleSheet, Text, TextInput } from 'react-native';
import { StackNavigationProp } from '@react-navigation/stack'; import { StackNavigationProp } from '@react-navigation/stack';
import { RootStackParamList } from "../../navigation/navigationTypes"; import { RootStackParamList } from "../../navigation/navigationTypes";
@ -44,6 +44,12 @@ const MoveFormScreen = ({ navigation, route }: Props) => {
schemaVersion: 2 schemaVersion: 2
}); });
useEffect(() => {
navigation.setOptions({
title: route.params?.move ? route.params.move.name : 'New move',
});
}, [navigation, route.params?.move]);
const [selectedWeakAgainst, setSelectedWeakAgainst] = useState<string[]>(move.type.weakAgainst); const [selectedWeakAgainst, setSelectedWeakAgainst] = useState<string[]>(move.type.weakAgainst);
const [selectedEffectiveAgainst, setSelectedEffectiveAgainst] = useState<string[]>(move.type.effectiveAgainst); const [selectedEffectiveAgainst, setSelectedEffectiveAgainst] = useState<string[]>(move.type.effectiveAgainst);
@ -96,14 +102,22 @@ const MoveFormScreen = ({ navigation, route }: Props) => {
<Text style={styles.label}>Power: </Text> <Text style={styles.label}>Power: </Text>
<TextInput <TextInput
value={move.power.toString()} value={move.power.toString()}
onChangeText={(text) => setMove({ ...move, power: Number(text) })} onChangeText={(text) => {
if (!isNaN(Number(text))) {
setMove({ ...move, power: Number(text) });
}
}}
style={styles.input} style={styles.input}
keyboardType="numeric" keyboardType="numeric"
/> />
<Text style={styles.label}>Accuracy: </Text> <Text style={styles.label}>Accuracy: </Text>
<TextInput <TextInput
value={move.accuracy.toString()} value={move.accuracy.toString()}
onChangeText={(text) => setMove({ ...move, accuracy: Number(text) })} onChangeText={(text) => {
if (!isNaN(Number(text))) {
setMove({ ...move, accuracy: Number(text) });
}
}}
style={styles.input} style={styles.input}
keyboardType="numeric" keyboardType="numeric"
/> />

Loading…
Cancel
Save