Skip to content

Commit 692059a

Browse files
committed
Added new logic for the vote button and some CSS modifications for the mobile
1 parent 860f583 commit 692059a

File tree

5 files changed

+122
-35
lines changed

5 files changed

+122
-35
lines changed

components/vote/api.dev.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ let lists = {
1212
{
1313
name: "influence",
1414
currency: "influence",
15-
maximum: 30,
1615
score: 1,
17-
step: 2,
1816
color: "blue"
1917
},
2018
{
2119
name: "golden",
2220
currency: "goldenInfluence",
2321
score: 1,
24-
step: 10,
2522
color: "#bfa203"
2623
}
2724
],

components/vote/app-style.scss

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929

3030
&__user-section {
3131
flex: 0 0 25%;
32-
padding-left: 20px;
32+
padding: 0 0 30px;
33+
34+
@include break(medium) {
35+
padding: 0 0 0 20px;
36+
}
3337

3438
@include break(large) {
3539
border-left: 2px solid getColor(elephant);
@@ -44,6 +48,7 @@
4448
padding: 1em 0;
4549
font-size: smaller;
4650
color: red;
51+
4752
@include break(medium) {
4853
text-align: center;
4954
}
@@ -141,27 +146,42 @@
141146
display: flex;
142147
flex: 0 0 40%;
143148
border: 1px solid lightgray;
144-
padding: 0 0 0 20px;
145-
margin-right: 30px;
149+
user-select: none;
150+
flex-wrap: wrap;
151+
152+
@include break(medium){
153+
margin-right: 30px;
154+
padding: 0 0 0 20px;
155+
}
146156
}
147157

148158
&__item-score {
149159
align-self: center;
150160
font-size: 20pt;
151-
flex: 0 0 20%;
161+
flex: 0 0 100%;
162+
text-align: center;
163+
164+
@include break(medium){
165+
flex: 0 0 20%;
166+
text-align: left;
167+
}
152168
}
153169

154170
&__item-button {
155-
flex: 0 0 40%;
171+
flex: 0 0 50%;
156172
align-self: center;
173+
174+
@include break(medium){
175+
flex: 0 0 40%;
176+
}
157177
}
158178

159179
&__items-list {
160180
display: block;
161181

162182
& > li {
163183
display: block;
164-
padding: 5px;
184+
padding: 5px 0;
165185
}
166186
}
167187

components/vote/app.jsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import 'whatwg-fetch';
3-
import SidebarItem from '../sidebar-item/sidebar-item';
43
import * as api from "./api";
54
import VoteButton from './button/button';
65
import Influence from './influence.jsx';
@@ -211,16 +210,19 @@ export default class VoteApp extends React.Component {
211210
let value = (userVote && userVote.votes) ? userVote.votes: 0;
212211
if(currencyInfo && currencyInfo.remaining + value < maximum) maximum = currencyInfo.remaining + value;
213212
return <div className="vote-app__item-button">
214-
<VoteButton
215-
className={"vote-app__vote-"+voteSettings.name}
216-
value={vote.votes} myValue={value}
217-
maxUp={userVote ? maximum - value : 0}
218-
maxDown={userVote ? value - minimum : 0}
219-
color={this.getColor(voteSettings.name)}
220-
isLoggedIn = {!!voteAppToken}
221-
onVote={(diffValue) => {
222-
this.vote(item.id, voteSettings.name, diffValue, voteSettings.currency, voteSettings.score);
223-
}}></VoteButton></div>;
213+
<VoteButton
214+
className={"vote-app__vote-" + voteSettings.name}
215+
value={vote.votes}
216+
myValue={value}
217+
maxUp={userVote ? maximum - value : 0}
218+
maxDown={userVote ? value - minimum : 0}
219+
color={this.getColor(voteSettings.name)}
220+
isLoggedIn = {!!voteAppToken}
221+
onVote={(diffValue) => {
222+
this.vote(item.id, voteSettings.name, diffValue, voteSettings.currency, voteSettings.score);
223+
}}
224+
/>
225+
</div>;
224226
})}
225227
</div>
226228
<div className="vote-app__item-content">

components/vote/button/button-style.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
@import 'vars';
2+
@import 'mixins';
3+
@import 'functions';
4+
15
.vote-button {
26
text-align: center;
37
&__value {
@@ -18,6 +22,11 @@
1822

1923
.vote-new-button {
2024
display: flex;
25+
justify-content: center;
26+
27+
@include break(medium) {
28+
justify-content: inherit;
29+
}
2130

2231
&__arrows {
2332
flex: 0 0 10%;
@@ -37,6 +46,7 @@
3746
border: 0;
3847
padding: 0;
3948
margin: 0;
49+
cursor: pointer;
4050
}
4151

4252
&__logout-value {

components/vote/button/button.jsx

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import React, {Component} from 'react';
2-
import "./button-style.scss";
32

43
export default class NewButton extends Component {
5-
handleClick (e, n) {
4+
handleClick (n) {
65
const {maxUp, maxDown, onVote} = this.props;
76
onVote(Math.min(maxUp, Math.max(n, -maxDown)));
8-
e.preventDefault();
97
return false;
108
}
119

@@ -16,30 +14,90 @@ export default class NewButton extends Component {
1614
return n > 0 ? "+" + n : "" + n;
1715
}
1816

19-
makeTriangle (n, fn, size, minForEnabled) {
17+
makeTriangle (n, fn, size, minForEnabled, increase) {
2018
const {maxUp, maxDown, color} = this.props;
2119
const enabled = n !== 0 && (n > 0 ? (maxUp >= minForEnabled) : (maxDown >= minForEnabled));
2220
const className = "vote-new-button__upDown";
21+
2322
if(enabled) {
24-
return <a href="#"
23+
return <span
2524
title={this.titleText(n, maxUp, maxDown)}
26-
onClick={e => this.handleClick(e, n)}
27-
className={className}>
28-
{fn({size: size, color: color})}
29-
</a>;
25+
onClick={() => this.handleClick(n)}
26+
onMouseDown={() => this.startCounter(increase)}
27+
onMouseUp={() => this.stopCounter()}
28+
onMouseOut={() => this.stopCounter()}
29+
onTouchStart={() => this.startCounter(increase)}
30+
onTouchEnd={() => this.stopCounter()}
31+
onTouchCancel={() => this.stopCounter()}
32+
className={className}
33+
>
34+
{fn({size: size, color: color})}
35+
</span>;
3036
} else {
31-
return <a
32-
className={className}>
33-
{fn({size: size, color: "#eee"})}
34-
</a>;
37+
return <span
38+
className={className}
39+
>
40+
{fn({size: size, color: "#eee"})}
41+
</span>;
3542
}
3643
}
44+
45+
startCounter(increase) {
46+
let current = 0;
47+
let add = 0;
48+
const that = this;
49+
50+
if (this.interval) {
51+
clearInterval(this.interval);
52+
}
53+
54+
this.interval = setInterval(function() {
55+
// increase for 1 between 0 and 5
56+
if(current <= 5) {
57+
current++;
58+
add = 1;
59+
}
60+
// increase for 2 between 6 and 10
61+
else if(current <= 10) {
62+
current+=2;
63+
add = 2;
64+
}
65+
// increase for 5 between 11 and 40
66+
else if(current <= 40) {
67+
current+=5;
68+
add = 5;
69+
}
70+
// increase for 10 between 41 and 70
71+
else if(current <= 70) {
72+
current+=10;
73+
add = 10;
74+
}
75+
// increase for 15 after 71
76+
else {
77+
current+=15;
78+
add = 15;
79+
}
80+
81+
if(!increase) {
82+
add *= -1;
83+
}
84+
85+
that.handleClick(add);
86+
}, 200);
87+
}
88+
89+
stopCounter() {
90+
if (this.interval) {
91+
clearInterval(this.interval);
92+
}
93+
}
94+
3795
render() {
3896
const {color, className, value, myValue, isLoggedIn} = this.props;
3997
return isLoggedIn ? (<div className="vote-new-button" style={{color: color}}>
4098
<div className="vote-new-button__arrows">
41-
{this.makeTriangle(1, triangleUp, 10, 1)}
42-
{this.makeTriangle(-1, triangleDown, 10, 1)}
99+
{this.makeTriangle(1, triangleUp, 10, 1, true)}
100+
{this.makeTriangle(-1, triangleDown, 10, 1, false)}
43101
</div>
44102
<div className="vote-new-button__value" title={value + " was voted in total by all users."}>
45103
<span className={className}>{value}</span>

0 commit comments

Comments
 (0)