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

View File

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

View File

@ -1,7 +1,15 @@
import { connect } from 'react-redux'
import Profile from './Profile'
import { toggleProfileModalAction } from './Profile.reducer'
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 icon from '../../common/assets/images/icon.svg'
import chat from '../../common/assets/images/chat.svg'
import { Redirect } from 'react-router-dom'
import { push } from 'connected-react-router'
const DesktopScreen = props => {
return <Modal visible={props.visible}>{props.children}</Modal>
}
const MobileScreen = props => {
return (
<>
{props.router.location.state &&
props.router.location.state.name === props.profile.dapp.name ? (
props.children
) : (
<Redirect to={'/'} />
)}
</>
)
return <>{props.children}</>
}
const ProfileContent = ({
@ -29,7 +20,6 @@ const ProfileContent = ({
url,
description,
image,
isRanked,
position,
category,
}) => {
@ -104,26 +94,53 @@ const ProfileContent = ({
)
}
const Profile = props => {
const { innerWidth } = window
return innerWidth >= 1024 ? (
<DesktopScreen {...props.profile}>
<ProfileContent {...props.profile.dapp} />
</DesktopScreen>
) : (
<MobileScreen {...props}>
<ProfileContent {...props.profile.dapp} />
</MobileScreen>
)
}
class Profile extends Component {
constructor(props) {
super(props)
this.state = {
screenSize: 0,
visible: true,
dapp: {},
}
}
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 = {
visible: PropTypes.bool.isRequired,
visible: PropTypes.bool,
dapp: PropTypes.object,
}
Profile.defaultProps = {
visible: false,
// visible: false,
}
export default Profile

View File

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