bigbuffet-rw/app/soapbox/features/share/index.js

48 lines
865 B
JavaScript
Raw Normal View History

import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { Redirect } from 'react-router-dom';
2021-10-15 13:24:08 -07:00
import { openComposeWithText } from '../../actions/compose';
const mapDispatchToProps = dispatch => ({
onShare: (text) => {
2021-10-15 13:24:08 -07:00
dispatch(openComposeWithText(text));
},
});
export default @connect(null, mapDispatchToProps)
class Share extends React.Component {
static propTypes = {
onShare: PropTypes.func.isRequired,
};
constructor(props) {
super(props);
2021-10-15 13:24:08 -07:00
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() {
return (
<Redirect to='/' />
);
}
}