moved and renamed linkUrl to keep url generation in one place

This commit is contained in:
Ben Wheeler 2019-05-06 18:33:56 -04:00
parent d5e2ed69ad
commit 6a3110e24e
5 changed files with 17 additions and 15 deletions

View file

@ -22,7 +22,6 @@ class SocialModal extends React.Component {
'handleCopyProjectLink',
'hideEmbedResult',
'hideLinkResult',
'linkUrl',
'setEmbedTextarea',
'setLinkTextarea'
]);
@ -67,9 +66,6 @@ class SocialModal extends React.Component {
this.setState({showLinkResult: false});
this.linkCopyTimeoutId = null;
}
linkUrl () {
return `${window.location.origin}${window.location.pathname}`;
}
setEmbedTextarea (textarea) {
this.embedTextarea = textarea;
return textarea;
@ -98,7 +94,7 @@ class SocialModal extends React.Component {
fbUrl={social.facebookIntentLink(projectId)}
googleClassroomUrl={social.googleClassroomIntentLink(projectId)}
isOpen={this.props.isOpen}
linkUrl={this.linkUrl()}
projectUrl={social.projectUrl(projectId)}
setEmbedTextarea={this.setEmbedTextarea}
setLinkTextarea={this.setLinkTextarea}
showEmbedResult={this.state.showEmbedResult}

View file

@ -15,10 +15,10 @@ const SocialModalPresentation = ({
embedHtml,
intl,
isOpen,
linkUrl,
onCopyEmbed,
onCopyProjectLink,
onRequestClose,
projectUrl,
setEmbedTextarea,
setLinkTextarea,
showEmbedResult,
@ -72,7 +72,7 @@ const SocialModalPresentation = ({
className="social-form social-input"
name="link"
ref={textarea => setLinkTextarea(textarea)}
value={linkUrl}
value={projectUrl}
/>
</FlexRow>
</div>
@ -122,10 +122,10 @@ SocialModalPresentation.propTypes = {
embedHtml: PropTypes.string,
intl: intlShape,
isOpen: PropTypes.bool,
linkUrl: PropTypes.string,
onCopyEmbed: PropTypes.func,
onCopyProjectLink: PropTypes.func,
onRequestClose: PropTypes.func,
projectUrl: PropTypes.string,
setEmbedTextarea: PropTypes.func,
setLinkTextarea: PropTypes.func,
showEmbedResult: PropTypes.bool,

View file

@ -1,5 +1,12 @@
module.exports = {};
module.exports.projectUrl = projectId => {
if (projectId) {
return `https://scratch.mit.edu/projects/${projectId}`;
}
return '';
};
module.exports.embedHtml = projectId => {
if (projectId) {
return `<iframe src="https://scratch.mit.edu/projects/${projectId}/embed" ` +

View file

@ -382,6 +382,12 @@ class Preview extends React.Component {
handleAddToStudioClose () {
this.setState({addToStudioOpen: false});
}
handleSocialClick () {
this.setState({socialOpen: true});
}
handleSocialClose () {
this.setState({socialOpen: false});
}
handleReportSubmit (formData) {
const submit = data => this.props.reportProject(this.state.projectId, data, this.props.user.token);
if (this.getProjectThumbnail) {
@ -580,12 +586,6 @@ class Preview extends React.Component {
this.props.user.token
);
}
handleSocialClick () {
this.setState({socialOpen: true});
}
handleSocialClose () {
this.setState({socialOpen: false});
}
initCounts (favorites, loves) {
this.setState({
favoriteCount: favorites,

View file

@ -3,7 +3,6 @@ const connect = require('react-redux').connect;
const defaults = require('lodash.defaultsdeep');
const PropTypes = require('prop-types');
const React = require('react');
// const formik = require('formik');
const api = require('../../lib/api');
const injectIntl = require('../../lib/intl.jsx').injectIntl;