vote & visual fixes

This commit is contained in:
Kamen Stoykov 2019-05-14 14:24:25 +03:00
parent 6276697321
commit 2d57263307
5 changed files with 66 additions and 11 deletions

View File

@ -8,14 +8,6 @@ import dropdownArrows from '../../common/assets/images/dropdown-arrows.svg'
import styles from './CategorySelector.module.scss' import styles from './CategorySelector.module.scss'
class CategorySelector extends React.Component { class CategorySelector extends React.Component {
static onClickHighestRanked() {
window.location.hash = 'highest-ranked'
}
static onClickRecentlyAdded() {
window.location.hash = 'recently-added'
}
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { open: false } this.state = { open: false }
@ -23,6 +15,8 @@ class CategorySelector extends React.Component {
this.updateCategory = this.updateCategory.bind(this) this.updateCategory = this.updateCategory.bind(this)
this.container = React.createRef() this.container = React.createRef()
this.onClickSubmit = this.onClickSubmit.bind(this) this.onClickSubmit = this.onClickSubmit.bind(this)
this.onClickHighestRanked = this.onClickHighestRanked.bind(this)
this.onClickRecentlyAdded = this.onClickRecentlyAdded.bind(this)
} }
componentDidMount() { componentDidMount() {
@ -49,6 +43,20 @@ class CategorySelector extends React.Component {
this.setState({ open: false }) this.setState({ open: false })
} }
onClickHighestRanked(e) {
const { onClickCloseDesktopMenu } = this.props
onClickCloseDesktopMenu()
e.stopPropagation()
window.location.hash = 'highest-ranked'
}
onClickRecentlyAdded(e) {
const { onClickCloseDesktopMenu } = this.props
onClickCloseDesktopMenu()
e.stopPropagation()
window.location.hash = 'recently-added'
}
updateCategory(event) { updateCategory(event) {
const { select } = this.props const { select } = this.props
select(event.target.value) select(event.target.value)
@ -106,7 +114,7 @@ class CategorySelector extends React.Component {
<button <button
className={styles.openButton} className={styles.openButton}
type="button" type="button"
onClick={CategorySelector.onClickHighestRanked} onClick={this.onClickHighestRanked}
> >
<svg <svg
width="18" width="18"
@ -125,7 +133,7 @@ class CategorySelector extends React.Component {
<button <button
className={styles.openButton} className={styles.openButton}
type="button" type="button"
onClick={CategorySelector.onClickRecentlyAdded} onClick={this.onClickRecentlyAdded}
> >
<svg <svg
width="18" width="18"

View File

@ -7,6 +7,8 @@ import {
switchToUpDownvoteAction, switchToUpDownvoteAction,
onInputSntValueAction, onInputSntValueAction,
fetchVoteRatingAction, fetchVoteRatingAction,
upVoteAction,
downVoteAction,
} from './Vote.reducer' } from './Vote.reducer'
const mapStateToProps = state => const mapStateToProps = state =>
@ -19,6 +21,8 @@ const mapDispatchToProps = dispatch => ({
fetchVoteRating: (dapp, isUpvote, sntValue) => { fetchVoteRating: (dapp, isUpvote, sntValue) => {
dispatch(fetchVoteRatingAction(dapp, isUpvote, sntValue)) dispatch(fetchVoteRatingAction(dapp, isUpvote, sntValue))
}, },
upVote: (dapp, amount) => dispatch(upVoteAction(dapp, amount)),
downVote: (dapp, amount) => dispatch(downVoteAction(dapp, amount)),
}) })
export default withRouter( export default withRouter(

View File

@ -9,6 +9,8 @@ import icon from '../../common/assets/images/icon.svg'
import Modal from '../../common/components/Modal' import Modal from '../../common/components/Modal'
import { DappModel } from '../../common/utils/models' import { DappModel } from '../../common/utils/models'
const DOWNVOTE_COST = 3425
const getCategoryName = category => const getCategoryName = category =>
Categories.find(x => x.key === category).value Categories.find(x => x.key === category).value
@ -18,6 +20,7 @@ class Vote extends Component {
this.onClickUpvote = this.onClickUpvote.bind(this) this.onClickUpvote = this.onClickUpvote.bind(this)
this.onClickDownvote = this.onClickDownvote.bind(this) this.onClickDownvote = this.onClickDownvote.bind(this)
this.handleChange = this.handleChange.bind(this) this.handleChange = this.handleChange.bind(this)
this.onClickVote = this.onClickVote.bind(this)
} }
onClickUpvote() { onClickUpvote() {
@ -46,6 +49,12 @@ class Vote extends Component {
fetchVoteRating(dapp, true, intValue) fetchVoteRating(dapp, true, intValue)
} }
onClickVote() {
const { dapp, sntValue, isUpvote, upVote, downVote } = this.props
if (isUpvote) upVote(dapp, parseInt(sntValue, 10))
else downVote(dapp, DOWNVOTE_COST)
}
render() { render() {
const { const {
visible, visible,
@ -64,7 +73,7 @@ class Vote extends Component {
//const catPosition = dapp.categoryPosition //const catPosition = dapp.categoryPosition
// const upvoteSNTcost = currentSNTamount + parseInt(sntValue, 10) // const upvoteSNTcost = currentSNTamount + parseInt(sntValue, 10)
const currentSNTamount = dapp.sntValue const currentSNTamount = dapp.sntValue
const downvoteSNTcost = 3244 const downvoteSNTcost = DOWNVOTE_COST
const dappsByCategory = dapps.filter( const dappsByCategory = dapps.filter(
dapp_ => dapp_.category === dapp.category, dapp_ => dapp_.category === dapp.category,
) )
@ -202,6 +211,7 @@ class Vote extends Component {
<button <button
type="submit" type="submit"
disabled={(!sntValue || sntValue === '0') && isUpvote} disabled={(!sntValue || sntValue === '0') && isUpvote}
onClick={this.onClickVote}
> >
{isUpvote ? 'Upvote' : 'Downvote'} {isUpvote ? 'Upvote' : 'Downvote'}
</button> </button>
@ -227,6 +237,8 @@ Vote.propTypes = {
onClickDownvote: PropTypes.func.isRequired, onClickDownvote: PropTypes.func.isRequired,
onInputSntValue: PropTypes.func.isRequired, onInputSntValue: PropTypes.func.isRequired,
fetchVoteRating: PropTypes.func.isRequired, fetchVoteRating: PropTypes.func.isRequired,
upVote: PropTypes.func.isRequired,
downVote: PropTypes.func.isRequired,
} }
export default Vote export default Vote

View File

@ -192,6 +192,7 @@
font-family: $font; font-family: $font;
padding: calculateRem(11) calculateRem(38); padding: calculateRem(11) calculateRem(38);
font-size: calculateRem(15); font-size: calculateRem(15);
cursor: pointer;
} }
.footer button:disabled, .footer button:disabled,

View File

@ -17,6 +17,20 @@ BlockchainSDK.DiscoverService.upVoteEffect = (id, amount) => {
}, 1000) }, 1000)
}) })
} }
BlockchainSDK.DiscoverService.upVote = (id, amount) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('0xfae78787fa79')
}, 1000)
})
}
BlockchainSDK.DiscoverService.downVote = (id, amount) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('0xfae78787fa79')
}, 1000)
})
}
export const showUpVoteAction = dapp => { export const showUpVoteAction = dapp => {
window.location.hash = 'vote' window.location.hash = 'vote'
@ -80,6 +94,22 @@ export const fetchVoteRatingAction = (dapp, isUpvote, sntValue) => {
} }
} }
export const upVoteAction = (dapp, amount) => {
return async dispatch => {
dispatch(closeVoteAction())
const tx = await BlockchainSDK.DiscoverService.upVote(dapp.id, amount)
console.log('upvote', tx)
}
}
export const downVoteAction = (dapp, amount) => {
return async dispatch => {
dispatch(closeVoteAction())
const tx = await BlockchainSDK.DiscoverService.downVote(dapp.id, amount)
console.log('downvote', tx)
}
}
const showUpVote = (state, dapp) => { const showUpVote = (state, dapp) => {
return Object.assign({}, state, { return Object.assign({}, state, {
visible: true, visible: true,