UpdaUpdate changes

This commit is contained in:
Onuwa Nnachi Isaac 2019-04-27 12:27:48 +01:00
parent cf77606157
commit d886b5bc39
No known key found for this signature in database
GPG Key ID: 831A4177E1A2CEBB
5 changed files with 56 additions and 62 deletions

View File

@ -26,19 +26,7 @@ const DappListItem = props => {
return ( return (
<div className={isRanked ? styles.rankedListItem : styles.listItem}> <div className={isRanked ? styles.rankedListItem : styles.listItem}>
{isRanked && <div className={styles.position}>{position}</div>} {isRanked && <div className={styles.position}>{position}</div>}
<div <div onClick={() => onToggleProfileModal(name)}>
onClick={() =>
onToggleProfileModal({
name,
url,
description,
image,
isRanked,
position,
category,
})
}
>
<ReactImageFallback <ReactImageFallback
className={styles.image} className={styles.image}
src={image} src={image}
@ -47,19 +35,7 @@ const DappListItem = props => {
/> />
</div> </div>
<div> <div>
<div <div onClick={() => onToggleProfileModal(name)}>
onClick={() =>
onToggleProfileModal({
name,
url,
description,
image,
isRanked,
position,
category,
})
}
>
<h2 className={styles.header}>{name}</h2> <h2 className={styles.header}>{name}</h2>
<p className={styles.description}>{description}</p> <p className={styles.description}>{description}</p>
</div> </div>

View File

@ -13,8 +13,7 @@ export default () => [
<Route path="/categories" component={Filtered} /> <Route path="/categories" component={Filtered} />
<Route path="/all" component={Dapps} /> <Route path="/all" component={Dapps} />
<Route path="/recently-added" component={RecentlyAdded} /> <Route path="/recently-added" component={RecentlyAdded} />
<Route path="/:dapp-name" component={Profile} /> <Route path="/:dapp_name" component={Profile} />
</Switch>, </Switch>,
<Vote key={2} />, <Vote key={2} />,
<Profile key={3} />,
] ]

View File

@ -1,7 +1,15 @@
import { connect } from 'react-redux' import { connect } from 'react-redux'
import Profile from './Profile' import Profile from './Profile'
import { toggleProfileModalAction } from './Profile.reducer'
const mapStateToProps = state => state const mapStateToProps = state => state
export default connect(mapStateToProps)(Profile) const mapDispatchToProps = dispatch => ({
openModal: dapp => dispatch(toggleProfileModalAction(dapp)),
})
export default connect(
mapStateToProps,
mapDispatchToProps,
)(Profile)

View File

@ -5,23 +5,14 @@ import Modal from '../../common/components/Modal'
import styles from './Profile.module.scss' import styles from './Profile.module.scss'
import icon from '../../common/assets/images/icon.svg' import icon from '../../common/assets/images/icon.svg'
import chat from '../../common/assets/images/chat.svg' import chat from '../../common/assets/images/chat.svg'
import { Redirect } from 'react-router-dom' import { push } from 'connected-react-router'
const DesktopScreen = props => { const DesktopScreen = props => {
return <Modal visible={props.visible}>{props.children}</Modal> return <Modal visible={props.visible}>{props.children}</Modal>
} }
const MobileScreen = props => { const MobileScreen = props => {
return ( return <>{props.children}</>
<>
{props.router.location.state &&
props.router.location.state.name === props.profile.dapp.name ? (
props.children
) : (
<Redirect to={'/'} />
)}
</>
)
} }
const ProfileContent = ({ const ProfileContent = ({
@ -29,7 +20,6 @@ const ProfileContent = ({
url, url,
description, description,
image, image,
isRanked,
position, position,
category, category,
}) => { }) => {
@ -104,26 +94,53 @@ const ProfileContent = ({
) )
} }
const Profile = props => { class Profile extends Component {
const { innerWidth } = window constructor(props) {
return innerWidth >= 1024 ? ( super(props)
<DesktopScreen {...props.profile}> this.state = {
<ProfileContent {...props.profile.dapp} /> screenSize: 0,
</DesktopScreen> visible: true,
) : ( dapp: {},
<MobileScreen {...props}> }
<ProfileContent {...props.profile.dapp} /> }
</MobileScreen>
)
}
componentDidMount() {
const { innerWidth } = window
const { dapp_name } = this.props.match.params
this.props.dapps.find(dapp => {
if (dapp.name.toLowerCase() === dapp_name.toLowerCase()) {
if (innerWidth >= 1024) {
this.props.openModal(dapp.name)
}
this.setState({
screenSize: innerWidth,
visible: true,
dapp,
})
}
})
}
render() {
return this.state.screenSize >= 1024 ? (
<DesktopScreen visible={this.state.visible}>
<ProfileContent {...this.state.dapp} />
</DesktopScreen>
) : (
<MobileScreen {...this.props}>
<ProfileContent {...this.state.dapp} />
</MobileScreen>
)
}
}
Profile.propTypes = { Profile.propTypes = {
visible: PropTypes.bool.isRequired, visible: PropTypes.bool,
dapp: PropTypes.object, dapp: PropTypes.object,
} }
Profile.defaultProps = { Profile.defaultProps = {
visible: false, // visible: false,
} }
export default Profile export default Profile

View File

@ -7,14 +7,8 @@ const MOBILE_NAVIGATE = 'MOBILE_NAVIGATE'
export const toggleProfileModalAction = dapp => { export const toggleProfileModalAction = dapp => {
const { innerWidth } = window const { innerWidth } = window
history.push(`/${dapp.trim()}`, dapp)
if (innerWidth <= 1024) { if (innerWidth <= 1024) {
history.push(
`/${dapp.name
.toLowerCase()
.trim()
.replace(' ', '-')}`,
dapp,
)
return { return {
type: MOBILE_NAVIGATE, type: MOBILE_NAVIGATE,
payload: dapp, payload: dapp,