Skip to content

Commit 59c22b3

Browse files
committed
did a lot... chagned model, made restaurant recommendations page, made route for editing user based on kevins food preferences, refactored duplicate code, uncamelcased components
1 parent b92ac97 commit 59c22b3

14 files changed

+189
-133
lines changed

client/components/GoogleMap.js

-31
This file was deleted.

client/components/google-map.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, {Component} from 'react'
2+
import {withGoogleMap, GoogleMap, Marker} from 'react-google-maps'
3+
const {
4+
MarkerWithLabel
5+
} = require('react-google-maps/lib/components/addons/MarkerWithLabel')
6+
7+
const Map = props => {
8+
const {longitude, latitude} = props
9+
console.log(props)
10+
const GoogleMapExample = withGoogleMap(props => (
11+
<GoogleMap defaultCenter={{lat: latitude, lng: longitude}} defaultZoom={13}>
12+
<MarkerWithLabel
13+
position={{lat: latitude, lng: longitude}}
14+
labelAnchor={new google.maps.Point(0, 0)}
15+
labelStyle={{}}
16+
>
17+
<div />
18+
</MarkerWithLabel>
19+
</GoogleMap>
20+
))
21+
return (
22+
<div>
23+
<GoogleMapExample
24+
containerElement={<div style={{height: `200px`, width: '600px'}} />}
25+
mapElement={<div style={{height: `100%`}} />}
26+
/>
27+
</div>
28+
)
29+
}
30+
export default Map

client/components/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ export {default as MergedAuth} from './merged-auth'
99
export {default as Homepage} from './homepage'
1010
export {default as Restaurant} from './restaurant-list'
1111
export {default as Options} from './options'
12-
export {default as Profile} from './profile'
12+
export {default as Recommendations} from './recommendations'

client/components/merged-auth.js

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class mergedAuth extends Component {
99
<Grid columns={2} divided>
1010
<Grid.Column>
1111
<h1>Sign Up</h1>
12+
<p>
13+
Create an account to get personalized recommendations based on
14+
your favorite cuisines.
15+
</p>
1216
<Signup />
1317
</Grid.Column>
1418
<Grid.Column>

client/components/navbar.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import {connect} from 'react-redux'
44
import {Link} from 'react-router-dom'
55
import {logout} from '../store'
66
import {Menu, Grid, MenuItem} from 'semantic-ui-react'
7-
import {reset as resetWeights} from '../store/weighSources'
8-
import {reset as resetFilters} from '../store/filters'
97

108
class Navbar extends Component {
119
constructor() {
@@ -46,7 +44,7 @@ class Navbar extends Component {
4644
// The navbar will show these links after you log in
4745
<React.Fragment>
4846
<Menu.Item>
49-
<Link to="/profile">Profile</Link>
47+
<Link to="/recommendations">Recommendations</Link>
5048
</Menu.Item>
5149
<Menu.Item>
5250
<Link to="#" onClick={handleClick}>

client/components/profile.js

-22
This file was deleted.

client/components/recommendations.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React, {Component} from 'react'
2+
import {connect} from 'react-redux'
3+
import {Card} from 'semantic-ui-react'
4+
import {restaurantSort, restaurantScorer} from '../helperFuncs'
5+
import RestaurantCard from './restaurant-card'
6+
7+
class Profile extends Component {
8+
render() {
9+
const {user, restaurants} = this.props
10+
const userStr = user.email.slice(0, user.email.indexOf('@'))
11+
return (
12+
<div>
13+
<h1>Recommendations for {userStr}</h1>
14+
<h3>Based on cuisines you've liked, we recommend:</h3>
15+
{user.likedCuisines.map(cuisine => {
16+
return (
17+
<React.Fragment key={cuisine}>
18+
<h4>{cuisine}</h4>
19+
<Card.Group>
20+
{restaurantSort(
21+
restaurants.filter(restaurant => {
22+
if (restaurant.cuisineType[0].title === cuisine) {
23+
restaurant.score = restaurantScorer(
24+
restaurant.reviews,
25+
5,
26+
5,
27+
5,
28+
5
29+
)
30+
return true
31+
}
32+
})
33+
)
34+
.slice(0, 8)
35+
.map(restaurant => {
36+
return (
37+
<RestaurantCard
38+
restaurant={restaurant}
39+
key={restaurant.id}
40+
/>
41+
)
42+
})}
43+
</Card.Group>
44+
</React.Fragment>
45+
)
46+
})}
47+
</div>
48+
)
49+
}
50+
}
51+
52+
const mapState = state => ({
53+
user: state.user,
54+
restaurants: state.restaurantReducer.restaurants
55+
})
56+
57+
export default connect(mapState)(Profile)

client/components/restaurant-list.js

+9-70
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
Loader,
1717
Dimmer
1818
} from 'semantic-ui-react'
19+
import {restaurantSort, restaurantScorer} from '../helperFuncs'
1920

2021
class RestaurantList extends Component {
2122
constructor() {
@@ -41,8 +42,9 @@ class RestaurantList extends Component {
4142
foursquareWeight,
4243
restaurants
4344
} = this.props
45+
4446
restaurants.forEach(restaurant => {
45-
restaurant.score = this.restaurantScore(
47+
restaurant.score = restaurantScorer(
4648
restaurant.reviews,
4749
yelpWeight,
4850
zomatoWeight,
@@ -72,57 +74,6 @@ class RestaurantList extends Component {
7274
this.setState({loading: false})
7375
}
7476

75-
restaurantScore = (
76-
reviews,
77-
yelpWeight,
78-
zomatoWeight,
79-
googleWeight,
80-
foursquareWeight
81-
) => {
82-
let totalWeight = yelpWeight
83-
let reviewsString = ''
84-
reviews.forEach(review => {
85-
reviewsString += review.source
86-
})
87-
const reviewsLength = reviews.length
88-
89-
if (reviewsString.indexOf('Zomato') !== -1) totalWeight += zomatoWeight
90-
if (reviewsString.indexOf('Google') !== -1) totalWeight += googleWeight
91-
if (reviewsString.indexOf('Foursquare') !== -1)
92-
totalWeight += foursquareWeight
93-
94-
function weighter(sourceWeight, review) {
95-
const weight = sourceWeight / totalWeight * reviewsLength
96-
let denominator
97-
if (review.source === 'Foursquare') {
98-
denominator = 10
99-
} else {
100-
denominator = 5
101-
}
102-
const rating = review.rating / denominator
103-
return weight * rating
104-
}
105-
106-
return Math.round(
107-
reviews
108-
.map(review => {
109-
if (review.source === 'Yelp') {
110-
return weighter(yelpWeight, review)
111-
} else if (review.source === 'Zomato') {
112-
return weighter(zomatoWeight, review)
113-
} else if (review.source === 'Google') {
114-
return weighter(googleWeight, review)
115-
} else if (review.source === 'Foursquare') {
116-
return weighter(foursquareWeight, review)
117-
}
118-
})
119-
.reduce((accum, currentVal) => accum + currentVal, 0) /
120-
reviews.length *
121-
100,
122-
0
123-
)
124-
}
125-
12677
async handleChange(event) {
12778
await this.props.updateSearchBar(event.target.value)
12879

@@ -187,7 +138,7 @@ class RestaurantList extends Component {
187138
} = this.props
188139

189140
this.props.restaurants.forEach(restaurant => {
190-
restaurant.score = this.restaurantScore(
141+
restaurant.score = restaurantScorer(
191142
restaurant.reviews,
192143
yelpWeight,
193144
zomatoWeight,
@@ -230,23 +181,11 @@ class RestaurantList extends Component {
230181
/>
231182
<Divider hidden />
232183
<Card.Group>
233-
{restaurants
234-
.sort((restaurant1, restaurant2) => {
235-
if (restaurant2.reviews.length === restaurant1.reviews.length) {
236-
if (restaurant2.score === restaurant1.score) {
237-
return restaurant2.id - restaurant1.id
238-
} else {
239-
return restaurant2.score - restaurant1.score
240-
}
241-
} else {
242-
return restaurant2.reviews.length - restaurant1.reviews.length
243-
}
244-
})
245-
.map(restaurant => {
246-
return (
247-
<RestaurantCard restaurant={restaurant} key={restaurant.id} />
248-
)
249-
})}
184+
{restaurantSort(restaurants).map(restaurant => {
185+
return (
186+
<RestaurantCard restaurant={restaurant} key={restaurant.id} />
187+
)
188+
})}
250189
</Card.Group>
251190
</React.Fragment>
252191
)

client/components/SingleRestaurant.js client/components/single-restaurant.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
ListItem
1414
} from 'semantic-ui-react'
1515
import ApplePie from './pie-chart'
16-
import Map from './GoogleMap'
16+
import Map from './google-map'
1717

1818
const dollarSignHelper = expenseRating => {
1919
if (expenseRating === 0) return 'No Expense Rating Yet'

client/helperFuncs.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
export const restaurantSort = restaurantArr => {
2+
return restaurantArr.sort((restaurant1, restaurant2) => {
3+
if (restaurant2.reviews.length === restaurant1.reviews.length) {
4+
if (restaurant2.score === restaurant1.score) {
5+
return restaurant2.id - restaurant1.id
6+
} else {
7+
return restaurant2.score - restaurant1.score
8+
}
9+
} else {
10+
return restaurant2.reviews.length - restaurant1.reviews.length
11+
}
12+
})
13+
}
14+
15+
export const restaurantScorer = (
16+
reviews,
17+
yelpWeight,
18+
zomatoWeight,
19+
googleWeight,
20+
foursquareWeight
21+
) => {
22+
let totalWeight = yelpWeight
23+
let reviewsString = ''
24+
reviews.forEach(review => {
25+
reviewsString += review.source
26+
})
27+
const reviewsLength = reviews.length
28+
29+
if (reviewsString.indexOf('Zomato') !== -1) totalWeight += zomatoWeight
30+
if (reviewsString.indexOf('Google') !== -1) totalWeight += googleWeight
31+
if (reviewsString.indexOf('Foursquare') !== -1)
32+
totalWeight += foursquareWeight
33+
34+
function weighter(sourceWeight, review) {
35+
const weight = sourceWeight / totalWeight * reviewsLength
36+
let denominator
37+
if (review.source === 'Foursquare') {
38+
denominator = 10
39+
} else {
40+
denominator = 5
41+
}
42+
const rating = review.rating / denominator
43+
return weight * rating
44+
}
45+
46+
return Math.round(
47+
reviews
48+
.map(review => {
49+
if (review.source === 'Yelp') {
50+
return weighter(yelpWeight, review)
51+
} else if (review.source === 'Zomato') {
52+
return weighter(zomatoWeight, review)
53+
} else if (review.source === 'Google') {
54+
return weighter(googleWeight, review)
55+
} else if (review.source === 'Foursquare') {
56+
return weighter(foursquareWeight, review)
57+
}
58+
})
59+
.reduce((accum, currentVal) => accum + currentVal, 0) /
60+
reviews.length *
61+
100,
62+
0
63+
)
64+
}

client/routes.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, {Component} from 'react'
22
import {connect} from 'react-redux'
33
import {withRouter, Route, Switch} from 'react-router-dom'
44
import PropTypes from 'prop-types'
5-
import {MergedAuth, Homepage, Profile} from './components'
6-
import SingleRestaurant from './components/SingleRestaurant'
5+
import {MergedAuth, Homepage, Recommendations} from './components'
6+
import SingleRestaurant from './components/single-restaurant'
77
import {me} from './store'
88

99
/**
@@ -31,7 +31,7 @@ class Routes extends Component {
3131
<Switch>
3232
{/* Routes placed here are only available after logging in */}
3333
<Route path="/home" component={Homepage} />
34-
<Route path="/profile" component={Profile} />
34+
<Route path="/recommendations" component={Recommendations} />
3535
</Switch>
3636
)}
3737
{/* Displays our Login component as a fallback */}

0 commit comments

Comments
 (0)