-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPropertyView.js
More file actions
186 lines (159 loc) · 4.34 KB
/
Copy pathPropertyView.js
File metadata and controls
186 lines (159 loc) · 4.34 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
'use strict';
var React = require('react');
var {
Component
} = React;
var ReactNative = require('react-native');
var {
ScrollView,
StyleSheet,
Text,
View,
Image,
TouchableHighlight,
AlertIOS
} = ReactNative;
var styles = StyleSheet.create({
container: {
marginTop: 0
},
heading: {
backgroundColor: '#F8F8F8',
},
seperator: {
height: 1,
backgroundColor: '#DDDDDD'
},
image: {
width: 400,
height: 300
},
price: {
fontSize: 25,
fontWeight: 'bold',
margin: 5,
color: '#48BBEC'
},
title: {
fontSize: 20,
margin: 5,
color: '#656565'
},
description: {
fontSize: 18,
margin: 5,
color: '#656565'
},
actionText: {
color: '#fff',
fontSize: 16,
textAlign: 'center',
},
action: {
backgroundColor: '#55dc97',
borderColor: 'transparent',
borderWidth: 1,
paddingTop: 14,
paddingBottom: 16,
},
share: {
backgroundColor: '#559bdc',
borderColor: 'transparent',
borderWidth: 1,
paddingTop: 14,
paddingBottom: 16,
}
});
import Share, {ShareSheet, Button} from 'react-native-share';
{/* This is implementing Firebase Database
import ReactNative from "react-native";
import * as firebase from 'firebase';
const firebaseConfig = {
apiKey: "AIzaSyBGy05Mk1w9qf7T4-jaPIbIRB4kP4fdaPs",
authDomain: "propertyfinder-7928a.firebaseapp.com",
databaseURL: "https://propertyfinder-7928a.firebaseio.com",
storageBucket: "",
};
firebase.initalizeApp(firebaseConfig);
*/}
class PropertyView extends Component {
constructor(props) {
super(props);
/* Comment from React Native API on the page of AlertIO
'$FlowFixMe this seems to be a Flow bug, `saveResponse` is defined below'
My Comment: this.saveResponse will save the response of the user when he clicks
enter then save in promptValue then trigger saveResponse(promptValue) 'I think
thisi is how it works'*/
this.saveResponse = this.saveResponse.bind(this);
this.state = {
promptValue: '',
}
}
// saves entered comment in prompt that appears in alert box when clicking 'Add to favorites'
saveResponse(promptValue) {
console.log(this.props.property.lister_url);
/* this.setState will render the page again */
this.setState({ promptValue: JSON.stringify(promptValue) });
console.log(promptValue);
/* connecting to end point to save response */
fetch('http://propertyfinder.herokuapp.com/addfav', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: 'user100',
propertyId: this.props.property.lister_url,
comment: promptValue
})
})
}
render() {
// for properties that are used in the share prompt when
// clicking the share button
let shareOptions = {
title: "React Native",
message: "Hola mundo",
url: "http://facebook.github.io/react-native/",
subject: "Share Link" // for email
};
// property has all the properties of such property so its an object with such properties.
var property = this.props.property;
var stats = property.bedroom_number + ' bed ' + property.property_type;
if (property.bathroom_number) {
stats += ', ' + property.bathroom_number + ' ' + (property.bathroom_number > 1
? 'bathrooms' : 'bathroom');
}
var price = property.price_formatted;
return(
<ScrollView style={styles.container}>
<Image style={styles.image} source={{uri: property.img_url}} />
<View style={styles.heading}>
<Text style={styles.price}>{price}</Text>
<Text style={styles.title}>{property.title}</Text>
</View>
<Text style={styles.description}>{stats}</Text>
<Text style={styles.description}>{property.summary}</Text>
<View style={styles.action}>
{/* add to favorites button */}
<TouchableHighlight
onPress={() => AlertIOS.prompt('Now this property '
+ this.props.property.title + ' is in your list of favorites. '
, 'Optional: Add a note about this house. e.g. why you like this house?'
, this.saveResponse, 'plain-text', 'type in here :)')}>
<Text style={styles.actionText}>Add to favorites</Text>
</TouchableHighlight>
</View>
<View style={styles.share}>
{/* share button */}
<TouchableHighlight
onPress={()=>{Share.open(shareOptions);}}>
<Text style={styles.actionText}>Share</Text>
</TouchableHighlight>
</View>
</ScrollView>
);
}
}
module.exports = PropertyView;