mirror of
https://github.com/status-im/snt-voting.git
synced 2025-02-23 07:38:07 +00:00
Slider works with click pressed
This commit is contained in:
parent
1886688e32
commit
7ac1b72114
@ -139,7 +139,8 @@ class PollVoting extends Component {
|
||||
class BallotSlider extends Component {
|
||||
|
||||
state = {
|
||||
value: 0
|
||||
value: 0,
|
||||
interval: null
|
||||
}
|
||||
|
||||
componentWillReceiveProps(prevProps){
|
||||
@ -156,26 +157,53 @@ class BallotSlider extends Component {
|
||||
this.props.updateVotes(value);
|
||||
};*/
|
||||
|
||||
increaseVotes = (event) => {
|
||||
let value = this.state.value;
|
||||
if(value + 1 > this.props.maxVotesAvailable){
|
||||
value = this.props.maxVotesAvailable;
|
||||
}
|
||||
|
||||
value++;
|
||||
this.setState({value});
|
||||
this.props.updateVotes(value);
|
||||
|
||||
|
||||
increaseVotes = (event) => {
|
||||
this.removeInterval();
|
||||
|
||||
const updateVotes = () => {
|
||||
let value = this.state.value;
|
||||
if(value + 1 > this.props.maxVotesAvailable){
|
||||
value = this.props.maxVotesAvailable;
|
||||
} else {
|
||||
value++;
|
||||
}
|
||||
this.setState({value});
|
||||
this.props.updateVotes(value);
|
||||
};
|
||||
|
||||
updateVotes();
|
||||
|
||||
const interval = setInterval(updateVotes, 150);
|
||||
this.setState({interval});
|
||||
}
|
||||
|
||||
reduceVotes = (event) => {
|
||||
let value = this.state.value;
|
||||
if(value - 1 < 0){
|
||||
value = 0;
|
||||
}
|
||||
this.removeInterval();
|
||||
|
||||
const updateVotes = () => {
|
||||
let value = this.state.value;
|
||||
if(value - 1 < 0){
|
||||
value = 0;
|
||||
} else {
|
||||
value--;
|
||||
}
|
||||
this.setState({value});
|
||||
this.props.updateVotes(value);
|
||||
|
||||
};
|
||||
|
||||
updateVotes();
|
||||
const interval = setInterval(updateVotes, 150);
|
||||
this.setState({interval});
|
||||
}
|
||||
|
||||
removeInterval = () => {
|
||||
clearInterval(this.state.interval);
|
||||
this.setState({interval: null});
|
||||
|
||||
value--;
|
||||
this.setState({value});
|
||||
this.props.updateVotes(value);
|
||||
}
|
||||
|
||||
render(){
|
||||
@ -193,10 +221,10 @@ class BallotSlider extends Component {
|
||||
<Typography component="p">{subtitle}</Typography>
|
||||
<div className="customSlider">
|
||||
<div className="nav1">
|
||||
<button onMouseDown={this.reduceVotes} disabled={percentage == 0 || cantVote || value == 0}><img src="images/slider-minus.svg" /></button>
|
||||
<button onMouseDown={this.reduceVotes} onMouseUp={this.removeInterval} disabled={percentage == 0 || cantVote || value == 0}><img src="images/slider-minus.svg" /></button>
|
||||
</div>
|
||||
<div className="nav2">
|
||||
<button onMouseDown={this.increaseVotes} disabled={percentage == 100 || cantVote || nextVote > maxVotesAvailable}><img src="images/slider-plus.svg" /></button>
|
||||
<button onMouseDown={this.increaseVotes} onMouseUp={this.removeInterval} disabled={percentage == 100 || cantVote || nextVote > maxVotesAvailable}><img src="images/slider-plus.svg" /></button>
|
||||
</div>
|
||||
<div className="content">
|
||||
<div className="progress progress-large">
|
||||
|
@ -71,7 +71,7 @@ contract PollManager is Controlled {
|
||||
{
|
||||
require(_endTime > block.timestamp, "End time must be greater than current timestamp");
|
||||
require(_startBlock >= block.number, "Start block must not be in the past");
|
||||
require(_numBallots <= 15, "Only a max of 15 ballots are allowed");
|
||||
require(_numBallots <= 50, "Only a max of 50 ballots are allowed");
|
||||
|
||||
_idPoll = _polls.length;
|
||||
_polls.length ++;
|
||||
@ -98,7 +98,7 @@ contract PollManager is Controlled {
|
||||
public
|
||||
{
|
||||
require(_idPoll < _polls.length, "Invalid _idPoll");
|
||||
require(_numBallots <= 15, "Only a max of 15 ballots are allowed");
|
||||
require(_numBallots <= 50, "Only a max of 50 ballots are allowed");
|
||||
|
||||
Poll storage p = _polls[_idPoll];
|
||||
require(p.startBlock > block.number, "You cannot modify an active poll");
|
||||
@ -252,8 +252,8 @@ contract PollManager is Controlled {
|
||||
bool _finalized,
|
||||
uint _voters,
|
||||
address _author,
|
||||
uint[15] _tokenTotal,
|
||||
uint[15] _quadraticVotes
|
||||
uint[50] _tokenTotal,
|
||||
uint[50] _quadraticVotes
|
||||
)
|
||||
{
|
||||
require(_idPoll < _polls.length, "Invalid _idPoll");
|
||||
@ -303,7 +303,7 @@ contract PollManager is Controlled {
|
||||
function getVote(uint _idPoll, address _voter)
|
||||
public
|
||||
view
|
||||
returns (uint[15] votes){
|
||||
returns (uint[50] votes){
|
||||
require(_idPoll < _polls.length, "Invalid _idPoll");
|
||||
Poll storage p = _polls[_idPoll];
|
||||
for(uint8 i = 0; i < p.numBallots; i++){
|
||||
|
Loading…
x
Reference in New Issue
Block a user