From 6235ca5ab222ab32707b7456b46fdf1471b515df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Fri, 1 Oct 2021 19:36:58 +0200 Subject: [PATCH] Implement /share route MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/features/share/index.js | 38 +++++++++++++++++++ app/soapbox/features/ui/index.js | 3 ++ .../features/ui/util/async-components.js | 4 ++ .../features/ui/util/react_router_helpers.js | 2 +- 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 app/soapbox/features/share/index.js diff --git a/app/soapbox/features/share/index.js b/app/soapbox/features/share/index.js new file mode 100644 index 000000000..94220d3d9 --- /dev/null +++ b/app/soapbox/features/share/index.js @@ -0,0 +1,38 @@ +import React from 'react'; +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'; + +const mapDispatchToProps = dispatch => ({ + + onShare: (text) => { + dispatch(openModal('COMPOSE')); + dispatch(changeCompose(text)); + }, + +}); + +export default @connect(null, mapDispatchToProps) +class Share extends ImmutablePureComponent { + + static propTypes = { + onShare: PropTypes.func.isRequired, + }; + + constructor(props) { + super(props); + + const text = new URLSearchParams(window.location.search).get('text'); + if (text) this.props.onShare(text); + } + + render() { + return ( + + ); + } + +} diff --git a/app/soapbox/features/ui/index.js b/app/soapbox/features/ui/index.js index 1badfaae2..74b5c0c40 100644 --- a/app/soapbox/features/ui/index.js +++ b/app/soapbox/features/ui/index.js @@ -107,6 +107,7 @@ import { ModalContainer, ProfileHoverCard, RegisterInvite, + Share, } from './util/async-components'; // Dummy import, to make sure that ends up in the application bundle. @@ -299,6 +300,8 @@ class SwitchingColumnsArea extends React.PureComponent { + + ); diff --git a/app/soapbox/features/ui/util/async-components.js b/app/soapbox/features/ui/util/async-components.js index 19a5fa1c5..43e8c99d3 100644 --- a/app/soapbox/features/ui/util/async-components.js +++ b/app/soapbox/features/ui/util/async-components.js @@ -405,3 +405,7 @@ export function FollowRecommendations() { export function RegisterInvite() { return import(/* webpackChunkName: "features/register_invite" */'../../register_invite'); } + +export function Share() { + return import(/* webpackChunkName: "features/share" */'../../share'); +} diff --git a/app/soapbox/features/ui/util/react_router_helpers.js b/app/soapbox/features/ui/util/react_router_helpers.js index 2fa1970e0..4a636a738 100644 --- a/app/soapbox/features/ui/util/react_router_helpers.js +++ b/app/soapbox/features/ui/util/react_router_helpers.js @@ -84,7 +84,7 @@ class WrappedRoute extends React.Component { const { component: Component, content, publicRoute, me, ...rest } = this.props; if (!publicRoute && me === false) { - const actualUrl = encodeURIComponent(this.props.computedMatch.url); // eslint-disable-line react/prop-types + const actualUrl = encodeURIComponent(`${this.props.computedMatch.url}${this.props.location.search}`); // eslint-disable-line react/prop-types return ; // return { // window.location.href = `/auth/sign_in?redirect_uri=${actualUrl}`;