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

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

parent 28d65250
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 { ...@@ -21,6 +21,7 @@ import {
import DropdownMenu from 'app/components/elements/DropdownMenu'; import DropdownMenu from 'app/components/elements/DropdownMenu';
import TimeAgoWrapper from 'app/components/elements/TimeAgoWrapper'; import TimeAgoWrapper from 'app/components/elements/TimeAgoWrapper';
import Dropdown from 'app/components/elements/Dropdown'; import Dropdown from 'app/components/elements/Dropdown';
import { List } from 'immutable';
const ABOUT_FLAG = ( const ABOUT_FLAG = (
<div> <div>
...@@ -613,7 +614,7 @@ export default connect( ...@@ -613,7 +614,7 @@ export default connect(
// mapStateToProps // mapStateToProps
(state, ownProps) => { (state, ownProps) => {
const post = const post =
ownProps.post || state.global.getIn(['content', ownProps.post_ref]); state.global.getIn(['content', ownProps.post_ref]) || ownProps.post;
if (!post) { if (!post) {
console.error('post_not_found', ownProps); console.error('post_not_found', ownProps);
...@@ -622,7 +623,8 @@ export default connect( ...@@ -622,7 +623,8 @@ export default connect(
const author = post.get('author'); const author = post.get('author');
const permlink = post.get('permlink'); 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 is_comment = post.get('depth') == 0;
const current = state.user.get('current'); const current = state.user.get('current');
...@@ -640,7 +642,17 @@ export default connect( ...@@ -640,7 +642,17 @@ export default connect(
let myVote = ownProps.myVote || null; // ownProps: test only let myVote = ownProps.myVote || null; // ownProps: test only
if (username && active_votes) { if (username && active_votes) {
const vote = active_votes.find(el => el.get('voter') === username); 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 { return {
......
...@@ -181,6 +181,14 @@ export default function reducer(state = defaultState, action = {}) { ...@@ -181,6 +181,14 @@ export default function reducer(state = defaultState, action = {}) {
c.mergeDeep(content) 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) // set creation-pending key (optimistic UI update)
if (content.get('depth') == 0) { if (content.get('depth') == 0) {
const category = content.get('category'); const category = content.get('category');
...@@ -246,10 +254,9 @@ export default function reducer(state = defaultState, action = {}) { ...@@ -246,10 +254,9 @@ export default function reducer(state = defaultState, action = {}) {
const idx = votes.findIndex(v => v.get('voter') === voter); const idx = votes.findIndex(v => v.get('voter') === voter);
votes = idx === -1 ? votes.push(vote) : votes.set(idx, vote); 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 // TODO: new state never returned -- masked by RECEIVE_CONTENT
state.setIn(key, votes); state = state.setIn(key, votes);
return state; return state;
} }
......
...@@ -21,8 +21,10 @@ export async function callBridge(method, params) { ...@@ -21,8 +21,10 @@ export async function callBridge(method, params) {
params && params &&
(params.observer === null || params.observer === undefined) && (params.observer === null || params.observer === undefined) &&
params.tag === 'my' params.tag === 'my'
) ) {
delete params.tag; delete params.tag;
delete params.observer;
}
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
api.call('bridge.' + method, params, function(err, data) { 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