Skip to content
Snippets Groups Projects
Commit 6f1ca0d7 authored by Jason Salyers's avatar Jason Salyers
Browse files

Merge branch 'jsalyers-temp-voting-fix' into 'develop'

[JES] Temporary fix to the vote button not changing state after votes

See merge request !129
parents 28d65250 8c8448b4
No related branches found
No related tags found
2 merge requests!131Develop,!129[JES] Temporary fix to the vote button not changing state after votes
......@@ -21,6 +21,7 @@ import {
import DropdownMenu from 'app/components/elements/DropdownMenu';
import TimeAgoWrapper from 'app/components/elements/TimeAgoWrapper';
import Dropdown from 'app/components/elements/Dropdown';
import { List } from 'immutable';
const ABOUT_FLAG = (
<div>
......@@ -613,7 +614,7 @@ export default connect(
// mapStateToProps
(state, ownProps) => {
const post =
ownProps.post || state.global.getIn(['content', ownProps.post_ref]);
state.global.getIn(['content', ownProps.post_ref]) || ownProps.post;
if (!post) {
console.error('post_not_found', ownProps);
......@@ -622,7 +623,8 @@ export default connect(
const author = post.get('author');
const permlink = post.get('permlink');
const active_votes = post.get('active_votes');
let votes_key = ['content', author + '/' + permlink, 'active_votes'];
const active_votes = state.global.getIn(votes_key, List());
const is_comment = post.get('depth') == 0;
const current = state.user.get('current');
......@@ -640,7 +642,17 @@ export default connect(
let myVote = ownProps.myVote || null; // ownProps: test only
if (username && active_votes) {
const vote = active_votes.find(el => el.get('voter') === username);
if (vote) myVote = parseInt(vote.get('rshares'), 10);
if (vote) {
let has_rshares = vote.get('rshares') !== undefined;
let has_percent = vote.get('percent') !== undefined;
if (has_rshares && !has_percent) {
myVote = parseInt(vote.get('rshares'), 10);
} else if (!has_rshares && has_percent) {
myVote = vote.get('percent');
} else if (has_rshares && has_percent) {
myVote = null;
}
}
}
return {
......
......@@ -181,6 +181,14 @@ export default function reducer(state = defaultState, action = {}) {
c.mergeDeep(content)
);
// merge vote info taking pending votes into account
let votes_key = ['content', key, 'active_votes'];
let old_votes = state.getIn(votes_key, List());
let new_votes = content.get('active_votes');
const { merge } = require('immutable');
let merged_votes = new_votes.merge(new_votes, old_votes);
new_state = new_state.setIn(votes_key, merged_votes);
// set creation-pending key (optimistic UI update)
if (content.get('depth') == 0) {
const category = content.get('category');
......@@ -246,10 +254,9 @@ export default function reducer(state = defaultState, action = {}) {
const idx = votes.findIndex(v => v.get('voter') === voter);
votes = idx === -1 ? votes.push(vote) : votes.set(idx, vote);
console.log('Applying vote @ idx', idx, payload);
// TODO: new state never returned -- masked by RECEIVE_CONTENT
state.setIn(key, votes);
state = state.setIn(key, votes);
return state;
}
......
......@@ -21,8 +21,10 @@ export async function callBridge(method, params) {
params &&
(params.observer === null || params.observer === undefined) &&
params.tag === 'my'
)
) {
delete params.tag;
delete params.observer;
}
return new Promise(function(resolve, reject) {
api.call('bridge.' + method, params, function(err, data) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment