Skip to content

Commit 276ab9d

Browse files
authored
Merge pull request #419 from webpack/feature/vote
bugfixes and improvments in the vote app
2 parents fa23cef + f17eea8 commit 276ab9d

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

components/vote/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
vote as devVote
99
} from "./api.dev";
1010

11-
const API_URL = "https://ipttmcpme6.execute-api.us-east-1.amazonaws.com/production";
11+
const API_URL = "https://oswils44oj.execute-api.us-east-1.amazonaws.com/production/";
1212
const GITHUB_CLIENT_ID = "4d355e2799cb8926c665";
1313
const PRODUCTION_HOST = "webpack.js.org";
1414

components/vote/app-style.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262

6363
&__item-score {
6464
font-size: 150%;
65+
width: 90px;
66+
text-align: right;
6567
}
6668

6769
&__items-list {

components/vote/app.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default class VoteApp extends React.Component {
117117
...vote,
118118
votes: vote.votes + diffValue
119119
})),
120-
score: item.score + score
120+
score: item.score + score * diffValue
121121
}))
122122
},
123123
selfInfo: selfInfo && {
@@ -215,8 +215,8 @@ export default class VoteApp extends React.Component {
215215
return <td>
216216
<VoteButton
217217
className={"vote-app__vote-" + voteSettings.name}
218-
value={vote.votes} myValue={userVote.votes}
219-
maxUp={maximum - userVote.votes} maxDown={userVote.votes - minimum}
218+
value={vote.votes} myValue={value}
219+
maxUp={userVote ? maximum - value : 0} maxDown={userVote ? value - minimum : 0}
220220
color={this.getColor(voteSettings.name)} onVote={(diffValue) => {
221221
this.vote(item.id, voteSettings.name, diffValue, voteSettings.currency, voteSettings.score);
222222
}} />

components/vote/button/button-style.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
font-size: 150%;
55
}
66

7-
&__value, &__my-value, &__upMax, &__up10, &__up1, &__down1, &__down10, &__downMax {
7+
&__value, &__my-value, &__upDown {
88
display: block;
9+
width: 90px;
910
}
1011

11-
&__upMax, &__up10, &__up1, &__down1, &__down10, &__downMax {
12+
&__upDown {
1213
border: 0;
1314
padding: 0;
1415
margin: 0;

components/vote/button/button.jsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,33 @@ export default (props) => {
1818
};
1919

2020
let makeTriangle = (n, fn, size, minForEnabled) => {
21-
const enabled = n > 0 ? (maxUp >= minForEnabled) : (maxDown >= minForEnabled);
22-
return <a href="#"
23-
title={titleText(n)}
24-
onClick={e => click(e, n)}
25-
className="vote-button__upMax">
26-
{fn({size: size, color: enabled ? color : "transparent"})}
27-
</a>;
21+
const enabled = n !== 0 && (n > 0 ? (maxUp >= minForEnabled) : (maxDown >= minForEnabled));
22+
const className = "vote-button__upDown";
23+
if(enabled) {
24+
return <a href="#"
25+
title={titleText(n)}
26+
onClick={e => click(e, n)}
27+
className={className}>
28+
{fn({size: size, color: color})}
29+
</a>;
30+
} else {
31+
return <a
32+
className={className}>
33+
{fn({size: size, color: "#eee"})}
34+
</a>;
35+
}
2836
};
2937

3038
return <div className="vote-button" style={{color: color}}>
3139
{makeTriangle(Infinity, triangleUp, 30, 11)}
3240
{makeTriangle(10, triangleUp, 20, 2)}
3341
{makeTriangle(1, triangleUp, 15, 1)}
34-
<div className="vote-button__value"><span className={className}>{value}</span></div>
35-
<div className="vote-button__my-value">(<span className={className}>{myValue}</span>)</div>
42+
<div className="vote-button__value" title={value + " was voted in total by all users."}>
43+
<span className={className}>{value}</span>
44+
</div>
45+
<div className="vote-button__my-value" title={myValue + " was voted by you."}>
46+
(<span className={className}>{myValue}</span>)
47+
</div>
3648
{makeTriangle(-1, triangleDown, 15, 1)}
3749
{makeTriangle(-10, triangleDown, 20, 2)}
3850
{makeTriangle(-Infinity, triangleDown, 30, 11)}

0 commit comments

Comments
 (0)