Skip to content

Commit

Permalink
add default payout options (steemit#2769)
Browse files Browse the repository at this point in the history
* remove autovote steemit#2512
* add default comment and blog payout options steemit#2512
* remove dead nsfwPref, use camelCase for payoutType steemit#2512
  • Loading branch information
roadscape authored May 1, 2018
1 parent e0c4fbe commit bf226f4
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 168 deletions.
113 changes: 29 additions & 84 deletions src/app/components/elements/ReplyEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ReplyEditor extends React.Component {
title: React.PropTypes.string, // initial value
body: React.PropTypes.string, // initial value
richTextEditor: React.PropTypes.func,
payoutType: React.PropTypes.string,
};

static defaultProps = {
Expand Down Expand Up @@ -96,12 +97,6 @@ class ReplyEditor extends React.Component {
? stateFromHtml(this.props.richTextEditor, raw)
: null,
});
this.setAutoVote();
this.setState({
payoutType: this.props.isStory
? localStorage.getItem('defaultPayoutType') || '50%'
: '50%',
});
}
}

Expand Down Expand Up @@ -205,7 +200,6 @@ class ReplyEditor extends React.Component {
confirm(tt('reply_editor.are_you_sure_you_want_to_clear_this_form'))
) {
replyForm.resetForm();
this.setAutoVote();
this.setState({
rte_value: stateFromHtml(this.props.richTextEditor),
});
Expand All @@ -214,13 +208,6 @@ class ReplyEditor extends React.Component {
}
};

autoVoteOnChange = () => {
const { autoVote } = this.state;
const key = 'replyEditorData-autoVote-story';
localStorage.setItem(key, !autoVote.value);
autoVote.props.onChange(!autoVote.value);
};

// As rte_editor is updated, keep the (invisible) 'body' field in sync.
onChange = rte_value => {
this.setState({ rte_value });
Expand All @@ -229,17 +216,6 @@ class ReplyEditor extends React.Component {
if (body.value !== html) body.props.onChange(html);
};

setAutoVote() {
const { isStory } = this.props;
if (isStory) {
const { autoVote } = this.state;
const key = 'replyEditorData-autoVote-story';
const autoVoteDefault = JSON.parse(
localStorage.getItem(key) || false
);
autoVote.props.onChange(autoVoteDefault);
}
}
toggleRte = e => {
e.preventDefault();
const state = { rte: !this.state.rte };
Expand All @@ -259,13 +235,6 @@ class ReplyEditor extends React.Component {
draft.className = 'ReplyEditor__draft ReplyEditor__draft-saved';
}

onPayoutTypeChange = e => {
const payoutType = e.currentTarget.value;
this.setState({ payoutType });
if (payoutType !== '0%')
localStorage.setItem('defaultPayoutType', payoutType);
};

onDrop = (acceptedFiles, rejectedFiles) => {
if (!acceptedFiles.length) {
if (rejectedFiles.length) {
Expand Down Expand Up @@ -334,8 +303,8 @@ class ReplyEditor extends React.Component {
category: this.props.category,
body: this.props.body,
};
const { onCancel, onTitleChange, autoVoteOnChange } = this;
const { title, category, body, autoVote } = this.state;
const { onCancel, onTitleChange } = this;
const { title, category, body } = this.state;
const {
reply,
username,
Expand All @@ -350,9 +319,10 @@ class ReplyEditor extends React.Component {
jsonMetadata,
state,
successCallback,
payoutType,
} = this.props;
const { submitting, valid, handleSubmit } = this.state.replyForm;
const { postError, titleWarn, rte, payoutType } = this.state;
const { postError, titleWarn, rte } = this.state;
const { progress, noClipboardData } = this.state;
const disabled = submitting || !valid;
const loading = submitting || this.state.loading;
Expand All @@ -366,8 +336,6 @@ class ReplyEditor extends React.Component {
};
const isEdit = type === 'edit';
const isHtml = rte || isHtmlTest(body.value);
// Be careful, autoVote can reset curation rewards. Never autoVote on edit..
const autoVoteValue = !isEdit && autoVote.value;
const replyParams = {
author,
permlink,
Expand All @@ -379,7 +347,6 @@ class ReplyEditor extends React.Component {
isHtml,
isStory,
jsonMetadata,
autoVote: autoVoteValue,
payoutType,
successCallback: successCallbackWrapper,
errorCallback,
Expand Down Expand Up @@ -640,50 +607,19 @@ class ReplyEditor extends React.Component {
{tt('g.clear')}
</button>
)}
{isStory &&
!isEdit && (
{!isEdit &&
this.props.payoutType != '50%' && (
<div className="ReplyEditor__options float-right text-right">
{tt('g.rewards')} &nbsp;
<select
value={this.state.payoutType}
onChange={this.onPayoutTypeChange}
style={{
color:
this.state.payoutType ==
'0%'
? 'orange'
: '',
}}
>
<option value="100%">
{tt(
'reply_editor.power_up_100'
)}
</option>
<option value="50%">
{tt(
'reply_editor.default_50_50'
)}
</option>
<option value="0%">
{tt(
'reply_editor.decline_payout'
)}
</option>
</select>
<br />
<label
title={tt(
'reply_editor.check_this_to_auto_upvote_your_post'
)}
>
{tt('g.upvote_post')} &nbsp;
<input
type="checkbox"
checked={autoVote.value}
onChange={autoVoteOnChange}
/>
</label>
{tt('g.rewards')}
{': '}
{this.props.payoutType == '0%' &&
tt('reply_editor.decline_payout')}
{this.props.payoutType == '100%' &&
tt('reply_editor.power_up_100')}
{'. '}
<a href={'/@' + username + '/settings'}>
Update settings
</a>
</div>
)}
</div>
Expand Down Expand Up @@ -775,7 +711,7 @@ export default formId =>
// mapStateToProps
(state, ownProps) => {
const username = state.user.getIn(['current', 'username']);
const fields = ['body', 'autoVote:checked'];
const fields = ['body'];
const { type, parent_author, jsonMetadata } = ownProps;
const isEdit = type === 'edit';
const isStory =
Expand All @@ -788,11 +724,21 @@ export default formId =>
if (isStory && jsonMetadata && jsonMetadata.tags) {
category = Set([category, ...jsonMetadata.tags]).join(' ');
}

const payoutType = state.app.getIn(
[
'user_preferences',
isStory ? 'defaultBlogPayout' : 'defaultCommentPayout',
],
'50%'
);

const ret = {
...ownProps,
fields,
isStory,
username,
payoutType,
initialValues: { title, body, category },
state,
formId,
Expand Down Expand Up @@ -828,7 +774,6 @@ export default formId =>
isStory,
type,
originalPost,
autoVote = false,
payoutType = '50%',
state,
jsonMetadata,
Expand Down Expand Up @@ -950,7 +895,7 @@ export default formId =>
startLoadingIndicator();

const originalBody = isEdit ? originalPost.body : null;
const __config = { originalBody, autoVote };
const __config = { originalBody };

// Avoid changing payout option during edits #735
if (!isEdit) {
Expand Down
Loading

0 comments on commit bf226f4

Please sign in to comment.