Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Added flagging/downvoting for posts
Browse files Browse the repository at this point in the history
Flags or downvotes are now functional for posts. A vote slider appears where you can set the amount to flag, from 1 to 100% of vote power applied to the flag. Removing a flag is also possible.
  • Loading branch information
KrNel committed May 26, 2019
1 parent d86e07e commit d10f373
Show file tree
Hide file tree
Showing 11 changed files with 480 additions and 101 deletions.
16 changes: 7 additions & 9 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ class App extends Component {
const loginURL = SteemConnect.getLoginURL(scState);

return (
<React.Fragment>
<NavMenu loginURL={loginURL}>
<Grid container className="wrapper">
<Grid.Column width={16}>
{children}
</Grid.Column>
</Grid>
</NavMenu>
</React.Fragment>
<NavMenu loginURL={loginURL}>
<Grid className="wrapper">
<Grid.Column width={16}>
{children}
</Grid.Column>
</Grid>
</NavMenu>
)
}
}
Expand Down
81 changes: 75 additions & 6 deletions client/src/actions/upvoteActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const client = new Client('https://hive.anyx.io/');

export const UPVOTE_START = 'UPVOTE_START';
export const UPVOTE_SUCCESS = 'UPVOTE_SUCCESS';
export const UPVOTE_FAILED = 'UPVOTE_FAILED';
export const VOTE_FAILED = 'VOTE_FAILED';
export const DOWNVOTE_START = 'DOWNVOTE_START';
export const DOWNVOTE_SUCCESS = 'DOWNVOTE_SUCCESS';

/**
* Action creator for starting an upvote
Expand All @@ -29,7 +31,7 @@ export const upvoteStart = (author, permlink) => ({
});

/**
* Action creator for successful upvote.
* Action creator for a successful upvote.
*
* @param {string} author Author of post
* @param {string} permlink Permlink of post
Expand All @@ -45,6 +47,42 @@ export const upvoteSuccess = (author, permlink, post) => ({
}
});

/**
* Action creator for starting a downvote
*
* @param {string} author Author of post
* @param {string} permlink Permlink of post
* @return {object} The action data
*/
export const downvoteStart = (author, permlink) => ({
type: DOWNVOTE_START,
payload: {
author,
permlink,
post: {
id: 0,
active_votes: [],
},
}
});

/**
* Action creator for a successful downvote.
*
* @param {string} author Author of post
* @param {string} permlink Permlink of post
* @param {object} post Post being voted on
* @return {object} The action data
*/
export const downvoteSuccess = (author, permlink, post) => ({
type: DOWNVOTE_SUCCESS,
payload: {
author,
permlink,
post,
}
});

/**
* Action creator for failed upvote.
*
Expand All @@ -53,8 +91,8 @@ export const upvoteSuccess = (author, permlink, post) => ({
* @param {string} error Error message
* @return {object} The action data
*/
export const upvoteFailed = (author, permlink, post, error) => ({
type: UPVOTE_FAILED,
export const voteFailed = (author, permlink, post, error) => ({
type: VOTE_FAILED,
payload: {
author,
permlink,
Expand Down Expand Up @@ -86,10 +124,41 @@ export const upvotePost = (author, permlink, weight) => (dispatch, getState) =>
})
.catch((err) => {
logger({level: 'error', message: {name: err.name, message: err.message, stack: err.stack}});


client.database.call('get_content', [author, permlink])
.then(post => {
dispatch(voteFailed(author, permlink, post, 'Error on upvote/unvote.'));
})
});
}

/**
* Uses SteemConnect to downvote a post by author and permlink with specified
* vote weight percentage.
*
* @param {string} author Author to upvote
* @param {string} permlink Post permlink to upvote
* @param {number} weight Vote weight percentage to upvote with
* @returns {function} Dispatches returned action object
*/
export const downvotePost = (author, permlink, weight) => (dispatch, getState) => {
dispatch(downvoteStart(author, permlink));

const { user } = getState().auth;

return SteemConnect.vote(user, author, permlink, weight)
.then(res => {
client.database.call('get_content', [author, permlink])
.then(post => {
dispatch(downvoteSuccess(author, permlink, post));
})
})
.catch((err) => {
logger({level: 'error', message: {name: err.name, message: err.message, stack: err.stack}});

client.database.call('get_content', [author, permlink])
.then(post => {
dispatch(upvoteFailed(author, permlink, post, 'Error on upvote/unvote.'));
dispatch(voteFailed(author, permlink, post, 'Error on upvote/unvote.'));
})
});
}
Expand Down
Loading

0 comments on commit d10f373

Please sign in to comment.