From 3935f74bebd859b2290f7195290608923782400a Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 23 Feb 2024 20:29:09 +0100 Subject: [PATCH] [WiP] Add secondary post button back --- .../compose/components/compose_form.jsx | 12 +++++ .../components/secondary_privacy_button.jsx | 44 +++++++++++++++++++ .../containers/compose_form_container.js | 20 +++++++++ 3 files changed, 76 insertions(+) create mode 100644 app/javascript/flavours/glitch/features/compose/components/secondary_privacy_button.jsx diff --git a/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx b/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx index ac5ff73928985d..eb28379f0abb8a 100644 --- a/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx +++ b/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx @@ -33,6 +33,7 @@ import { FederationButton } from './federation_button'; import { NavigationBar } from './navigation_bar'; import { PollForm } from "./poll_form"; import { ReplyIndicator } from './reply_indicator'; +import { SecondaryPrivacyButton } from './secondary_privacy_button'; import { ThreadModeButton } from './thread_mode_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'; @@ -53,6 +54,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, @@ -100,6 +102,10 @@ class ComposeForm extends ImmutablePureComponent { if (e.keyCode === 13 && (e.ctrlKey || e.metaKey)) { this.handleSubmit(); } + + if (e.keyCode === 13 && e.altKey) { + this.handleSecondarySubmit(); + } }; getFulltextForCharacterCounting = () => { @@ -132,6 +138,11 @@ class ComposeForm extends ImmutablePureComponent { } }; + handleSecondarySubmit = () => { + const { sideArm } = this.props; + this.handleSubmit(null, sideArm === 'none' ? null : sideArm); + }; + onSuggestionsClearRequested = () => { this.props.onClearSuggestions(); }; @@ -310,6 +321,7 @@ class ComposeForm extends ImmutablePureComponent {
+ + ); +}; + +SecondaryPrivacyButton.propTypes = { + privacy: PropTypes.string, + isEditing: PropTypes.bool, + onClick: PropTypes.func.isRequired, +}; diff --git a/app/javascript/flavours/glitch/features/compose/containers/compose_form_container.js b/app/javascript/flavours/glitch/features/compose/containers/compose_form_container.js index 0d9df213bd7373..a371606bee0af5 100644 --- a/app/javascript/flavours/glitch/features/compose/containers/compose_form_container.js +++ b/app/javascript/flavours/glitch/features/compose/containers/compose_form_container.js @@ -1,5 +1,7 @@ import { connect } from 'react-redux'; +import { privacyPreference } from 'flavours/glitch/utils/privacy_preference'; + import { changeCompose, submitCompose, @@ -12,6 +14,23 @@ import { } from '../../../actions/compose'; import ComposeForm from '../components/compose_form'; +const sideArmPrivacy = state => { + const inReplyTo = state.getIn(['compose', 'in_reply_to']); + const replyPrivacy = inReplyTo ? state.getIn(['statuses', inReplyTo, 'visibility']) : null; + const sideArmBasePrivacy = state.getIn(['local_settings', 'side_arm']); + const sideArmRestrictedPrivacy = replyPrivacy ? privacyPreference(replyPrivacy, sideArmBasePrivacy) : null; + let sideArmPrivacy = null; + switch (state.getIn(['local_settings', 'side_arm_reply_mode'])) { + case 'copy': + sideArmPrivacy = replyPrivacy; + break; + case 'restrict': + sideArmPrivacy = sideArmRestrictedPrivacy; + break; + } + return sideArmPrivacy || sideArmBasePrivacy; +}; + const mapStateToProps = state => ({ text: state.getIn(['compose', 'text']), suggestions: state.getIn(['compose', 'suggestions']), @@ -30,6 +49,7 @@ const mapStateToProps = state => ({ anyMedia: state.getIn(['compose', 'media_attachments']).size > 0, isInReply: state.getIn(['compose', 'in_reply_to']) !== null, lang: state.getIn(['compose', 'language']), + sideArm: sideArmPrivacy(state), }); const mapDispatchToProps = (dispatch) => ({