-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateThreadScreen.js
More file actions
54 lines (50 loc) · 1.32 KB
/
Copy pathCreateThreadScreen.js
File metadata and controls
54 lines (50 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React, { useState } from 'react';
import { View, TextInput, Button, Text, StyleSheet } from 'react-native';
import { db, auth } from './firebase';
import { addDoc, collection } from "firebase/firestore";
export default function CreateThreadScreen({ navigation }) {
const [title, setTitle] = useState('');
const [content, setContent] = useState('');
const createThread = async () => {
await addDoc(collection(db, "threads"), {
title,
content,
createdAt: new Date(),
user: auth.currentUser.email,
displayName: auth.currentUser.displayName || auth.currentUser.email,
});
navigation.navigate('Feed');
};
return (
<View style={styles.container}>
<TextInput
placeholder="Title"
value={title}
onChangeText={setTitle}
style={styles.input}
/>
<TextInput
placeholder="Content"
value={content}
onChangeText={setContent}
style={styles.input}
multiline
/>
<Button title="Create Thread" onPress={createThread} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
backgroundColor: 'black',
},
input: {
backgroundColor: 'rgba(255, 255, 255, 0.2)',
color: 'white',
padding: 10,
borderRadius: 5,
marginBottom: 10,
},
});