Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Local-Toot/Secondary Button #33

Merged
merged 2 commits into from Oct 27, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -63,6 +63,9 @@ class ComposeForm extends ImmutablePureComponent {
layout: PropTypes.string,
media: ImmutablePropTypes.list,
sideArm: PropTypes.string,
showSideArmLocalToot: PropTypes.bool,
showSideArmLocalSecondary: PropTypes.bool,
onChangeLocal: PropTypes.func,
sensitive: PropTypes.bool,
spoilersAlwaysOn: PropTypes.bool,
mediaDescriptionConfirmation: PropTypes.bool,
@@ -81,7 +84,14 @@ class ComposeForm extends ImmutablePureComponent {
this.props.onChange(e.target.value);
}

handleKeyDown = ({ ctrlKey, keyCode, metaKey, altKey }) => {
handleKeyDown = ({ ctrlKey, keyCode, metaKey, altKey, shiftKey }) => {
const { onChangeLocal } = this.props;

// Shift + Enter + x = Local
if (shiftKey && keyCode === 13 && (ctrlKey || metaKey || altKey)) {
onChangeLocal(true);
}

// We submit the status on control/meta + enter.
if (keyCode === 13 && (ctrlKey || metaKey)) {
this.handleSubmit();
@@ -161,6 +171,17 @@ class ComposeForm extends ImmutablePureComponent {
this.handleSubmit();
}

handleSideArmLocalSubmit = type => {
const {
onChangeVisibility,
onChangeLocal,
} = this.props;

onChangeVisibility(type);
onChangeLocal(true);
this.handleSubmit();
}

// Selects a suggestion from the autofill.
onSuggestionSelected = (tokenStart, token, value) => {
this.props.onSuggestionSelected(tokenStart, token, value, ['text']);
@@ -266,6 +287,7 @@ class ComposeForm extends ImmutablePureComponent {
handleSelect,
handleSubmit,
handleRefTextarea,
handleSideArmLocalSubmit,
} = this;
const {
advancedOptions,
@@ -285,6 +307,8 @@ class ComposeForm extends ImmutablePureComponent {
sensitive,
showSearch,
sideArm,
showSideArmLocalToot,
showSideArmLocalSecondary,
spoiler,
spoilerText,
suggestions,
@@ -368,6 +392,9 @@ class ComposeForm extends ImmutablePureComponent {
onSubmit={handleSubmit}
privacy={privacy}
sideArm={sideArm}
showSideArmLocalToot={showSideArmLocalToot}
showSideArmLocalSecondary={showSideArmLocalSecondary}
handleSideArmLocalSubmit={handleSideArmLocalSubmit}
/>
</div>
);
@@ -1,3 +1,5 @@
/* eslint react/jsx-no-bind: 0 */

// Package imports.
import classNames from 'classnames';
import PropTypes from 'prop-types';
@@ -36,10 +38,14 @@ class Publisher extends ImmutablePureComponent {
onSubmit: PropTypes.func,
privacy: PropTypes.oneOf(['direct', 'private', 'unlisted', 'public']),
sideArm: PropTypes.oneOf(['none', 'direct', 'private', 'unlisted', 'public']),
showSideArmLocalToot: PropTypes.bool,
showSideArmLocalSecondary: PropTypes.bool,
handleSideArmLocalSubmit: PropTypes.func,
};

render () {
const { countText, disabled, intl, onSecondarySubmit, onSubmit, privacy, sideArm } = this.props;
const { showSideArmLocalToot, showSideArmLocalSecondary, handleSideArmLocalSubmit } = this.props;

const diff = maxChars - length(countText || '');
const computedClass = classNames('composer--publisher', {
@@ -49,6 +55,29 @@ class Publisher extends ImmutablePureComponent {

return (
<div className={computedClass}>
{sideArm && sideArm !== 'none' && showSideArmLocalSecondary && (
<Button
className='side_arm is_local'
disabled={disabled || diff < 0}
onClick={() => handleSideArmLocalSubmit(sideArm)}
text={
<span>
<Icon
id={{
public: 'globe',
unlisted: 'unlock',
private: 'lock',
direct: 'envelope',
}[sideArm]}
fixedWidth
/>
<Icon id='home' fixedWidth />
</span>
}
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage({ id: `privacy.${sideArm}.short` })} (${intl.formatMessage({ id: 'advanced_options.local-only.short' })})`}
/>
)}

{sideArm && sideArm !== 'none' ? (
<Button
className='side_arm'
@@ -70,6 +99,30 @@ class Publisher extends ImmutablePureComponent {
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage({ id: `privacy.${sideArm}.short` })}`}
/>
) : null}

{showSideArmLocalToot && (
<Button
className='side_arm is_local'
disabled={disabled || diff < 0}
onClick={() => handleSideArmLocalSubmit(privacy)}
text={
<span>
<Icon
id={{
public: 'globe',
unlisted: 'unlock',
private: 'lock',
direct: 'envelope',
}[privacy]}
fixedWidth
/>
<Icon id='home' fixedWidth />
</span>
}
title={`${intl.formatMessage(messages.publish)}: ${intl.formatMessage({ id: `privacy.${privacy}.short` })} (${intl.formatMessage({ id: 'advanced_options.local-only.short' })})`}
/>
)}

<Button
className='primary'
text={function () {
@@ -12,6 +12,7 @@ import {
selectComposeSuggestion,
submitCompose,
uploadCompose,
changeComposeAdvancedOption,
} from 'flavours/glitch/actions/compose';
import {
openModal,
@@ -58,6 +59,8 @@ function mapStateToProps (state) {
preselectDate: state.getIn(['compose', 'preselectDate']),
privacy: state.getIn(['compose', 'privacy']),
sideArm: sideArmPrivacy,
showSideArmLocalToot: state.getIn(['local_settings', 'side_arm_local_toot']),
showSideArmLocalSecondary: state.getIn(['local_settings', 'side_arm_local_secondary']),
sensitive: state.getIn(['compose', 'sensitive']),
showSearch: state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']),
spoiler: spoilersAlwaysOn || state.getIn(['compose', 'spoiler']),
@@ -125,6 +128,10 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}));
},

onChangeLocal(value) {
dispatch(changeComposeAdvancedOption('do_not_federate', value));
},

});

export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(ComposeForm));
@@ -199,6 +199,22 @@ class LocalSettingsPage extends React.PureComponent {
>
<FormattedMessage id='settings.show_content_type_choice' defaultMessage='Show content-type choice when authoring toots' />
</LocalSettingsPageItem>
<LocalSettingsPageItem
settings={settings}
item={['side_arm_local_toot']}
id='mastodon-settings--side_arm_local_toot'
onChange={onChange}
>
<FormattedMessage id='settings.side_arm_local_toot' defaultMessage='トゥートボタンの横にローカル投稿ボタンを表示する' />
</LocalSettingsPageItem>
<LocalSettingsPageItem
settings={settings}
item={['side_arm_local_secondary']}
id='mastodon-settings--side_arm_local_secondary'
onChange={onChange}
>
<FormattedMessage id='settings.side_arm_local_secondary' defaultMessage='セカンダリボタンの横に(セカンダリの)ローカル投稿ボタンを表示する' />
</LocalSettingsPageItem>
<LocalSettingsPageItem
settings={settings}
item={['side_arm']}
@@ -68,6 +68,8 @@ const messages = {
'settings.side_arm_reply_mode.copy': '返信先の投稿範囲を利用する',
'settings.side_arm_reply_mode.keep': 'セカンダリートゥートボタンの設定を維持する',
'settings.side_arm_reply_mode.restrict': '返信先の投稿範囲に制限する',
'settings.side_arm_local_toot': 'トゥートボタンの横にローカル投稿ボタンを表示する',
'settings.side_arm_local_secondary': 'セカンダリボタンの横に(セカンダリの)ローカル投稿ボタンを表示する',
'settings.layout': 'レイアウト',
'settings.layout_opts': 'レイアウトの設定',
'status.collapse': '折りたたむ',
@@ -646,10 +646,15 @@

& > .side_arm {
display: inline-block;
margin: 0 2px;
padding: 0;
width: 36px;
text-align: center;
margin-right: 2px;

&.is_local {
width: initial;
padding: 0 4px !important;
}
}

&.over {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.