parent
bb986a8929
commit
495bdb9d3b
@ -1,11 +1,14 @@
|
||||
// entities/Move.ts
|
||||
|
||||
import { Type } from "./Type";
|
||||
import { Type } from "./Type";
|
||||
import { MoveCategoryName } from "./MoveCategoryName";
|
||||
|
||||
export interface Move {
|
||||
id: string | null;
|
||||
name: string;
|
||||
category: string;
|
||||
category: MoveCategoryName;
|
||||
power: number;
|
||||
accuracy: number;
|
||||
type: Type;
|
||||
schemaVersion: number;
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
export enum MoveCategoryName {
|
||||
PHYSICAL = 'PHYSICAL',
|
||||
SPECIAL = 'SPECIAL',
|
||||
STATUS = 'STATUS',
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
// entities/Type.ts
|
||||
|
||||
import { TypeName } from "./TypeName";
|
||||
|
||||
export interface Type {
|
||||
name: string;
|
||||
name: TypeName;
|
||||
weakAgainst: string[];
|
||||
effectiveAgainst: string[];
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
export enum TypeName {
|
||||
NORMAL = 'NORMAL',
|
||||
GRASS = 'GRASS',
|
||||
ELECTRIC = 'ELECTRIC',
|
||||
WATER = 'WATER',
|
||||
FIRE = 'FIRE',
|
||||
BUG = 'BUG',
|
||||
GHOST = 'GHOST',
|
||||
PSYCHIC = 'PSYCHIC',
|
||||
STEEL = 'STEEL',
|
||||
DARK = 'DARK',
|
||||
FLYING = 'FLYING',
|
||||
ICE = 'ICE',
|
||||
POISON = 'POISON',
|
||||
GROUND = 'GROUND',
|
||||
ROCK = 'ROCK',
|
||||
DRAGON = 'DRAGON',
|
||||
FIGHTING = 'FIGHTING',
|
||||
FAIRY = 'FAIRY',
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
// navigation/constants.ts
|
||||
|
||||
export const MOVE_DETAIL = 'MoveDetail';
|
||||
export const MOVE_FORM = 'MoveForm';
|
||||
export const MOVE_LIST = 'MoveList';
|
@ -0,0 +1,111 @@
|
||||
// screens/moves/MoveFormScreen.tsx
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { Button, StyleSheet, TextInput, View } from 'react-native';
|
||||
import { StackNavigationProp } from '@react-navigation/stack';
|
||||
import { RootStackParamList } from "../../navigation/navigationTypes";
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { createMove, updateMove } from '../../redux/actions/moveActions';
|
||||
import { AppDispatch } from "../../redux/store";
|
||||
import { Move } from "../../entities/Move";
|
||||
import { RouteProp } from "@react-navigation/native";
|
||||
import { MOVE_FORM } from "../../navigation/constants";
|
||||
import { Picker } from "@react-native-community/picker";
|
||||
import { ItemValue } from "@react-native-community/picker/typings/Picker";
|
||||
import { MoveCategoryName } from "../../entities/MoveCategoryName";
|
||||
import { TypeName } from "../../entities/TypeName";
|
||||
|
||||
type MoveFormScreenNavigationProp = StackNavigationProp<RootStackParamList, typeof MOVE_FORM>;
|
||||
type MoveFormScreenRouteProp = RouteProp<RootStackParamList, typeof MOVE_FORM>;
|
||||
|
||||
type Props = {
|
||||
navigation: MoveFormScreenNavigationProp;
|
||||
route: MoveFormScreenRouteProp
|
||||
};
|
||||
|
||||
const MoveFormScreen = ({ navigation, route }: Props) => {
|
||||
const dispatch = useDispatch();
|
||||
const [move, setMove] = useState<Move>(route.params?.move || {
|
||||
id: null,
|
||||
name: '',
|
||||
category: MoveCategoryName.PHYSICAL,
|
||||
power: 0,
|
||||
accuracy: 0,
|
||||
type: {
|
||||
name: TypeName.NORMAL,
|
||||
weakAgainst: [],
|
||||
effectiveAgainst: [],
|
||||
},
|
||||
schemaVersion: 2
|
||||
});
|
||||
|
||||
const handleSave = () => {
|
||||
if (route.params?.move) {
|
||||
(dispatch as AppDispatch)(updateMove(route.params.move.id!, move));
|
||||
}
|
||||
else {
|
||||
(dispatch as AppDispatch)(createMove(move));
|
||||
}
|
||||
navigation.goBack();
|
||||
};
|
||||
|
||||
// TODO add labels and remove placeholders
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<TextInput
|
||||
value={move.name}
|
||||
onChangeText={(text) => setMove({ ...move, name: text })}
|
||||
placeholder="Name"
|
||||
style={styles.input}
|
||||
/>
|
||||
<Picker
|
||||
selectedValue={move.category}
|
||||
onValueChange={(itemValue: ItemValue) =>
|
||||
setMove({ ...move, category: itemValue as MoveCategoryName })
|
||||
}>
|
||||
{Object.values(MoveCategoryName).map((value) =>
|
||||
<Picker.Item key={value} label={value} value={value}/>
|
||||
)}
|
||||
</Picker>
|
||||
<TextInput
|
||||
value={move.power.toString()}
|
||||
onChangeText={(text) => setMove({ ...move, power: Number(text) })}
|
||||
placeholder="Power"
|
||||
style={styles.input}
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
<TextInput
|
||||
value={move.accuracy.toString()}
|
||||
onChangeText={(text) => setMove({ ...move, accuracy: Number(text) })}
|
||||
placeholder="Accuracy"
|
||||
style={styles.input}
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
<Picker
|
||||
selectedValue={move.type.name}
|
||||
onValueChange={(itemValue: ItemValue) =>
|
||||
setMove({ ...move, type: { ...move.type, name: itemValue as TypeName } })
|
||||
}>
|
||||
{Object.values(TypeName).map((value) =>
|
||||
<Picker.Item key={value} label={value} value={value}/>
|
||||
)}
|
||||
</Picker>
|
||||
{/*TODO add weakAgainst and effectiveAgainst columns... Two pickers for that, and the ability to keep adding types in each column.. but user can't put the same type in each column or twice in a column*/}
|
||||
<Button title="Save" onPress={handleSave}/>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
// TODO improve styles a bit
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
padding: 16,
|
||||
},
|
||||
input: {
|
||||
backgroundColor: '#CEC',
|
||||
borderRadius: 8,
|
||||
},
|
||||
});
|
||||
|
||||
export default MoveFormScreen;
|
Loading…
Reference in new issue