Skip to content
Snippets Groups Projects
Commit b957368d authored by isaacwsolomon's avatar isaacwsolomon
Browse files

Added input text box and added some styling

parent 6547c89f
No related branches found
No related tags found
No related merge requests found
import { addDoc, collection } from 'firebase/firestore'; import { addDoc, collection } from 'firebase/firestore';
import React, { useEffect } from 'react'; import React, { useEffect, useState } from 'react';
import { View, Text, Button } from 'react-native'; import { View, Text, Button, TextInput, StyleSheet } from 'react-native';
import { FIRESTORE_DB } from '../../firebaseConfig'; import { FIRESTORE_DB } from '../../firebaseConfig';
const List = ({navigation} : any) => { const List = ({navigation} : any) => {
const[todos, setTodos] = useState<any[]>([]);
const[todo, setTodo] = useState('');
useEffect(() => {}, []); useEffect(() => {}, []);
const addTodo = async () => { const addTodo = async () => {
console.log('ADD'); console.log('ADD');
const doc = addDoc(collection(FIRESTORE_DB, 'todos'), { title: 'I am a test', done: false }); const doc = await addDoc(collection(FIRESTORE_DB, 'todos'), { title: 'I am a test', done: false });
console.log('📝 ~ file: List.tsx:12 ~ addTodo ~ doc:', doc); console.log('📝 ~ file: List.tsx:12 ~ addTodo ~ doc:', doc);
}; };
return ( return (
<View> <View style ={styles.container}>
<Button onPress={() => addTodo()} title="Add Todo" /> <View style={styles.form}>
<TextInput style={styles.input} placeholder="Add new todo"
onChangeText={(text: string) => setTodo(text)}
value={todo}/>
<Button onPress={addTodo} title="Add Todo"disabled={todo === ''}/>
</View> </View>
</View>
); );
} }
export default List; export default List;
\ No newline at end of file
const styles = StyleSheet.create ({
container: {
marginHorizontal: 20,
},
form: {
marginVertical: 10,
flexDirection: 'row',
alignItems: 'center',
},
input: {
flex: 1,
height: 40,
borderWidth: 1,
borderRadius: 1,
padding: 10,
backgroundColor: '#fff',
}
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment