forked from mthuret/react-vr-feat-react-instantsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.vr.js
235 lines (220 loc) · 5.32 KB
/
index.vr.js
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import React from 'react';
import {
AppRegistry,
asset,
StyleSheet,
Pano,
Text,
View,
NativeModules,
VrButton,
Image,
} from 'react-vr';
import { InstantSearch, Configure } from 'react-instantsearch/native';
import {
connectHits,
connectSearchBox,
connectRange,
connectMenu,
connectRefinementList,
connectPagination,
} from 'react-instantsearch/connectors';
const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
export default class ReactVrFeatReactInstantSearch extends React.Component {
constructor() {
super();
this.state = {
query: 'San Francisco',
minGuest: 1,
page: 0,
maxGuest: 6,
roomType: [],
visitFlat: false,
annyang: NativeModules.Annyang,
};
RCTDeviceEventEmitter.addListener('myWorkerEvent', state => {
let page = this.state.page;
if (state.pagination && state.pagination === 'next') {
page = page + 1;
} else if (
state.pagination &&
state.pagination === 'previous' &&
page > 0
) {
page = page - 1;
}
this.setState({ ...this.state, ...state, page });
});
this.onClick = this.onClick.bind(this);
this.find = this.find.bind(this);
}
onClick() {
this.setState({ visitFlat: !this.state.visitFlat });
}
find(cityName) {
return ['sanfrancisco', 'paris', 'sydney', 'rome'].find(
city => city === cityName
);
}
render() {
//const hits = this.state.query ? <Hits /> : null;
const searchInterface = !this.state.visitFlat
? <SearchInterface {...this.state} onClick={this.onClick} />
: null;
const backButton = this.state.visitFlat
? <BackButton onClick={this.onClick} />
: null;
const cityName = this.state.query.replace(' ', '').toLowerCase();
const assetFilename = this.find(cityName) ? cityName : 'default';
return (
<View>
<Pano
source={asset(
!this.state.visitFlat ? `${assetFilename}.jpg` : 'flat.jpg'
)}
style={{
transform: [
{
translate: [0, -10, 20],
},
],
}}
/>
{backButton}
{searchInterface}
</View>
);
}
}
const SearchInterface = props =>
<InstantSearch
appId="latency"
apiKey="6be0576ff61c053d5f9a3225e2a90f76"
indexName="airbnb"
>
<Hits onClick={props.onClick} />
<Configure hitsPerPage={5} />
<SearchBox defaultRefinement={props.query} />
<RefinementList
defaultRefinement={props.roomType}
attributeName={'room_type'}
/>
<Range
defaultRefinement={{
min: props.minGuest,
max: props.maxGuest,
}}
attributeName={'person_capacity'}
/>
<Range
defaultRefinement={
props.minPrice
? {
min: props.minPrice,
max: props.maxPrice,
}
: null
}
attributeName={'price'}
/>
<Pagination defaultRefinement={props.page} />
</InstantSearch>;
const Hits = connectHits(({ hits, onClick }) => {
const buttons = hits.map(hit => {
return (
<FlatButton
key={hit.objectID}
onClick={() => {
onClick(hit.key);
}}
src={hit.picture_url}
{...hit}
/>
);
});
return (
<View
style={{
flexDirection: 'row',
flexWrap: 'wrap',
transform: [{ rotateX: -5 }, { translate: [-2, 0.7, -3] }],
width: 5,
}}
>
{buttons}
</View>
);
});
class BackButton extends React.Component {
onButtonClick = () => {
this.props.onClick();
};
render() {
return (
<View
style={{
flexDirection: 'row',
flexWrap: 'wrap',
transform: [{ translate: [1.8, 1.5, -3] }],
width: 5,
}}
>
<VrButton onClick={this.onButtonClick}>
<Image
style={{
width: 0.7,
height: 0.7,
}}
source={asset('goBack.png')}
/>
</VrButton>
</View>
);
}
}
class FlatButton extends React.Component {
onButtonClick = () => {
this.props.onClick();
};
render() {
return (
<View
style={{
alignItems: 'center',
flexDirection: 'row',
margin: 0.1,
width: 0.7,
backgroundColor: '#0099ff',
}}
>
<VrButton onClick={this.onButtonClick}>
<Image
style={{
width: 0.7,
height: 0.7,
}}
source={{ uri: this.props.src }}
/>
<Text style={{ textAlign: 'center' }}>
{this.props.name} - {this.props.price}$
</Text>
<Text style={{ textAlign: 'center' }}>
{this.props.room_type} - {this.props.city},{this.props.country}
</Text>
<Text style={{ textAlign: 'center' }}>
{this.props.person_capacity} guests
</Text>
</VrButton>
</View>
);
}
}
const SearchBox = connectSearchBox(() => null);
const Range = connectRange(() => null);
const RefinementList = connectRefinementList(() => null);
const Menu = connectMenu(() => null);
const Pagination = connectPagination(() => null);
AppRegistry.registerComponent(
'ReactVrFeatReactInstantSearch',
() => ReactVrFeatReactInstantSearch
);