From b2dd152fae530abffb02cf26ac935d4dcaf54f15 Mon Sep 17 00:00:00 2001 From: Kamen Stoykov Date: Tue, 21 May 2019 10:16:25 +0300 Subject: [PATCH] submit flow --- src/common/data/submit.js | 4 +- src/modules/Dapps/Dapps.reducer.js | 13 +- src/modules/Submit/Submit.container.js | 7 +- src/modules/Submit/Submit.jsx | 385 ++++++++++++------ src/modules/Submit/Submit.module.scss | 143 ++++++- src/modules/Submit/Submit.reducer.js | 34 +- .../TransactionStatus.recuder.js | 9 +- .../TransactionStatus.utilities.js | 14 +- src/modules/Vote/Vote.jsx | 2 +- src/modules/Vote/Vote.reducer.js | 12 +- 10 files changed, 482 insertions(+), 141 deletions(-) diff --git a/src/common/data/submit.js b/src/common/data/submit.js index 6cf7e49..8a17f3e 100644 --- a/src/common/data/submit.js +++ b/src/common/data/submit.js @@ -1,5 +1,6 @@ const submit = { - visible: false, + visible_submit: false, + visible_rating: false, id: '', name: '', desc: '', @@ -11,6 +12,7 @@ const submit = { imgControlMove: false, imgControlX: 0, imgControlY: 0, + sntValue: '0', } export default submit diff --git a/src/modules/Dapps/Dapps.reducer.js b/src/modules/Dapps/Dapps.reducer.js index 15dc817..e40161e 100644 --- a/src/modules/Dapps/Dapps.reducer.js +++ b/src/modules/Dapps/Dapps.reducer.js @@ -2,6 +2,7 @@ import hardcodedDapps from '../../common/data/dapps' import * as Categories from '../../common/data/categories' import reducerUtil from '../../common/utils/reducer' import { showAlertAction } from '../Alert/Alert.reducer' +import { TYPE_SUBMIT } from '../TransactionStatus/TransactionStatus.utilities' //import BlockchainTool from '../../common/blockchain' const ON_FINISH_FETCH_ALL_DAPPS_ACTION = @@ -100,7 +101,9 @@ export const onFinishFetchByCategoryAction = (category, dapps) => ({ }) const fetchAllDappsInState = async (dispatch, getState) => { - const stateDapps = getState().dapps + const state = getState() + const { transactionStatus } = state + const stateDapps = state.dapps if (stateDapps.dapps === null) { try { let dapps = await BlockchainSDK.DiscoverService.getDApps() @@ -112,6 +115,14 @@ const fetchAllDappsInState = async (dispatch, getState) => { dapps.sort((a, b) => { return b.sntValue - a.sntValue }) + if (transactionStatus.type === TYPE_SUBMIT) { + for (let i = 0; i < dapps.length; i += 1) { + if (dapps[i].id === transactionStatus.dappId) { + dapps.splice(i, 1) + break + } + } + } dispatch(onFinishFetchAllDappsAction(dapps)) return dapps diff --git a/src/modules/Submit/Submit.container.js b/src/modules/Submit/Submit.container.js index 31fdf5c..fcfe9e9 100644 --- a/src/modules/Submit/Submit.container.js +++ b/src/modules/Submit/Submit.container.js @@ -15,9 +15,12 @@ import { onImgDoneAction, onImgCancelAction, submitAction, + switchToRatingAction, + onInputSntValueAction, } from './Submit.reducer' -const mapStateToProps = state => state.submit +const mapStateToProps = state => + Object.assign(state.submit, { dapps: state.dapps.dapps }) const mapDispatchToProps = dispatch => ({ onClickClose: () => dispatch(closeSubmitAction()), onInputName: name => dispatch(onInputNameAction(name)), @@ -31,6 +34,8 @@ const mapDispatchToProps = dispatch => ({ onImgDone: imgBase64 => dispatch(onImgDoneAction(imgBase64)), onSubmit: dapp => dispatch(submitAction(dapp)), onClickTerms: () => dispatch(push('/terms')), + switchToRating: () => dispatch(switchToRatingAction()), + onInputSntValue: sntValue => dispatch(onInputSntValueAction(sntValue)), }) export default withRouter( diff --git a/src/modules/Submit/Submit.jsx b/src/modules/Submit/Submit.jsx index 7508f30..738d0db 100644 --- a/src/modules/Submit/Submit.jsx +++ b/src/modules/Submit/Submit.jsx @@ -1,12 +1,20 @@ import React from 'react' import PropTypes from 'prop-types' +import ReactImageFallback from 'react-image-fallback' import styles from './Submit.module.scss' import Modal from '../../common/components/Modal' import CategorySelector from '../CategorySelector/CategorySelector.picker' import Slider from '../../common/components/Slider/Slider' +import CategoriesUtils from '../Categories/Categories.utils' +import Categories from '../../common/utils/categories' +import icon from '../../common/assets/images/icon.svg' +import sntIcon from '../../common/assets/images/SNT.svg' import 'rc-slider/assets/index.css' import 'rc-tooltip/assets/bootstrap.css' +const getCategoryName = category => + Categories.find(x => x.key === category).value + class Submit extends React.Component { constructor(props) { super(props) @@ -24,6 +32,7 @@ class Submit extends React.Component { this.onEndMove = this.onEndMove.bind(this) this.onImgDone = this.onImgDone.bind(this) this.onSubmit = this.onSubmit.bind(this) + this.handleSNTChange = this.handleSNTChange.bind(this) } componentDidUpdate() { @@ -153,9 +162,29 @@ class Submit extends React.Component { onSubmit(dapp) } + handleSNTChange(e) { + const { value } = e.target + if (value !== '' && /^[1-9][0-9]*$/.test(value) === false) return + + const intValue = value === '' ? 0 : parseInt(value, 10) + if (intValue > 1571296) return + + const { dapp, onInputSntValue, fetchVoteRating } = this.props + onInputSntValue(value) + } + + title() { + const { visible_submit, visible_rating, imgControl } = this.props + if (visible_submit) + return imgControl ? 'Position and size your image' : 'Submit a Ðapp' + return 'Ðapp rating' + } + render() { const { - visible, + dapps, + visible_submit, + visible_rating, onClickClose, name, desc, @@ -166,161 +195,256 @@ class Submit extends React.Component { imgControlZoom, onImgCancel, onClickTerms, + switchToRating, + sntValue, } = this.props const canSubmit = name !== '' && desc !== '' && url !== '' && img !== '' && category !== '' + const visible = visible_submit || visible_rating + + /* rating */ + let currentSNTamount = 0 + let dappsByCategory = [] + let catPosition = 0 + let afterVoteRating = null + let afterVoteCategoryPosition = null + + if (visible_rating) { + dappsByCategory = dapps.filter(dapp_ => dapp_.category === category) + + catPosition = dappsByCategory.length + 1 + if (sntValue !== '') { + afterVoteRating = parseInt(sntValue, 10) + afterVoteCategoryPosition = 1 + for (let i = 0; i < dappsByCategory.length; ++i) { + if (dappsByCategory[i].sntValue < afterVoteRating) break + afterVoteCategoryPosition++ + } + } + } + return ( -
- {imgControl ? 'Position and size your image' : 'Submit a Ðapp'} -
-
-
-
-
- Name of your Ðapp -
- -
-
-
- A short description - {desc.length}/140 -
-