-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp2.js
More file actions
168 lines (140 loc) · 4.03 KB
/
App2.js
File metadata and controls
168 lines (140 loc) · 4.03 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
import React, { useState, useEffect } from 'react';
import {StyleSheet, Text, View, Image} from 'react-native';
import SwipeCards from "react-native-swipe-cards-deck";
import Geo from './components/Geo';
import GeoExpo from './components/GeoExpo';
import YelpSearch from './components/YelpSearch';
import * as Location from 'expo-location';
import axios from 'axios';
import db from 'firebase';
class Card extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<View style={styles.card}>
<Image style={styles.thumbnail} source={{uri: this.props.image}} />
<Text style={styles.text}>{this.props.name}</Text>
<GeoExpo />
</View>
)
}
}
class NoMoreCards extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<View style={styles.noMoreCards}>
<Text>No more cards</Text>
</View>
)
}
}
// const cards = [
// {name: '1', image: 'https://media.giphy.com/media/GfXFVHUzjlbOg/giphy.gif'},
// {name: '2', image: 'https://media.giphy.com/media/irTuv1L1T34TC/giphy.gif'},
// {name: '3', image: 'https://media.giphy.com/media/LkLL0HJerdXMI/giphy.gif'},
// {name: '4', image: 'https://media.giphy.com/media/fFBmUMzFL5zRS/giphy.gif'},
// {name: '5', image: 'https://media.giphy.com/media/oDLDbBgf0dkis/giphy.gif'},
// {name: '6', image: 'https://media.giphy.com/media/7r4g8V2UkBUcw/giphy.gif'},
// {name: '7', image: 'https://media.giphy.com/media/K6Q7ZCdLy8pCE/giphy.gif'},
// {name: '8', image: 'https://media.giphy.com/media/hEwST9KM0UGti/giphy.gif'},
// {name: '9', image: 'https://media.giphy.com/media/3oEduJbDtIuA2VrtS0/giphy.gif'},
// ]
const cards2 = [
{name: 'McDonalds', image: '//logo.clearbit.com/mcdonalds.com.au?size=400'},
{name: 'Taco Bell', image: '//logo.clearbit.com/tacobell.com?size=400'},
{name: 'Starbucks', image: '//logo.clearbit.com/starbucks.com?size=400'},
]
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
cards: cards2,
outOfCards: false,
location: null,
geo: null,
errorMsg: null,
cardsPre: [],
nearbyRestaurants: []
}
}
// componentDidMount(){
// db.collection('users').doc('nYkTHm0iE6twpdz4MPUg').collection('nearby').doc('ZuZnkY1OZM9Fx84WCkIF').onSnapshot((snapshot).then(function(snapshot){
// console.log(snapshot)
// }))
// }
setCards (cards) {
console.log(cards)
this.setState({
cards: this.state.cards.concat(cards)
})
}
handleYup (card) {
console.log("yup")
return true;
}
handleNope (card) {
console.log("nope")
return true;
}
cardRemoved (index) {
console.log(index);
let CARD_REFRESH_LIMIT = 3
if (this.state.cards.length - index <= CARD_REFRESH_LIMIT + 1) {
console.log(`There are only ${this.state.cards.length - index - 1} cards left.`);
if (!this.state.outOfCards) {
console.log(`Adding ${cards2.length} more cards`)
this.setState({
cards: this.state.cards.concat(cards2),
outOfCards: true
})
}
}
}
render() {
return (
<SwipeCards
cards={this.state.cards}
loop={false}
renderCard={(cardData) => <Card {...cardData} />}
keyExtractor={(cardData) => String(cardData.name)}
renderNoMoreCards={() => <NoMoreCards />}
showYup={true}
showNope={true}
handleYup={this.handleYup}
handleNope={this.handleNope}
cardRemoved={this.cardRemoved.bind(this)}
/>
)
}
}
const styles = StyleSheet.create({
card: {
alignItems: 'center',
borderRadius: 5,
overflow: 'hidden',
borderColor: 'lightgrey',
backgroundColor: 'white',
borderWidth: 1,
elevation: 1,
},
thumbnail: {
width: 300,
height: 300,
},
text: {
fontSize: 20,
color: 'grey',
paddingTop: 10,
paddingBottom: 10
},
noMoreCards: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}
})