Sin descripción

Home_page.js 2.2KB

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