-
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.
converting all to redux and moving out collection from shopping page
- Loading branch information
Showing
14 changed files
with
164 additions
and
85 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
24 changes: 24 additions & 0 deletions
24
src/components/collections-overview/collections-overview.component.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,24 @@ | ||
import React from 'react'; | ||
import {connect} from 'react-redux'; | ||
import { createStructuredSelector } from 'reselect'; | ||
|
||
import { selectShopCollection } from '../../redux/shop/shop.selector' | ||
|
||
import CollectionPreview from '../../components/preview-collection/preview-collection-component'; | ||
|
||
import './collections-overview.styles.scss'; | ||
|
||
const collectionOverview = ({collections}) =>( | ||
<div className='collection-overview'> | ||
{collections.map(({id, ...othersProps})=>( | ||
<CollectionPreview key={id} {...othersProps} /> | ||
))} | ||
</div> | ||
|
||
) | ||
const mapStateToProps = createStructuredSelector ({ | ||
collections: selectShopCollection | ||
} | ||
) | ||
|
||
export default connect(mapStateToProps)(collectionOverview); |
4 changes: 4 additions & 0 deletions
4
src/components/collections-overview/collections-overview.styles.scss
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,4 @@ | ||
.collections-overview { | ||
display: flex; | ||
flex-direction: column; | ||
} |
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,66 +1,23 @@ | ||
import React from 'react'; | ||
import MenuItem from '../menu-item/menu-items.component'; | ||
import { connect } from 'react-redux'; | ||
import { createStructuredSelector } from 'reselect'; | ||
import { selectDirectorySections } from '../../redux/directory/directory.selector'; | ||
import './directory.styles.scss'; | ||
|
||
class Directory extends React.Component { | ||
constructor(){ | ||
super(); | ||
this.state = { | ||
sections : [ | ||
{ | ||
title: 'hats', | ||
// imageUrl: 'https://i.ibb.co/cvpntL1/hats.png', | ||
imageUrl: 'images/hats.png', // local file in public/images/ | ||
id: 1, | ||
linkUrl: 'shop/hats' | ||
|
||
}, | ||
{ | ||
title: 'jackets', | ||
// imageUrl: 'https://i.ibb.co/px2tCc3/jackets.png', | ||
imageUrl: 'images/jackets.png', // local file in public/images/ | ||
id: 2, | ||
linkUrl: 'shop/jackets' | ||
}, | ||
{ | ||
title: 'sneakers', | ||
// imageUrl: 'https://i.ibb.co/0jqHpnp/sneakers.png', | ||
imageUrl: 'images/sneakers.png', // local file in public/images/ | ||
id: 3, | ||
linkUrl: 'shop/sneakers' | ||
}, | ||
{ | ||
title: 'womens', | ||
// imageUrl: 'https://i.ibb.co/GCCdy8t/womens.png', | ||
imageUrl: 'images/womens.png', // local file in public/images/ | ||
size: 'large', | ||
id: 4, | ||
linkUrl: 'shop/womens' | ||
}, | ||
{ | ||
title: 'mens', | ||
// imageUrl: 'https://i.ibb.co/R70vBrQ/men.png', | ||
imageUrl: 'images/men.png', // local file in public/images/ | ||
size: 'large', | ||
id: 5, | ||
linkUrl: 'shop/mens' | ||
} | ||
] | ||
const Directory = ( { sections } ) => ( | ||
<div className='directory-menu'> | ||
{ | ||
sections.map(({id, ...otherSectionProps})=>( | ||
<MenuItem key={id} {...otherSectionProps} /> | ||
)) | ||
} | ||
} | ||
render(){ | ||
return( | ||
<div className='directory-menu'> | ||
{ | ||
this.state.sections.map(({id, ...otherSectionProps})=>( | ||
<MenuItem key={id} {...otherSectionProps} /> | ||
)) | ||
} | ||
|
||
</div> | ||
) | ||
} | ||
</div> | ||
) | ||
|
||
} | ||
const mapStateToProps = createStructuredSelector ({ | ||
sections: selectDirectorySections | ||
}) | ||
|
||
export default Directory; | ||
export default connect(mapStateToProps)(Directory); |
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,24 +1,13 @@ | ||
import React from 'react'; | ||
import ShopData from './shop.data'; | ||
import CollectionPreview from '../../components/preview-collection/preview-collection-component'; | ||
|
||
class ShopPage extends React.Component { | ||
constructor(props){ | ||
super(props); | ||
this.state = { | ||
collections:ShopData | ||
} | ||
} | ||
render(){ | ||
const {collections} = this.state; | ||
return( | ||
<div className="shopPage"> | ||
{collections.map(({id, ...othersProps})=>( | ||
<CollectionPreview key={id} {...othersProps} /> | ||
))} | ||
</div> | ||
|
||
) | ||
} | ||
} | ||
import CollectionOverview from '../../components/collections-overview/collections-overview.component' | ||
|
||
|
||
const ShopPage = ({collections}) => ( | ||
<div className="shopPage"> | ||
<CollectionOverview /> | ||
</div> | ||
) | ||
|
||
|
||
export default ShopPage; |
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,50 @@ | ||
const INITIAL_STATE = { | ||
sections : [ | ||
{ | ||
title: 'hats', | ||
// imageUrl: 'https://i.ibb.co/cvpntL1/hats.png', | ||
imageUrl: 'images/hats.png', // local file in public/images/ | ||
id: 1, | ||
linkUrl: 'shop/hats' | ||
|
||
}, | ||
{ | ||
title: 'jackets', | ||
// imageUrl: 'https://i.ibb.co/px2tCc3/jackets.png', | ||
imageUrl: 'images/jackets.png', // local file in public/images/ | ||
id: 2, | ||
linkUrl: 'shop/jackets' | ||
}, | ||
{ | ||
title: 'sneakers', | ||
// imageUrl: 'https://i.ibb.co/0jqHpnp/sneakers.png', | ||
imageUrl: 'images/sneakers.png', // local file in public/images/ | ||
id: 3, | ||
linkUrl: 'shop/sneakers' | ||
}, | ||
{ | ||
title: 'womens', | ||
// imageUrl: 'https://i.ibb.co/GCCdy8t/womens.png', | ||
imageUrl: 'images/womens.png', // local file in public/images/ | ||
size: 'large', | ||
id: 4, | ||
linkUrl: 'shop/womens' | ||
}, | ||
{ | ||
title: 'mens', | ||
// imageUrl: 'https://i.ibb.co/R70vBrQ/men.png', | ||
imageUrl: 'images/men.png', // local file in public/images/ | ||
size: 'large', | ||
id: 5, | ||
linkUrl: 'shop/mens' | ||
} | ||
] | ||
}; | ||
|
||
export const directoryReducer = (state = INITIAL_STATE, action) => { | ||
switch(action.type){ | ||
default: | ||
return state | ||
} | ||
|
||
} |
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,8 @@ | ||
import { createSelector } from 'reselect'; | ||
|
||
const selectDirectory = state => state.directory; | ||
|
||
export const selectDirectorySections = createSelector ( | ||
[selectDirectory], | ||
directory => directory.sections | ||
) |
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,9 +1,24 @@ | ||
import { combineReducers } from 'redux'; | ||
import { persistReducer } from 'redux-persist' | ||
|
||
import { userReducer } from './user/user.reducer'; | ||
import { cartReducer } from './cart/cart.reducer'; | ||
import { directoryReducer } from './directory/directory.reducer'; | ||
import { shopReducer } from './shop/shop.reducer'; | ||
import storage from 'redux-persist/lib/storage' | ||
|
||
export default combineReducers({ | ||
const persistConfig = { | ||
key: 'root', | ||
storage, | ||
whitelist: ['cart'] | ||
} | ||
|
||
const rootReducer = combineReducers({ | ||
user: userReducer, | ||
cart: cartReducer | ||
}); | ||
cart: cartReducer, | ||
directory: directoryReducer, | ||
shop: shopReducer | ||
}); | ||
|
||
|
||
export default persistReducer(persistConfig, rootReducer); |
File renamed without changes.
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,12 @@ | ||
import ShopData from './shop.data' | ||
|
||
const INITIAL_STATE = { | ||
collections: ShopData | ||
} | ||
|
||
export const shopReducer = (state=INITIAL_STATE, action) => { | ||
switch(action.type){ | ||
default: | ||
return state; | ||
} | ||
}; |
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,8 @@ | ||
import { createSelector } from 'reselect'; | ||
|
||
const selectShop = state => state.shop; | ||
|
||
export const selectShopCollection = createSelector( | ||
[selectShop], | ||
shop=>shop.collections | ||
) |
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,10 +1,13 @@ | ||
import {createStore, applyMiddleware} from 'redux'; | ||
import logger from 'redux-logger'; | ||
import { persistStore } from 'redux-persist' | ||
|
||
import rootReducer from './root-reducer'; | ||
|
||
const middlewares = [logger]; | ||
|
||
const store = createStore(rootReducer, applyMiddleware(...middlewares)); | ||
export const store = createStore(rootReducer, applyMiddleware(...middlewares)); | ||
|
||
export const persistor = persistStore(store); | ||
|
||
export default store; |
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