From 966f0e84e40e39b95c566ba2ce8d812a26155ca4 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 15 Oct 2021 15:24:08 -0500 Subject: [PATCH] Share: support title and url params --- app/soapbox/actions/compose.js | 8 ++++++++ app/soapbox/features/share/index.js | 21 +++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/soapbox/actions/compose.js b/app/soapbox/actions/compose.js index b77944ef8..c63069757 100644 --- a/app/soapbox/actions/compose.js +++ b/app/soapbox/actions/compose.js @@ -615,3 +615,11 @@ export function changePollSettings(expiresIn, isMultiple) { isMultiple, }; } + +export function openComposeWithText(text = '') { + return (dispatch, getState) => { + dispatch(resetCompose()); + dispatch(openModal('COMPOSE')); + dispatch(changeCompose(text)); + }; +} diff --git a/app/soapbox/features/share/index.js b/app/soapbox/features/share/index.js index 94220d3d9..f52904b87 100644 --- a/app/soapbox/features/share/index.js +++ b/app/soapbox/features/share/index.js @@ -3,14 +3,12 @@ import { connect } from 'react-redux'; import { Redirect } from 'react-router-dom'; import PropTypes from 'prop-types'; import ImmutablePureComponent from 'react-immutable-pure-component'; -import { changeCompose } from '../../actions/compose'; -import { openModal } from '../../actions/modal'; +import { openComposeWithText } from '../../actions/compose'; const mapDispatchToProps = dispatch => ({ onShare: (text) => { - dispatch(openModal('COMPOSE')); - dispatch(changeCompose(text)); + dispatch(openComposeWithText(text)); }, }); @@ -25,8 +23,19 @@ class Share extends ImmutablePureComponent { constructor(props) { super(props); - const text = new URLSearchParams(window.location.search).get('text'); - if (text) this.props.onShare(text); + const params = new URLSearchParams(window.location.search); + + const text = [ + params.get('title'), + params.get('text'), + params.get('url'), + ] + .filter(v => v) + .join('\n\n'); + + if (text) { + this.props.onShare(text); + } } render() {