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

Commit

Permalink
Added rewards option for Steem posts
Browse files Browse the repository at this point in the history
Posting main content to Steem can be done with 3 payout options: 50/50 SBD?STEEM split, 100% STEEM, or no payout at all.
  • Loading branch information
KrNel committed Apr 10, 2019
1 parent a15fc17 commit 61cac37
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 39 deletions.
5 changes: 5 additions & 0 deletions client/src/actions/sendPostActions.js
Expand Up @@ -36,6 +36,11 @@ const sendPostError = error => ({
error,
});

/**
* Action creator for clearing a new post after the page is loaded.
*
* @return {object} The action data
*/
export const clearNewPost = () => ({
type: CLEAR_NEW_POST,
});
Expand Down
14 changes: 10 additions & 4 deletions client/src/components/pages/Steem/Post/Post.js
Expand Up @@ -142,11 +142,11 @@ class Post extends Component {
commentPayload={commentPayload}
/>
)
: !isFetchingDetails && !hasLength(post)
? (
: isFetchingDetails && !hasLength(post)
? <Loading />
: (
<div>That post does not exist.</div>
)
: <Loading />
}
</React.Fragment>
</ErrorBoundary>
Expand Down Expand Up @@ -214,7 +214,13 @@ class Post extends Component {
}
}

const mapDispatchToProps = (dispatch) => (
/**
* Map redux dispatch functions to component props.
*
* @param {object} dispatch - Redux dispatch
* @returns {object} - Object with recent activity data
*/
const mapDispatchToProps = dispatch => (
{
getContent: (author, permlink) => (
dispatch(getDetailsContent(author, permlink))
Expand Down
47 changes: 23 additions & 24 deletions client/src/components/pages/Steem/Post/PostDetails.js
Expand Up @@ -52,6 +52,13 @@ class PostDetails extends Component {

this.images = [];
this.imagesAlts = [];
this.sortOptions = [
{key: 0, value: 'new', text: 'New'},
{key: 1, value: 'old', text: 'Old'},
//{key: 2, value: 'votes', text: 'Votes'},
{key: 3, value: 'rep', text: 'Reputation'},
{key: 4, value: 'payout', text: 'Payout'}
];

this.state = {
sortBy: 'new',
Expand Down Expand Up @@ -162,19 +169,6 @@ class PostDetails extends Component {
const comments = replies;
const pid = post.id;

const sortPicker = (
<Form>
<Form.Group>
<Form.Field
control={Select}
defaultValue={sortOptions[0].value}
options={sortOptions}
onChange={this.handleSortChange}
/>
</Form.Group>
</Form>
);

return (
<HelmetProvider>
<React.Fragment>
Expand Down Expand Up @@ -281,10 +275,23 @@ class PostDetails extends Component {
}
<div className='comments' id='comments'>
{
comments && (
!!comments.length && (
<React.Fragment>
<div className='left'><h2>Comments</h2></div>
<div className='right'>{ sortPicker }</div>
<div className='left'>
<h2>Comments</h2>
</div>
<div className='right'>
<Form>
<Form.Group>
<Form.Field
control={Select}
defaultValue={this.sortOptions[0].value}
options={this.sortOptions}
onChange={this.handleSortChange}
/>
</Form.Group>
</Form>
</div>
<Comments
comments={comments}
sendComment={sendComment}
Expand Down Expand Up @@ -312,12 +319,4 @@ class PostDetails extends Component {
}
}

const sortOptions = [
{key: 0, value: 'new', text: 'New'},
{key: 1, value: 'old', text: 'Old'},
//{key: 2, value: 'votes', text: 'Votes'},
{key: 3, value: 'rep', text: 'Reputation'},
{key: 4, value: 'payout', text: 'Payout'}
];

export default PostDetails;
8 changes: 7 additions & 1 deletion client/src/components/pages/Steem/Posts.js
Expand Up @@ -287,7 +287,13 @@ const mapStateToProps = state => {
}
}

const mapDispatchToProps = (dispatch) => (
/**
* Map redux dispatch functions to component props.
*
* @param {object} dispatch - Redux dispatch
* @returns {object} - Object with recent activity data
*/
const mapDispatchToProps = dispatch => (
{
getContent: (selectedFilter, query, nextPost, page) => (
dispatch(getSummaryContent(selectedFilter, query, nextPost, page))
Expand Down
49 changes: 39 additions & 10 deletions client/src/components/pages/Steem/Write/Write.js
@@ -1,7 +1,7 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Form, Label } from 'semantic-ui-react'
import { Form, Label, Select } from 'semantic-ui-react'
import { Redirect } from 'react-router-dom';

import Preview from '../Post/Preview';
Expand Down Expand Up @@ -30,10 +30,16 @@ class Write extends Component {
this.state = {
title: '',
body: '',
tags: ''
tags: '',
reward: '50',
}

this.redirect = '';
this.rewardOptions = [
{key: 0, value: '50', text: '50% SBD / 50% STEEM'},
{key: 1, value: '100', text: '100% STEEM'},
{key: 2, value: '0', text: 'Decline Payout'},
];
}


Expand All @@ -57,17 +63,17 @@ class Write extends Component {
handleSubmit = (e) => {
e.preventDefault();

const { title, body, tags } = this.state;
const { title, body, tags, reward } = this.state;
const { createPost } = this.props;

if (body === '' || title === '' || tags === '') return;

const post = this.getNewPostData(title, body, tags);
const post = this.getNewPostData(title, body, tags, reward);

createPost(post);
}

getNewPostData = (title, body, tags) => {
getNewPostData = (title, body, tags, reward) => {
tags = tags.split(' ');
const { user } = this.props;
const post = {
Expand All @@ -81,11 +87,23 @@ class Write extends Component {
post.author = user;
post.parentPermlink = tags[0];
post.jsonMetadata = createPostMetadata(post.body, tags);
post.reward = 'half';
post.reward = reward;

return post;
}

/**
* Set state values for when tag input text changes.
*
* @param {event} e Event triggered by element to handle
* @param {string} value Value of the element triggering the event
*/
handleRewardChange = (e, {value}) => {
this.setState({
reward: value,
});
}

render() {
const {
state: {
Expand Down Expand Up @@ -129,9 +147,14 @@ class Write extends Component {
onChange={this.handleChange}
/>

<Form.Checkbox
label='Payout at 50/50'
/>
<Form.Group>
<Form.Field
control={Select}
defaultValue={this.rewardOptions[0].value}
options={this.rewardOptions}
onChange={this.handleRewardChange}
/>
</Form.Group>

<Form.Button>Submit</Form.Button>
{
Expand Down Expand Up @@ -177,7 +200,13 @@ class Write extends Component {
}
}

const mapDispatchToProps = (dispatch) => (
/**
* Map redux dispatch functions to component props.
*
* @param {object} dispatch - Redux dispatch
* @returns {object} - Object with recent activity data
*/
const mapDispatchToProps = dispatch => (
{
createPost: (post) => (
dispatch(sendPost(post))
Expand Down

0 comments on commit 61cac37

Please sign in to comment.