Commit 887918a2 authored by Jonathan Porta's avatar Jonathan Porta
Browse files

Fix showing votes for login

parent 213ddb63
......@@ -17,9 +17,9 @@ Proposal.propTypes = {
subject: PropTypes.string.isRequired,
total_votes: PropTypes.number.isRequired,
permlink: PropTypes.string.isRequired,
onUpvote: PropTypes.func.isRequired,
onVote: PropTypes.func.isRequired,
isVoting: PropTypes.bool.isRequired,
upVoted: PropTypes.bool.isRequired,
isUpVoted: PropTypes.bool.isRequired,
};
export default function Proposal(props) {
......@@ -32,11 +32,11 @@ export default function Proposal(props) {
subject,
total_votes,
permlink,
onUpvote,
onVote,
isVoting,
voteFailed,
voteSucceeded,
upVoted,
isUpVoted,
} = props;
const start = new Date(props.start_date);
......@@ -45,17 +45,23 @@ export default function Proposal(props) {
const durationInDays = Moment(end).diff(Moment(start), 'days');
const totalPayout = durationInDays * daily_pay.amount;
// console.log('daily_pay', daily_pay, durationInDays);
console.log(
'PROPOSAL-RENDER(isUpVoted, voteSucceeded, voteFailed, isVoting)',
props,
isUpVoted,
voteSucceeded,
voteFailed,
isVoting
);
const classUp =
'Voting__button Voting__button-up' +
(upVoted > 0 ? ' Voting__button--upvoted' : '') +
(voteSucceeded > 0 ? ' Voting__button--upvoted' : '') +
(voteFailed > 0 ? ' Voting__button--downvoted' : '') +
(isUpVoted ? ' Voting__button--upvoted' : '') +
(voteFailed ? ' Voting__button--downvoted' : '') +
(isVoting ? ' votingUp' : '');
return (
<div className="proposals__row">
<div className="proposals__votes">
<a onClick={onUpvote}>
<a onClick={onVote}>
<span className={classUp}>
<Icon
name={isVoting ? 'empty' : 'chevron-up-circle'}
......
......@@ -11,6 +11,7 @@ class ProposalContainer extends React.Component {
isVoting: false,
voteFailed: false,
voteSucceeded: false,
isUpVoted: props.proposal.isUpVoted,
};
this.id = this.props.proposal.id;
}
......@@ -19,29 +20,39 @@ class ProposalContainer extends React.Component {
// await console.log('ProposalContainer.jsx::componentWillMount()');
}
onUpvote = () => {
onVote = () => {
this.setState({
isVoting: true,
voteFailed: false,
voteSucceeded: false,
});
this.props.upvoteProposal(
const voteForIt = !this.state.isUpVoted;
console.log(
'const voteForIt = !this.props.proposal.upVoted;',
voteForIt
);
this.props.voteOnProposal(
this.id,
voteForIt,
() => {
// console.log('upvoteProposal->success()', arguments)
console.log('voteOnProposal->success()');
this.setState({
isVoting: false,
voteFailed: false,
voteSucceeded: true,
isUpVoted: voteForIt,
});
console.log('voteOnProposal->voteForIt', voteForIt);
},
() => {
// console.log('upvoteProposal->failure()', arguments)
console.log('voteOnProposal->failure()');
this.setState({
isVoting: false,
voteFailed: true,
voteSucceeded: false,
isUpVoted: !voteForIt,
});
console.log('voteOnProposal->voteForIt', voteForIt);
}
);
};
......@@ -50,16 +61,14 @@ class ProposalContainer extends React.Component {
const { proposal } = this.props;
// console.log('ProposalContainer.jsx::render()', this.props);
return (
<Proposal {...proposal} onUpvote={this.onUpvote} {...this.state} />
);
return <Proposal {...proposal} onVote={this.onVote} {...this.state} />;
}
}
ProposalContainer.propTypes = {
proposal: PropTypes.shape({ creator: PropTypes.string.isRequired })
.isRequired,
upvoteProposal: PropTypes.func.isRequired,
voteOnProposal: PropTypes.func.isRequired,
};
export default ProposalContainer;
......@@ -5,7 +5,7 @@ import ProposalContainer from './ProposalContainer';
ProposalList.propTypes = {
proposals: PropTypes.array.isRequired,
upvoteProposal: PropTypes.func.isRequired,
voteOnProposal: PropTypes.func.isRequired,
loading: PropTypes.bool.isRequired,
// proposals: PropTypes.arrayOf(
// PropTypes.shape({
......@@ -22,7 +22,7 @@ ProposalList.propTypes = {
export default function ProposalList(props) {
// console.log('ProposalList.jsx->()', props);
const { proposals, upvoteProposal, loading } = props;
const { proposals, voteOnProposal, loading } = props;
const proposalCount = proposals.length;
if (!loading && proposalCount == 0) {
......@@ -58,7 +58,7 @@ export default function ProposalList(props) {
{proposals.map(proposal => (
<ProposalContainer
key={proposal.id}
upvoteProposal={upvoteProposal}
voteOnProposal={voteOnProposal}
proposal={proposal}
/>
))}
......
......@@ -5,7 +5,7 @@ import ProposalList from './ProposalList';
ProposalList.propTypes = {
proposals: PropTypes.array.isRequired, // TODO: Specify shape.
upvoteProposal: PropTypes.func.isRequired,
voteOnProposal: PropTypes.func.isRequired,
loading: PropTypes.bool.isRequired,
};
......@@ -20,7 +20,7 @@ class ProposalListContainer extends React.Component {
}
render() {
const { proposals, upvoteProposal, loading } = this.props;
const { proposals, voteOnProposal, loading } = this.props;
// console.log('ProposalListContainer.jsx::render()', arguments);
return <ProposalList {...this.props} />;
......
......@@ -21,7 +21,7 @@ class Proposals extends React.Component {
this.state = {
proposals: [],
loading: true,
limit: 2,
limit: 10,
last_proposal: false,
status: 'all',
};
......@@ -31,19 +31,23 @@ class Proposals extends React.Component {
console.log('componentWillMount', this.state);
}
async load() {
async load(quiet = false) {
console.log('load', this.state);
// if (this.state.proposals && this.state.proposals.length > 0) {
// this.setState({ loading: false });
// } else {
this.setState({ loading: true });
if (quiet) {
this.setState({ loading: true });
}
// }
const proposals =
(await this.getAllProposals(
this.state.last_proposal,
'by_total_votes',
'ascending',
// 'by_creator',
// 'ascending',
'descending',
this.state.limit + this.state.proposals.length,
this.state.status
)) || [];
......@@ -122,13 +126,27 @@ class Proposals extends React.Component {
// // return [];
// }
upvoteProposal = (proposalId, onSuccess, onFailure) => {
return this.props.upvoteProposal(
// voteOnProposal = (proposalId, voteForIt, onSuccess, onFailure) => {
// return this.props.voteOnProposal(
// this.props.currentUser,
// [proposalId],
// voteForIt,
// onSuccess,
// onFailure
// );
// };
voteOnProposal = async (proposalId, voteForIt, onSuccess, onFailure) => {
return this.props.voteOnProposal(
this.props.currentUser,
[proposalId],
true,
onSuccess,
onFailure
voteForIt,
async () => {
if (onSuccess) onSuccess();
},
() => {
if (onFailure) onFailure();
}
);
};
......@@ -148,7 +166,7 @@ class Proposals extends React.Component {
return (
<div>
<ProposalListContainer
upvoteProposal={this.upvoteProposal}
voteOnProposal={this.voteOnProposal}
proposals={proposals}
loading={loading}
/>
......@@ -174,7 +192,7 @@ Proposals.propTypes = {
removeProposal: PropTypes.func.isRequired,
// updateProposalVotes: PropTypes.func.isRequired,
createProposal: PropTypes.func.isRequired,
upvoteProposal: PropTypes.func.isRequired,
voteOnProposal: PropTypes.func.isRequired,
};
module.exports = {
......@@ -183,7 +201,12 @@ module.exports = {
state => {
console.log('state.proposal', state.proposal.toJS());
const user = state.user.get('current');
console.log("const user = state.user.get('current');", user);
const currentUser = user && user.get('username');
console.log(
"const currentUser = user && user.get('username');",
currentUser
);
const proposals = state.proposal.get('proposals', List());
const last = proposals.size - 1;
const last_id =
......@@ -248,14 +271,14 @@ module.exports = {
// // );
// };
return {
upvoteProposal: (
voteOnProposal: (
voter,
proposal_ids,
approve,
successCallback,
errorCallback
) => {
console.log('upvoteProposal', arguments);
console.log('voteOnProposal', arguments);
dispatch(
transactionActions.broadcastOperation({
type: 'update_proposal_votes',
......
......@@ -43,10 +43,10 @@ export function* listProposals({
limit,
status
);
let start = [];
const start = [-1, 0];
if (last_proposal) {
//TODO: Switch on the logic for the different types of orders.
start = [last_proposal.id];
// start = [last_proposal.id];
}
const proposals = yield call(
......@@ -65,6 +65,7 @@ export function* listProposals({
console.log('ProposalSaga->listProposals()::proposalIds', proposalIds);
let proposalVotesIds = [];
console.log('ProposalSaga->listProposals()::if(voter_id)', voter_id);
if (voter_id) {
const proposalVotes = yield call(
[api, api.listProposalVotesAsync],
......@@ -81,9 +82,21 @@ export function* listProposals({
proposalVotesIds = proposalVotes
.filter(d => {
console.log(
'ProposalSaga->listProposals()::proposalVotes.filter::d.voter == voter_id',
d.voter == voter_id,
d,
voter_id
);
return d.voter == voter_id;
})
.map(p => {
console.log(
'ProposalSaga->listProposals()::proposalVotes.map((p)',
p.id,
p,
voter_id
);
return p.id;
});
console.log(
......@@ -92,10 +105,18 @@ export function* listProposals({
);
}
const mungedProposals = proposals.map(p => {
console.log(
'ProposalSaga->listProposals()::proposalVotesIds.indexOf(p.proposal_id)',
proposalVotesIds.indexOf(p.proposal_id),
proposalVotesIds
);
console.log('ProposalSaga->listProposals()::p', p, p.upVoted);
if (proposalVotesIds.indexOf(p.proposal_id) != -1) {
p.upVoted = true;
} else {
p.upVoted = false;
}
p.upVoted = false;
console.log('ProposalSaga->listProposals()::p', p, p.upVoted);
return p;
});
......@@ -146,7 +167,9 @@ export function* listVotedOnProposals({
const proposals = data.filter(d => {
return d.voter == voter_id;
});
console.log(`Proposals matching a vote from '${voter_id}', proposals`);
console.log(
`ProposalSaga->listVotedOnProposals()::Proposals matching a vote from '${voter_id}', proposals`
);
yield put(
proposalActions.receiveListProposalVotes({
proposals,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment