mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 16:59:41 +00:00
Add secondary post button back
This commit is contained in:
@@ -31,6 +31,7 @@ import { EditIndicator } from './edit_indicator';
|
||||
import { NavigationBar } from './navigation_bar';
|
||||
import { PollForm } from "./poll_form";
|
||||
import { ReplyIndicator } from './reply_indicator';
|
||||
import { SecondaryPrivacyButton } from './secondary_privacy_button';
|
||||
|
||||
const allowedAroundShortCode = '><\u0085\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029\u0009\u000a\u000b\u000c\u000d';
|
||||
|
||||
@@ -50,6 +51,7 @@ class ComposeForm extends ImmutablePureComponent {
|
||||
spoiler: PropTypes.bool,
|
||||
spoilerAlwaysOn: PropTypes.bool,
|
||||
privacy: PropTypes.string,
|
||||
sideArm: PropTypes.string,
|
||||
spoilerText: PropTypes.string,
|
||||
focusDate: PropTypes.instanceOf(Date),
|
||||
caretPosition: PropTypes.number,
|
||||
@@ -96,6 +98,10 @@ class ComposeForm extends ImmutablePureComponent {
|
||||
if (e.keyCode === 13 && (e.ctrlKey || e.metaKey)) {
|
||||
this.handleSubmit();
|
||||
}
|
||||
|
||||
if (e.keyCode === 13 && e.altKey) {
|
||||
this.handleSecondarySubmit();
|
||||
}
|
||||
};
|
||||
|
||||
getFulltextForCharacterCounting = () => {
|
||||
@@ -110,7 +116,7 @@ class ComposeForm extends ImmutablePureComponent {
|
||||
return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxChars || (isOnlyWhitespace && !anyMedia));
|
||||
};
|
||||
|
||||
handleSubmit = (e) => {
|
||||
handleSubmit = (e, overridePrivacy = null) => {
|
||||
if (this.props.text !== this.textareaRef.current.value) {
|
||||
// Something changed the text inside the textarea (e.g. browser extensions like Grammarly)
|
||||
// Update the state to match the current text
|
||||
@@ -121,13 +127,18 @@ class ComposeForm extends ImmutablePureComponent {
|
||||
return;
|
||||
}
|
||||
|
||||
this.props.onSubmit(this.props.history || null);
|
||||
this.props.onSubmit(this.props.history || null, overridePrivacy);
|
||||
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
handleSecondarySubmit = () => {
|
||||
const { sideArm } = this.props;
|
||||
this.handleSubmit(null, sideArm === 'none' ? null : sideArm);
|
||||
};
|
||||
|
||||
onSuggestionsClearRequested = () => {
|
||||
this.props.onClearSuggestions();
|
||||
};
|
||||
@@ -303,6 +314,12 @@ class ComposeForm extends ImmutablePureComponent {
|
||||
</div>
|
||||
|
||||
<div className='compose-form__submit'>
|
||||
<SecondaryPrivacyButton
|
||||
disabled={!this.canSubmit()}
|
||||
privacy={this.props.sideArm}
|
||||
isEditing={this.props.isEditing}
|
||||
onClick={this.handleSecondarySubmit}
|
||||
/>
|
||||
<Button
|
||||
type='submit'
|
||||
text={intl.formatMessage(this.props.isEditing ? messages.saveChanges : (this.props.isInReply ? messages.reply : messages.publish))}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { useIntl, defineMessages } from 'react-intl';
|
||||
|
||||
import LockIcon from '@/material-icons/400-24px/lock.svg?react';
|
||||
import MailIcon from '@/material-icons/400-24px/mail.svg?react';
|
||||
import PublicIcon from '@/material-icons/400-24px/public.svg?react';
|
||||
import QuietTimeIcon from '@/material-icons/400-24px/quiet_time.svg?react';
|
||||
import { Button } from 'flavours/glitch/components/button';
|
||||
import { Icon } from 'flavours/glitch/components/icon';
|
||||
|
||||
const messages = defineMessages({
|
||||
public: { id: 'privacy.public.short', defaultMessage: 'Public' },
|
||||
unlisted: { id: 'privacy.unlisted.short', defaultMessage: 'Quiet public' },
|
||||
private: { id: 'privacy.private.short', defaultMessage: 'Followers' },
|
||||
direct: { id: 'privacy.direct.short', defaultMessage: 'Specific people' },
|
||||
});
|
||||
|
||||
export const SecondaryPrivacyButton = ({ disabled, privacy, isEditing, onClick }) => {
|
||||
const intl = useIntl();
|
||||
|
||||
if (isEditing || !privacy || privacy === 'none') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const privacyProps = {
|
||||
direct: { icon: 'envelope', iconComponent: MailIcon, title: messages.direct },
|
||||
private: { icon: 'lock', iconComponent: LockIcon, title: messages.private },
|
||||
public: { icon: 'globe', iconComponent: PublicIcon, title: messages.public },
|
||||
unlisted: { icon: 'unlock', iconComponent: QuietTimeIcon, title: messages.unlisted },
|
||||
};
|
||||
|
||||
return (
|
||||
<Button className='secondary-post-button' disabled={disabled} onClick={onClick} title={intl.formatMessage(privacyProps[privacy].title)}>
|
||||
<Icon id={privacyProps[privacy].id} icon={privacyProps[privacy].iconComponent} />
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
SecondaryPrivacyButton.propTypes = {
|
||||
disabled: PropTypes.bool,
|
||||
privacy: PropTypes.string,
|
||||
isEditing: PropTypes.bool,
|
||||
onClick: PropTypes.func.isRequired,
|
||||
};
|
||||
Reference in New Issue
Block a user