-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGiftListView.js
More file actions
131 lines (108 loc) · 3.16 KB
/
GiftListView.js
File metadata and controls
131 lines (108 loc) · 3.16 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// GistListView.js
// componente che descrive nel dettaglio il gruppo regalo, con le varie proposte
import React from 'react'
import { StyleSheet, Text, ScrollView,TextInput, View, Button ,Image,Switch,FlatList} from 'react-native'
import GiftSummary from './GiftSummary'
//import firebase from 'react-native-firebase'
export default class GiftListView extends React.Component {
state = { imageUrl : null , groupId : null ,giftItem:null }
constructor() {
super()
this.ref = firebase.firestore().collection('gifts');
this.unsubscribe = null;
}
onPressAddGift = ()=>{
this.props.navigation.navigate('AddGiftView', {groupId:this.state.groupId})
}
componentDidMount() {
const groupId = this.props.navigation.getParam('groupId', '0');
console.log('groupId:',groupId);
this.setState({groupId:groupId});
//var strPath = 'guests.'+firebase.auth().currentUser.uid.toString();
// this.unsubscribe = this.ref.where('id','==',${groupId}).onSnapshot(this.onCollectionUpdate)
const docId = this.ref.doc(groupId).id;
console.log('doc ID: ',docId);
this.ref.doc(groupId).get()
.then((doc)=>{
const itemList=[];
const items = doc.get('items');
Object.keys(items).forEach(function(k){
console.log(k + ' - ' + items[k]);
itemList.push({
id : k,
title : items[k].title,
agreement : items[k].agreement,
imageURL : items[k].imageURL,
proposedBy : items[k].proposedBy,
});
});
this.setState({giftItems: itemList});
console.log('data items: ',itemList)
})
.catch((err)=>{console.log('err: ',err)}) ;;
//console.log('item: ',items);
// this.unsubscribe = this.ref.doc(groupId).get('items').then((doc)=>{console.log('item: ',doc)}).catch((err)=>{console.log('err: ',err)}) ;
const ref = firebase.storage().ref('warhammer_gift.jpg');
ref.getDownloadURL()
.then((url)=>{
this.setState({imageUrl : url})
})
.catch(function(e){console.log('getDownload error: ',e)})
}
componentWillUnmount() {
// this.unsubscribe();
}
_onPressItem = (id: string) => {
console.log('GiftListView _onPressItem this.state.groupId: ', this.state.groupId)
this.props.navigation.navigate('GiftView',{groupId:this.state.groupId, refId:id} )
}
render() {
return (
<View style={styles.container}>
<View >
<Text> Le tue liste regalo </Text>
</View>
<ScrollView >
<FlatList
data={this.state.giftItems}
renderItem={({ item}) => <GiftSummary onPressItem={this._onPressItem} {...item} />}
/>
</ScrollView>
<View >
<Button
title={'Crea un nuovo gruppo Regalo'}
onPress={this.onPressAddGift}
/>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
header:{
flex:1,
},
container: {
// display: flex;
// flex-direction:column,
// align-items:stretch,
flex: 1,
flexDirection:'column',
// justifyContent: 'center',
//alignItems: 'flex-start',
backgroundColor: "#fff"
},
item:{
backgroundColor: "#00ff00"
},
footer:{
flex:1,
},
textInput: {
height: 40,
width: '90%',
borderColor: 'gray',
borderWidth: 1,
marginTop: 8
}
})