Browse Source

Upload files to ''

gilberto.cancel 3 years ago
parent
commit
c79eb70abc
1 changed files with 98 additions and 0 deletions
  1. 98
    0
      Home_page.js

+ 98
- 0
Home_page.js View File

@@ -0,0 +1,98 @@
1
+
2
+import React, {useState, useEffect} from 'react'
3
+import { Button, Text, View, StyleSheet} from 'react-native'
4
+import {FlatList, ListViewBase } from 'react-native'
5
+import {TouchableOpacity} from 'react-native-gesture-handler'
6
+import {List, Divider} from 'react-native-paper'
7
+import Loading from '../components/Loading'
8
+import firebase from 'firebase';
9
+
10
+
11
+export default function Home_page({navigation}) {
12
+  const [threads, setThreads] = useState([]);  
13
+  const [loading, setLoading] = useState(true);
14
+
15
+  useEffect(() => {
16
+
17
+    const fire = firebase.firestore()
18
+    .collection('THREADS')
19
+    
20
+    .onSnapshot(querySnapshot => {
21
+      const threads = querySnapshot.docs.map(documentSnapshot => {
22
+        return{
23
+          _id:documentSnapshot.id,
24
+          name:'',
25
+          ...documentSnapshot.data()
26
+        };
27
+
28
+      });
29
+
30
+      setThreads(threads);
31
+
32
+      if(loading){
33
+        setLoading(false);
34
+      }
35
+
36
+    });
37
+
38
+    return () => fire();
39
+  }, []);
40
+  
41
+  if (loading) {
42
+    return <Loading />;
43
+  }
44
+  
45
+  return (
46
+      <View style={styles.container}>
47
+        <FlatList
48
+          data={threads}
49
+          keyExtractor = {item => item._id}
50
+          ItemSeparatorComponent={() => <Divider />}
51
+          renderItem = {({item}) => (
52
+
53
+            <TouchableOpacity
54
+            onPress={() => navigation.navigate('Room', {thread: item})}
55
+            
56
+            >
57
+            <List.Item
58
+              title={item.name}
59
+              description='Item description'
60
+              titleNumberOfLines={1}
61
+              titleStyle={styles.listTitle}
62
+              descriptionStyle={styles.listDescription}
63
+              descriptionNumberOfLines={1}
64
+            />
65
+          </TouchableOpacity>
66
+        )}
67
+      />
68
+
69
+      <Button
70
+        title='Add Room'
71
+        onPress={() => navigation.navigate('Add')}
72
+      />
73
+
74
+        <Button
75
+        title ='Room'
76
+        onPress= {() => navigation.navigate('Room')}
77
+        />
78
+
79
+      </View>
80
+    );
81
+  }
82
+  const styles = StyleSheet.create({
83
+    container: {
84
+      backgroundColor: '#f5f5f5',
85
+      flex: 1
86
+    },
87
+    listTitle: {
88
+      fontSize: 22
89
+    },
90
+    listDescription: {
91
+      fontSize: 16
92
+    }
93
+  });
94
+
95
+
96
+
97
+
98
+