Skip to content

Commit 6733f60

Browse files
committed
add base listings page
1 parent 59563ed commit 6733f60

File tree

10 files changed

+176
-19
lines changed

10 files changed

+176
-19
lines changed

components/Cards/VehicleCard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const VehicleCard = (props) => {
111111
const imageUrl = parseCloudinaryUrl(imageSrc)
112112

113113
return (
114-
<div className={styles.container} ref={ref}>
114+
<article className={styles.container} ref={ref}>
115115
<VehicleCardRibbons
116116
urgent={urgent}
117117
featured={featured}
@@ -194,7 +194,7 @@ const VehicleCard = (props) => {
194194
<FiMoreVertical />
195195
</button>
196196
</div>
197-
</div>
197+
</article>
198198
)
199199
}
200200

components/Cards/VehicleCard.module.scss

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
@import 'vars.scss';
22

3-
@keyframes slideTopFadeIn {
4-
0% {
5-
transform: translateY(-100%);
6-
opacity: 0;
7-
}
8-
75% {
9-
transform: translateY(20%);
10-
}
11-
100% {
12-
transform: translateY(0);
13-
opacity: 1;
14-
}
15-
}
16-
17-
183

194
.container {
205
width: calc(50vw - 16px);
@@ -30,8 +15,6 @@
3015
min-height: 340px;
3116
height: auto;
3217
margin-left: spacing(0.5);
33-
animation-fill-mode: forwards;
34-
animation: slideTopFadeIn 0.3s ease-in;
3518
}
3619
.likeButton {
3720
position: absolute;

components/Carousels/ListingsCarousel.module.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
@import 'vars.scss';
22

3+
4+
@keyframes slideTopFadeIn {
5+
0% {
6+
transform: translateY(-100%);
7+
opacity: 0;
8+
}
9+
75% {
10+
transform: translateY(20%);
11+
}
12+
100% {
13+
transform: translateY(0);
14+
opacity: 1;
15+
}
16+
}
17+
18+
319
.container {
420
position: relative;
521
margin: spacing(2) 0;
@@ -12,6 +28,10 @@
1228
@media (min-width: $tablet) {
1329
min-height: 30vh;
1430
}
31+
article {
32+
animation-fill-mode: forwards;
33+
animation: slideTopFadeIn 0.3s ease-in;
34+
}
1535
}
1636

1737
.wrapper {

components/Navigation/NavigationDropdown.module.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,29 @@
44
position: relative;
55
}
66

7+
@keyframes appear {
8+
0% {
9+
transform: scale(0) translate(-100%, 100%);
10+
opacity: 0;
11+
visibility: visible;
12+
}
13+
80% {
14+
transform: scale(1.2) translate(-100%, 100%);
15+
}
16+
100% {
17+
transform: scale(1) translate(-100%, 100%);
18+
opacity: 1;
19+
}
20+
}
21+
22+
723
.drawer {
824
position: absolute;
925
bottom: spacing(-2);
1026
left: 100%;
1127
transform: translate(-100%, 100%);
28+
animation: appear .6s ease-in-out;
29+
animation-fill-mode: forwards;
1230
background: $color-dark;
1331
padding: spacing(2) 0;
1432
border-radius: $border-radius-input;

pages/listings/index.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React, { useEffect } from 'react'
2+
import map from 'lodash/map'
3+
import styles from './listing.module.scss'
4+
import { useSelector, useDispatch } from 'react-redux'
5+
import {
6+
myListingsSelector,
7+
myListingsLoadingSelector,
8+
} from '../../store/listing/selectors'
9+
import ListignsCreator from '../../store/listing/creators'
10+
import { Layout, Loader, VehicleCard } from '../../components'
11+
import { getVehicleCardProps } from '~/utils/helpers'
12+
13+
const ListingsPage = () => {
14+
const loading = useSelector(myListingsLoadingSelector)
15+
const listings = useSelector(myListingsSelector)
16+
const dispatch = useDispatch()
17+
18+
useEffect(() => {
19+
dispatch(ListignsCreator.fetchMyListings())
20+
}, [])
21+
return (
22+
<Layout background="gray" fullscreen className={styles.container}>
23+
<h1>Listings</h1>
24+
<div className={styles.listings}>
25+
{map(listings, (listing) => (
26+
<VehicleCard
27+
key={listing._id}
28+
{...getVehicleCardProps(listing)}
29+
listingId={listing._id}
30+
/>
31+
))}
32+
<Loader loading={loading} />
33+
</div>
34+
</Layout>
35+
)
36+
}
37+
38+
export default ListingsPage

pages/listings/listing.module.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@import 'vars.scss';
2+
3+
.container {
4+
min-height: 100vh;
5+
h1 {
6+
text-align: center;
7+
margin-bottom: spacing(0.5);
8+
}
9+
padding-top: spacing(4);
10+
padding-bottom: spacing(12);
11+
.listings {
12+
display: grid;
13+
grid-gap: spacing(1);
14+
grid-template-columns: repeat(auto-fill, 142px);
15+
}
16+
}

store/listing/creators.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export const { Types, Creators } = createActions(
1111
fetchListings: ['params'],
1212
fetchListingsSuccess: ['data'],
1313
fetchListingsFailure: [],
14+
fetchMyListings: [],
15+
fetchMyListingsSuccess: ['data'],
16+
fetchMyListingsFailure: [],
1417
fetchFeaturedListings: ['params'],
1518
fetchFeaturedListingsSuccess: ['data'],
1619
fetchFeaturedListingsFailure: [],

store/listing/reducer.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,34 @@ const INITIAL_STATE = {
2121
userAvailableListings: {},
2222
userAvailableListingsPagination: {},
2323
loadingUserAvailableListings: false,
24+
myListings: {},
25+
myListingsPagination: {},
26+
loadingMyListings: false,
2427
}
2528

29+
const fetchMyListings = (state, { params }) => ({
30+
...state,
31+
myListings: get(params, 'resetPagination') ? {} : state.myListings,
32+
myListingsPagination: get(params, 'resetPagination') ? {} : state.myListingsPagination,
33+
loadingMyListings: true,
34+
})
35+
36+
37+
const fetchMyListingsSuccess = (state, { data, pagination }) => ({
38+
...state,
39+
myListings: {
40+
...state.myListings,
41+
...keyBy(data, '_id'),
42+
},
43+
loadingMyListings: false,
44+
myListingsPagination: pagination,
45+
})
46+
47+
const fetchMyListingsFailure = (state) => ({
48+
...state,
49+
loadingMyListings: false,
50+
})
51+
2652
const fetchListingById = (state) => ({
2753
...state,
2854
loadingListing: true,
@@ -212,4 +238,7 @@ export default createReducer(INITIAL_STATE, {
212238
[Types.FETCH_USER_SOLD_LISTINGS]: fetchUserSoldListings,
213239
[Types.FETCH_USER_SOLD_LISTINGS_SUCCESS]: fetchUserSoldListingsSuccess,
214240
[Types.FETCH_USER_SOLD_LISTINGS_FAILURE]: fetchUserSoldListingsFailure,
241+
[Types.FETCH_MY_LISTINGS]: fetchMyListings,
242+
[Types.FETCH_MY_LISTINGS_SUCCESS]: fetchMyListingsSuccess,
243+
[Types.FETCH_MY_LISTINGS_FAILURE]: fetchMyListingsFailure,
215244
})

store/listing/sagas.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,54 @@ function* handleFetchUserListingsCompose(action, type = 'SOLD') {
194194
}
195195
}
196196

197+
function* handleFetchMyListings(action) {
198+
const successType = Types.FETCH_MY_LISTINGS_SUCCESS
199+
const failureType = Types.FETCH_MY_LISTINGS_FAILURE
200+
try {
201+
const { params } = action
202+
const prevPagination = yield select(
203+
(state) => state.listing.myListingsPagination
204+
)
205+
const currentUser = yield select((state) => state.auth.currentUser)
206+
const userId = currentUser && currentUser._id
207+
if (!userId) {
208+
throw new Error('User is not logged in')
209+
}
210+
const { limit = 10, skip = 0, total = 0 } = prevPagination
211+
if (skip + limit < total || total === 0) {
212+
const response = yield call(listingsService.find, {
213+
query: {
214+
$limit: limit,
215+
userId,
216+
$sort: { createdAt: -1 },
217+
...(skip > 0 ? { $skip: skip } : {}),
218+
// userFilter: type === 'AVAILABLE' ? 'available' : 'sold',
219+
...params,
220+
},
221+
})
222+
const { data, ...pagination } = response
223+
yield put({
224+
type: successType,
225+
data,
226+
pagination,
227+
})
228+
} else {
229+
yield put({
230+
type: successType,
231+
data: {},
232+
pagination: prevPagination,
233+
})
234+
}
235+
} catch (error) {
236+
console.error(error)
237+
yield put({ type: failureType })
238+
}
239+
}
240+
197241
const sagas = [
198242
takeLatest(Types.FETCH_LISTING_BY_ID, handleFetchListingById),
199243
takeLatest(Types.FETCH_LISTINGS, handleFetchListingsCompose),
244+
takeLatest(Types.FETCH_MY_LISTINGS, handleFetchMyListings),
200245
takeLatest(Types.FETCH_RECOMMENDED_LISTINGS, (action) =>
201246
handleFetchListingsCompose(action, 'RECOMMENDED')
202247
),

store/listing/selectors.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ export const currentListingSelector = (state) => state.listing.currentListing
22
export const currentListingLoadingSelector = (state) =>
33
state.listing.loadingListing
44

5+
6+
export const myListingsPaginationSelector = (state) => state.listing.myListingsPagination
7+
export const myListingsSelector = (state) => state.listing.myListings
8+
export const myListingsLoadingSelector = (state) => state.listing.loadingMyListings
9+
510
export const listingPaginationSelector = (state) => state.listing.pagination
611
export const listingsSelector = (state) => state.listing.listings
712
export const listingsLoadingSelector = (state) => state.listing.loading

0 commit comments

Comments
 (0)