-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
117 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/components/collections-overview/collections-overview.container.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { connect } from 'react-redux'; | ||
import { compose } from 'redux'; | ||
import { createStructuredSelector } from 'reselect'; | ||
import { selectIsCollectionFetching } from '../../redux/shop/shop.selector'; | ||
import WithSpinner from '../with-spinner/with-spinner.component'; | ||
import CollectionOverview from './collections-overview.component'; | ||
|
||
const mapStateToProps = createStructuredSelector({ | ||
isLoading: selectIsCollectionFetching | ||
}) | ||
|
||
const CollectionOverviewContainer = compose( | ||
connect(mapStateToProps), | ||
WithSpinner | ||
)(CollectionOverview); | ||
|
||
export default CollectionOverviewContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { connect } from 'react-redux'; | ||
import { compose } from 'redux'; | ||
import { createStructuredSelector } from 'reselect'; | ||
|
||
import { selectIsCollectionsLoaded } from '../../redux/shop/shop.selector'; | ||
import WithSpinner from '../../components/with-spinner/with-spinner.component'; | ||
import CollectionPage from '../collection/collection.component'; | ||
|
||
const mapStateToProps = createStructuredSelector ({ | ||
isLoading: state=> !selectIsCollectionsLoaded(state) | ||
}) | ||
|
||
const CollectionPageContainer = compose( | ||
connect(mapStateToProps), | ||
WithSpinner | ||
)(CollectionPage); | ||
|
||
export default CollectionPageContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,29 @@ | ||
import ShopActionTypes from './shop.type'; | ||
import {firestore, convertCollectionsSnapshotToMap} from '../../fireabase/firebase.utils'; | ||
|
||
export const updateCollections = collectionsMap => ({ | ||
type: ShopActionTypes.UPDATE_COLLECTIONS, | ||
payload: collectionsMap | ||
}); | ||
export const fetchCollectionsStart = () => ({ | ||
type: ShopActionTypes.FETCH_COLLECTIONS_START | ||
}); | ||
|
||
export const fetchCollectionsSuccess = collectionMap => ({ | ||
type: ShopActionTypes.FETCH_COLLECTIONS_SUCCESS, | ||
payload: collectionMap | ||
}) | ||
export const fetchCollectionsFailure = errorMessage => ({ | ||
type: ShopActionTypes.FETCH_COLLECTIONS_FAILURE, | ||
payload: errorMessage | ||
}) | ||
|
||
export const fetchCollectionsStartAsync = () => { | ||
return dispatch => { | ||
const collectionRef = firestore.collection('collections'); | ||
dispatch(fetchCollectionsStart()); | ||
|
||
collectionRef.get().then( | ||
snapshot=>{ | ||
const collectionsMap = convertCollectionsSnapshotToMap(snapshot); | ||
dispatch(fetchCollectionsSuccess(collectionsMap)); | ||
} | ||
).catch(error=> dispatch(fetchCollectionsFailure(error))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
import ShopActionTypes from './shop.type'; | ||
|
||
const INITIAL_STATE = { | ||
collections: null | ||
collections: null, | ||
isFetching: false, | ||
errorMessage: undefined | ||
} | ||
|
||
export const shopReducer = (state=INITIAL_STATE, action) => { | ||
switch(action.type){ | ||
case ShopActionTypes.UPDATE_COLLECTIONS: | ||
case ShopActionTypes.FETCH_COLLECTIONS_START: | ||
return { | ||
...state, | ||
isFetching: true | ||
}; | ||
|
||
case ShopActionTypes.FETCH_COLLECTIONS_SUCCESS: | ||
return { | ||
...state, | ||
isFetching: false, | ||
collections: action.payload | ||
} | ||
case ShopActionTypes.FETCH_COLLECTIONS_FAILURE: | ||
return { | ||
...state, | ||
isFetching: false, | ||
errorMessage: action.payload | ||
} | ||
default: | ||
return state; | ||
} | ||
}; | ||
}; | ||
|
||
export default shopReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const ShopActionTypes = { | ||
UPDATE_COLLECTIONS: 'UPDATE_COLLECTIONS' | ||
FETCH_COLLECTIONS_START: 'FETCH_COLLECTIONS_START', | ||
FETCH_COLLECTIONS_SUCCESS: 'FETCH_COLLECTIONS_SUCCESS', | ||
FETCH_COLLECTIONS_FAILURE: 'FETCH_COLLECTIONS_FAILURE' | ||
} | ||
|
||
export default ShopActionTypes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters