Skip to content

Commit bbf2a8b

Browse files
committed
pulling location, listings and sending to client
1 parent 1910e9d commit bbf2a8b

File tree

9 files changed

+57
-42
lines changed

9 files changed

+57
-42
lines changed

waf-frontend-gatsby/src/components/listing-item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const buttonStyle = {
1212

1313
const profileImgStyle = { width: '50px', marginBottom: '1rem', borderRadius: '50%', overflow: 'hidden' };
1414

15-
const ListingItem = ({ header, creator, messagesRoomsList }: any) => {
15+
const ListingItem = ({ header, creator, description, messagesRoomsList }: any) => {
1616

1717
const [loggedIn, setLoggedIn] = useState(false)
1818

waf-frontend-gatsby/src/components/post-listing-form.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const fileSelectedHandler = (event: any) => {
6666

6767
const PostListingForm = (props: any) => {
6868
return (
69+
<>
6970
<div>
7071
{/* <h3>Current Location: {currentGeolocation}</h3> */}
7172
<h3></h3>
@@ -191,6 +192,8 @@ const PostListingForm = (props: any) => {
191192

192193
</div>
193194

195+
196+
</>
194197
);
195198

196199
};

waf-frontend-gatsby/src/pages/browse-listings.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { useState, Dispatch, SetStateAction } from 'react';
21
import { Link } from 'gatsby';
2+
import React, { useState, Dispatch, SetStateAction } from 'react';
33
import Layout from '../components/layout';
44
import SEO from '../components/seo';
55
import MessageThreadSection from '../components/conversation-section';
@@ -67,6 +67,8 @@ const BrowsePage = (props: any) => {
6767
const latitude = position.coords.latitude;
6868
const longitude = position.coords.longitude;
6969

70+
console.log('found location: lat: ', latitude, " long: ", longitude)
71+
7072
dispatch(submitUpdatedLocation({
7173
type: 'Point',
7274
coordinates: [latitude, longitude]
@@ -96,7 +98,8 @@ const BrowsePage = (props: any) => {
9698
}
9799

98100
{/* === Zipcode Not Yet Set === */}
99-
{!props.currentGeolocation &&
101+
{/* {!props.currentGeolocation && */}
102+
{!props.location &&
100103
<>
101104
<p>
102105
[No Geo]
@@ -108,14 +111,20 @@ const BrowsePage = (props: any) => {
108111
}
109112

110113
{/* === Zipcode Has Been Set === */}
111-
{props.currentGeolocation &&
114+
{/* {props.currentGeolocation && */}
115+
{props.location &&
112116
<>
113117
<h3>
114118
Showing listings within 25 miles of {props.currentZipcode}.
115119
</h3>
116120

117121
<h3> Listings from redux:</h3>
118-
<ListingItem creator={"You"} messagesRoomsList={props.listings} />
122+
123+
{props.listings.forEach( (listing: any) => (
124+
125+
<ListingItem creator={listing.creator} descriptiong={listing.description} />
126+
)
127+
)}
119128

120129
</>
121130
}
@@ -192,6 +201,7 @@ const mapStateToProps = (state: IState) => {
192201
userId: state.userReducer?.userId,
193202

194203
listings: state.listingsReducer?.listings,
204+
location: state.listingsReducer?.location,
195205
manuallyEditingLocation: state.globalAppPropertiesReducer?.manuallyEditingLocation,
196206

197207
currentZipcode: state.userReducer?.zipcode ? state.userReducer?.zipcode :

waf-frontend-gatsby/src/state/actions/listings.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ export const receivedNearbyListings = (location: any, listings: any) => {
1717
console.log('dispatching login success...')
1818
return {
1919
type: UPDATED_LISTINGS_RECEIVED,
20-
location: location,
21-
payload: listings,
20+
payload: {
21+
location,
22+
listings
23+
},
2224
}
2325
};
2426

waf-frontend-gatsby/src/state/middlewares/socketManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ const socketManager = () => {
4444

4545
socket.on('NEARBY_LISTINGS', (data: any) => {
4646
const location = data.location;
47-
const nearbyListings = data.nearbyListings;
47+
const nearbyListings = data.listings;
4848

49+
console.log('got some ish: ', data)
4950
console.log('Got response from server!\nLocation is ', location, '\nListings: ', nearbyListings)
5051

5152
store.dispatch(receivedNearbyListings(location, nearbyListings));

waf-frontend-gatsby/src/state/reducers/listings.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ import { LISTINGS_UPDATED, UPDATED_LISTINGS_RECEIVED } from '../types/listings';
33

44
export interface IListingsState {
55
listings: any[] | undefined,
6+
location: any
67
}
78

89
export const initialState = {
910
listings: [{
1011
createdBy: "Fake User",
1112
headline: "play guitar"
12-
},
13-
{
14-
createdBy: "Fake User",
15-
headline: "go to a dubstep show"
1613
}
1714
],
15+
location: undefined
1816
};
1917

2018
interface IAction {
2119
type?: string;
22-
payload?: unknown;
20+
payload?: any;
2321
}
2422

2523
const reducer = (state: IListingsState = initialState, action: IAction = {}): IListingsState => {
@@ -31,9 +29,12 @@ const reducer = (state: IListingsState = initialState, action: IAction = {}): IL
3129
return Object.assign({}, state, payload)
3230

3331
case UPDATED_LISTINGS_RECEIVED:
34-
35-
return { ...state, }
36-
break;
32+
console.log('got some listings, listings! ', action)
33+
return {
34+
...state,
35+
listings: action.payload.listings,
36+
location: action.payload.location
37+
}
3738

3839
default:
3940
return state;

waf-frontend-gatsby/src/state/reducers/user.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { USER_UPDATED } from '../types/user';
33
import { GeoJSON } from './global-app-properties';
44
import { AUTH0_LOGIN_SUCCESS, LOGOUT } from '../types/login';
5+
import { UPDATED_LISTINGS_RECEIVED } from '../types/listings';
56

67
export interface IUserState {
78
userId: string | undefined
@@ -41,6 +42,13 @@ const reducer = (state: IUserState = initialState, action: IAction = {}): IUserS
4142
user: undefined
4243
};
4344

45+
case UPDATED_LISTINGS_RECEIVED:
46+
47+
48+
console.log('got some listings user ', action)
49+
return { ...state}
50+
break;
51+
4452
default:
4553
return state;
4654
}

waf-socket-server/src/event-handlers/mongo-utils/listings/get-nearby-listings.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,30 @@ import Listing, { IListing } from './models';
44
export const MAX_DISTANCE_FREE_ACCOUNT = 25;
55

66
export const getNearbyListings = async (userGeoLocation: any) => {
7-
7+
88
console.log('looking for nearby listings 1... ', userGeoLocation)
9-
9+
1010
await connectToMongo()
11-
11+
1212
console.log('looking for nearby listings 2... ', userGeoLocation)
1313

1414
try {
1515
const doc = await Listing.find(
1616
{
1717
location: {
18-
$near: {
19-
$geometry: userGeoLocation,
20-
$maxDistance: MAX_DISTANCE_FREE_ACCOUNT, // distance in meters
21-
$minDistance: 0
22-
}
18+
$near: {
19+
$geometry: userGeoLocation,
20+
$maxDistance: MAX_DISTANCE_FREE_ACCOUNT, // distance in meters
21+
$minDistance: 0
22+
}
2323
}
24-
}
24+
}
2525
);
26-
return {
27-
statusCode: 200,
28-
body: JSON.stringify({
29-
data: doc,
30-
}, null, 2)
31-
};
26+
27+
return doc
28+
3229
} catch (err) {
33-
return {
34-
statusCode: 200,
35-
body: JSON.stringify({
36-
data: err,
37-
}, null, 2)
38-
};
30+
return err
3931
}
4032

4133
}

waf-socket-server/src/event-handlers/submit-zipcode.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ export const handleSubmitUpdatedLocation = async (socket: any, data: any) => {
1010
const nearbyListings: any = await getNearbyListings(data);
1111

1212
console.log('got some listings! ', nearbyListings)
13-
13+
1414
socket.emit('NEARBY_LISTINGS', {
15-
data: {
16-
location: data,
17-
listings: nearbyListings
18-
}
15+
location: data,
16+
listings: nearbyListings
1917
});
2018

2119
}

0 commit comments

Comments
 (0)