2018-03-08 15:57:19 -05:00
|
|
|
const injectIntl = require('react-intl').injectIntl;
|
|
|
|
const PropTypes = require('prop-types');
|
2018-09-04 14:29:59 -04:00
|
|
|
const intlShape = require('react-intl').intlShape;
|
2018-09-14 16:39:35 -04:00
|
|
|
const MediaQuery = require('react-responsive').default;
|
2018-03-08 15:57:19 -05:00
|
|
|
const React = require('react');
|
2018-04-24 11:00:47 -04:00
|
|
|
const Formsy = require('formsy-react').default;
|
|
|
|
const classNames = require('classnames');
|
2018-03-08 15:57:19 -05:00
|
|
|
|
2018-05-02 15:27:49 -04:00
|
|
|
const GUI = require('scratch-gui').default;
|
|
|
|
const IntlGUI = injectIntl(GUI);
|
|
|
|
|
2018-04-24 11:00:47 -04:00
|
|
|
const decorateText = require('../../lib/decorate-text.jsx');
|
2018-03-08 15:57:19 -05:00
|
|
|
const FlexRow = require('../../components/flex-row/flex-row.jsx');
|
2018-05-24 09:57:06 -04:00
|
|
|
const Button = require('../../components/forms/button.jsx');
|
2018-03-08 15:57:19 -05:00
|
|
|
const Avatar = require('../../components/avatar/avatar.jsx');
|
2018-05-31 16:49:17 -04:00
|
|
|
const ShareBanner = require('./share-banner.jsx');
|
|
|
|
const RemixCredit = require('./remix-credit.jsx');
|
|
|
|
const RemixList = require('./remix-list.jsx');
|
2018-09-25 17:16:02 -04:00
|
|
|
const Stats = require('./stats.jsx');
|
2018-05-31 16:49:17 -04:00
|
|
|
const StudioList = require('./studio-list.jsx');
|
2018-09-24 10:58:39 -04:00
|
|
|
const Subactions = require('./subactions.jsx');
|
2018-04-24 11:00:47 -04:00
|
|
|
const InplaceInput = require('../../components/forms/inplace-input.jsx');
|
2018-08-06 11:52:18 -04:00
|
|
|
const TopLevelComment = require('./comment/top-level-comment.jsx');
|
2018-06-13 16:45:48 -04:00
|
|
|
const ExtensionChip = require('./extension-chip.jsx');
|
2018-05-24 13:47:31 -04:00
|
|
|
|
2018-05-28 15:32:23 -04:00
|
|
|
const projectShape = require('./projectshape.jsx').projectShape;
|
2018-03-08 15:57:19 -05:00
|
|
|
require('./preview.scss');
|
|
|
|
|
2018-09-14 16:39:35 -04:00
|
|
|
const frameless = require('../../lib/frameless');
|
|
|
|
|
2018-08-27 17:11:05 -04:00
|
|
|
// disable enter key submission on formsy input fields; otherwise formsy thinks
|
|
|
|
// we meant to trigger the "See inside" button. Instead, treat these keypresses
|
|
|
|
// as a blur, which will trigger a save.
|
|
|
|
const onKeyPress = e => {
|
|
|
|
if (e.target.type === 'text' && e.which === 13 /* Enter */) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.target.blur();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-06-14 09:26:44 -04:00
|
|
|
const PreviewPresentation = ({
|
2018-07-12 10:01:27 -04:00
|
|
|
assetHost,
|
2018-07-09 16:31:16 -04:00
|
|
|
backpackOptions,
|
2018-08-06 11:52:18 -04:00
|
|
|
comments,
|
2018-06-14 09:26:44 -04:00
|
|
|
editable,
|
2018-06-20 09:28:41 -04:00
|
|
|
extensions,
|
2018-06-14 09:26:44 -04:00
|
|
|
faved,
|
|
|
|
favoriteCount,
|
2018-09-04 14:29:59 -04:00
|
|
|
intl,
|
2018-06-14 09:26:44 -04:00
|
|
|
isFullScreen,
|
|
|
|
isLoggedIn,
|
|
|
|
isShared,
|
|
|
|
loved,
|
|
|
|
loveCount,
|
|
|
|
originalInfo,
|
|
|
|
parentInfo,
|
2018-07-12 10:01:27 -04:00
|
|
|
projectHost,
|
2018-06-14 09:26:44 -04:00
|
|
|
projectId,
|
|
|
|
projectInfo,
|
|
|
|
remixes,
|
2018-08-02 17:54:43 -04:00
|
|
|
reportOpen,
|
2018-08-06 11:52:18 -04:00
|
|
|
replies,
|
2018-07-18 18:52:15 -04:00
|
|
|
addToStudioOpen,
|
2018-07-16 13:39:29 -04:00
|
|
|
projectStudios,
|
2018-07-18 18:52:15 -04:00
|
|
|
studios,
|
2018-06-14 09:26:44 -04:00
|
|
|
userOwnsProject,
|
2018-10-03 13:21:36 -04:00
|
|
|
onDeleteComment,
|
2018-06-14 09:26:44 -04:00
|
|
|
onFavoriteClicked,
|
2018-08-06 11:52:18 -04:00
|
|
|
onLoadMore,
|
2018-06-14 09:26:44 -04:00
|
|
|
onLoveClicked,
|
|
|
|
onReportClicked,
|
|
|
|
onReportClose,
|
|
|
|
onReportSubmit,
|
2018-07-18 18:52:15 -04:00
|
|
|
onAddToStudioClicked,
|
|
|
|
onAddToStudioClosed,
|
2018-07-16 13:39:29 -04:00
|
|
|
onToggleStudio,
|
2018-06-14 09:26:44 -04:00
|
|
|
onSeeInside,
|
|
|
|
onUpdate
|
2018-09-24 10:58:39 -04:00
|
|
|
}) => (
|
|
|
|
<div className="preview">
|
|
|
|
<ShareBanner shared={isShared} />
|
|
|
|
{ projectInfo && projectInfo.author && projectInfo.author.id && (
|
|
|
|
<Formsy onKeyPress={onKeyPress}>
|
|
|
|
<div className="inner">
|
2018-10-03 11:03:18 -04:00
|
|
|
<FlexRow className="preview-row force-row">
|
2018-09-24 10:58:39 -04:00
|
|
|
<FlexRow className="project-header">
|
|
|
|
<a href={`/users/${projectInfo.author.username}`}>
|
|
|
|
<Avatar
|
|
|
|
alt={projectInfo.author.username}
|
|
|
|
src={`https://cdn2.scratch.mit.edu/get_image/user/${projectInfo.author.id}_48x48.png`}
|
2018-06-14 09:26:44 -04:00
|
|
|
/>
|
2018-09-24 10:58:39 -04:00
|
|
|
</a>
|
|
|
|
<div className="title">
|
|
|
|
{editable ?
|
|
|
|
<InplaceInput
|
|
|
|
className="project-title"
|
|
|
|
handleUpdate={onUpdate}
|
|
|
|
name="title"
|
|
|
|
validationErrors={{
|
|
|
|
maxLength: intl.formatMessage({
|
|
|
|
id: 'preview.titleMaxLength'
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
validations={{
|
|
|
|
maxLength: 100
|
|
|
|
}}
|
|
|
|
value={projectInfo.title}
|
|
|
|
/> :
|
|
|
|
<React.Fragment>
|
|
|
|
<div
|
|
|
|
className="project-title no-edit"
|
|
|
|
title={projectInfo.title}
|
|
|
|
>{projectInfo.title}</div>
|
|
|
|
{'by '}
|
|
|
|
<a href={`/users/${projectInfo.author.username}`}>
|
|
|
|
{projectInfo.author.username}
|
|
|
|
</a>
|
|
|
|
</React.Fragment>
|
2018-06-14 09:26:44 -04:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</FlexRow>
|
2018-10-03 10:45:10 -04:00
|
|
|
<MediaQuery minWidth={frameless.mobile}>
|
2018-10-03 11:12:56 -04:00
|
|
|
<div className="project-buttons">
|
|
|
|
{/* TODO: Hide Remix button for now until implemented */}
|
|
|
|
{(!userOwnsProject && false) &&
|
|
|
|
<Button className="button remix-button">
|
|
|
|
Remix
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
<Button
|
|
|
|
className="button see-inside-button"
|
|
|
|
onClick={onSeeInside}
|
|
|
|
>
|
|
|
|
See Inside
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</MediaQuery>
|
2018-09-24 10:58:39 -04:00
|
|
|
</FlexRow>
|
|
|
|
<FlexRow className="preview-row">
|
|
|
|
<div className="guiPlayer">
|
|
|
|
<IntlGUI
|
|
|
|
isPlayerOnly
|
|
|
|
assetHost={assetHost}
|
|
|
|
backpackOptions={backpackOptions}
|
|
|
|
basePath="/"
|
|
|
|
className="guiPlayer"
|
|
|
|
isFullScreen={isFullScreen}
|
|
|
|
previewInfoVisible="false"
|
|
|
|
projectHost={projectHost}
|
|
|
|
projectId={projectId}
|
|
|
|
/>
|
|
|
|
</div>
|
2018-09-25 17:16:02 -04:00
|
|
|
<MediaQuery maxWidth={frameless.tablet - 1}>
|
|
|
|
<FlexRow className="preview-row force-center">
|
|
|
|
<Stats
|
|
|
|
faved={faved}
|
|
|
|
favoriteCount={favoriteCount}
|
|
|
|
loveCount={loveCount}
|
|
|
|
loved={loved}
|
|
|
|
projectInfo={projectInfo}
|
|
|
|
onFavoriteClicked={onFavoriteClicked}
|
|
|
|
onLoveClicked={onLoveClicked}
|
|
|
|
/>
|
|
|
|
<Subactions
|
|
|
|
addToStudioOpen={addToStudioOpen}
|
|
|
|
isLoggedIn={isLoggedIn}
|
|
|
|
projectInfo={projectInfo}
|
|
|
|
reportOpen={reportOpen}
|
|
|
|
studios={studios}
|
|
|
|
userOwnsProject={userOwnsProject}
|
|
|
|
onAddToStudioClicked={onAddToStudioClicked}
|
|
|
|
onAddToStudioClosed={onAddToStudioClosed}
|
|
|
|
onReportClicked={onReportClicked}
|
|
|
|
onReportClose={onReportClose}
|
|
|
|
onReportSubmit={onReportSubmit}
|
|
|
|
onToggleStudio={onToggleStudio}
|
|
|
|
/>
|
|
|
|
</FlexRow>
|
|
|
|
</MediaQuery>
|
2018-09-24 10:58:39 -04:00
|
|
|
<FlexRow className="project-notes">
|
|
|
|
<RemixCredit projectInfo={parentInfo} />
|
|
|
|
<RemixCredit projectInfo={originalInfo} />
|
|
|
|
{/* eslint-disable max-len */}
|
|
|
|
<MediaQuery maxWidth={frameless.tablet - 1}>
|
|
|
|
<FlexRow className="preview-row">
|
|
|
|
<FlexRow className="extension-list">
|
|
|
|
{extensions && extensions.map(extension => (
|
|
|
|
<ExtensionChip
|
|
|
|
extensionL10n={extension.l10nId}
|
|
|
|
extensionName={extension.name}
|
|
|
|
hasStatus={extension.hasStatus}
|
|
|
|
iconURI={extension.icon && `/svgs/project/${extension.icon}`}
|
|
|
|
key={extension.name || extension.l10nId}
|
|
|
|
/>
|
|
|
|
))}
|
2018-09-24 11:50:44 -04:00
|
|
|
</FlexRow>
|
2018-05-24 13:47:31 -04:00
|
|
|
</FlexRow>
|
2018-09-25 17:16:02 -04:00
|
|
|
</MediaQuery>
|
|
|
|
<FlexRow className="description-block">
|
2018-09-24 10:58:39 -04:00
|
|
|
<div className="project-textlabel">
|
|
|
|
Instructions
|
|
|
|
</div>
|
|
|
|
{editable ?
|
|
|
|
<InplaceInput
|
|
|
|
className={classNames(
|
|
|
|
'project-description-edit',
|
|
|
|
{remixes: parentInfo && parentInfo.author}
|
|
|
|
)}
|
|
|
|
handleUpdate={onUpdate}
|
|
|
|
name="instructions"
|
|
|
|
placeholder="Tell people how to use your project (such as which keys to press)."
|
|
|
|
type="textarea"
|
|
|
|
validationErrors={{
|
|
|
|
maxLength: 'Sorry description is too long'
|
|
|
|
// maxLength: props.intl.formatMessage({
|
|
|
|
// id: 'project.descriptionMaxLength'
|
|
|
|
// })
|
|
|
|
}}
|
|
|
|
validations={{
|
|
|
|
// TODO: actual 5000
|
|
|
|
maxLength: 1000
|
|
|
|
}}
|
|
|
|
value={projectInfo.instructions}
|
|
|
|
/> :
|
|
|
|
<div className="project-description">
|
|
|
|
{decorateText(projectInfo.instructions)}
|
2018-05-24 13:47:31 -04:00
|
|
|
</div>
|
2018-09-24 10:58:39 -04:00
|
|
|
}
|
2018-04-24 11:00:47 -04:00
|
|
|
</FlexRow>
|
2018-09-24 10:58:39 -04:00
|
|
|
<FlexRow className="description-block">
|
|
|
|
<div className="project-textlabel">
|
|
|
|
Notes and Credits
|
2018-03-08 15:57:19 -05:00
|
|
|
</div>
|
2018-09-24 10:58:39 -04:00
|
|
|
{editable ?
|
|
|
|
<InplaceInput
|
|
|
|
className={classNames(
|
|
|
|
'project-description-edit',
|
|
|
|
'last',
|
|
|
|
{remixes: parentInfo && parentInfo.author}
|
|
|
|
)}
|
|
|
|
handleUpdate={onUpdate}
|
|
|
|
name="description"
|
|
|
|
placeholder="How did you make this project? Did you use ideas scripts or artwork from other people? Thank them here."
|
|
|
|
type="textarea"
|
|
|
|
validationErrors={{
|
|
|
|
maxLength: 'Sorry description is too long'
|
|
|
|
// maxLength: props.intl.formatMessage({
|
|
|
|
// id: 'project.descriptionMaxLength'
|
|
|
|
// })
|
|
|
|
}}
|
|
|
|
validations={{
|
|
|
|
// TODO: actual 5000
|
|
|
|
maxLength: 1000
|
|
|
|
}}
|
|
|
|
value={projectInfo.description}
|
|
|
|
/> :
|
|
|
|
<div className="project-description last">
|
|
|
|
{decorateText(projectInfo.description)}
|
|
|
|
</div>
|
|
|
|
}
|
2018-04-24 11:00:47 -04:00
|
|
|
</FlexRow>
|
2018-09-24 10:58:39 -04:00
|
|
|
{/* eslint-enable max-len */}
|
|
|
|
</FlexRow>
|
|
|
|
</FlexRow>
|
2018-09-25 17:16:02 -04:00
|
|
|
<MediaQuery minWidth={frameless.tablet}>
|
|
|
|
<FlexRow className="preview-row">
|
|
|
|
<Stats
|
|
|
|
faved={faved}
|
|
|
|
favoriteCount={favoriteCount}
|
|
|
|
loveCount={loveCount}
|
|
|
|
loved={loved}
|
|
|
|
projectInfo={projectInfo}
|
|
|
|
onFavoriteClicked={onFavoriteClicked}
|
|
|
|
onLoveClicked={onLoveClicked}
|
|
|
|
/>
|
|
|
|
<Subactions
|
|
|
|
addToStudioOpen={addToStudioOpen}
|
|
|
|
isLoggedIn={isLoggedIn}
|
|
|
|
projectInfo={projectInfo}
|
|
|
|
reportOpen={reportOpen}
|
|
|
|
studios={studios}
|
|
|
|
userOwnsProject={userOwnsProject}
|
|
|
|
onAddToStudioClicked={onAddToStudioClicked}
|
|
|
|
onAddToStudioClosed={onAddToStudioClosed}
|
|
|
|
onReportClicked={onReportClicked}
|
|
|
|
onReportClose={onReportClose}
|
|
|
|
onReportSubmit={onReportSubmit}
|
|
|
|
onToggleStudio={onToggleStudio}
|
|
|
|
/>
|
2018-09-24 10:58:39 -04:00
|
|
|
</FlexRow>
|
2018-09-25 17:16:02 -04:00
|
|
|
</MediaQuery>
|
2018-09-24 10:58:39 -04:00
|
|
|
<MediaQuery minWidth={frameless.tablet}>
|
|
|
|
<FlexRow className="preview-row">
|
|
|
|
<FlexRow className="extension-list">
|
|
|
|
{extensions && extensions.map(extension => (
|
|
|
|
<ExtensionChip
|
|
|
|
extensionL10n={extension.l10nId}
|
|
|
|
extensionName={extension.name}
|
|
|
|
hasStatus={extension.hasStatus}
|
|
|
|
iconURI={extension.icon && `/svgs/project/${extension.icon}`}
|
|
|
|
key={extension.name || extension.l10nId}
|
|
|
|
/>
|
|
|
|
))}
|
2018-05-24 13:47:31 -04:00
|
|
|
</FlexRow>
|
2018-06-14 09:26:44 -04:00
|
|
|
</FlexRow>
|
2018-09-24 10:58:39 -04:00
|
|
|
</MediaQuery>
|
|
|
|
</div>
|
|
|
|
<div className="project-lower-container">
|
|
|
|
<div className="inner">
|
|
|
|
<FlexRow className="preview-row">
|
|
|
|
<div className="comments-container">
|
|
|
|
<FlexRow className="comments-header">
|
|
|
|
<h4>Comments</h4>
|
|
|
|
{/* TODO: Add toggle comments component and logic*/}
|
|
|
|
</FlexRow>
|
|
|
|
<FlexRow className="comments-list">
|
|
|
|
{comments.map(comment => (
|
|
|
|
<TopLevelComment
|
|
|
|
author={comment.author}
|
|
|
|
content={comment.content}
|
|
|
|
datetimeCreated={comment.datetime_created}
|
2018-10-03 13:21:36 -04:00
|
|
|
deletable={userOwnsProject}
|
|
|
|
deleted={comment.deleted}
|
2018-09-24 10:58:39 -04:00
|
|
|
id={comment.id}
|
|
|
|
key={comment.id}
|
|
|
|
parentId={comment.parent_id}
|
|
|
|
projectId={projectId}
|
|
|
|
replies={replies && replies[comment.id] ? replies[comment.id] : []}
|
2018-10-03 13:21:36 -04:00
|
|
|
onDelete={onDeleteComment}
|
2018-09-24 11:50:44 -04:00
|
|
|
/>
|
|
|
|
))}
|
2018-09-24 10:58:39 -04:00
|
|
|
{comments.length < projectInfo.stats.comments &&
|
|
|
|
<Button
|
|
|
|
className="button load-more-button"
|
|
|
|
onClick={onLoadMore}
|
|
|
|
>
|
|
|
|
Load More
|
|
|
|
</Button>
|
|
|
|
}
|
2018-09-24 11:50:44 -04:00
|
|
|
</FlexRow>
|
2018-09-24 10:58:39 -04:00
|
|
|
</div>
|
|
|
|
<FlexRow className="column">
|
|
|
|
<RemixList remixes={remixes} />
|
|
|
|
<StudioList studios={projectStudios} />
|
2018-04-24 11:00:47 -04:00
|
|
|
</FlexRow>
|
2018-09-24 10:58:39 -04:00
|
|
|
</FlexRow>
|
2018-08-06 11:52:18 -04:00
|
|
|
</div>
|
2018-09-24 10:58:39 -04:00
|
|
|
</div>
|
|
|
|
</Formsy>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
2018-03-08 15:57:19 -05:00
|
|
|
|
2018-03-15 17:40:16 -04:00
|
|
|
PreviewPresentation.propTypes = {
|
2018-07-25 15:08:12 -04:00
|
|
|
addToStudioOpen: PropTypes.bool,
|
2018-07-12 10:01:27 -04:00
|
|
|
assetHost: PropTypes.string,
|
2018-07-09 16:31:16 -04:00
|
|
|
backpackOptions: PropTypes.shape({
|
|
|
|
host: PropTypes.string,
|
|
|
|
visible: PropTypes.bool
|
|
|
|
}),
|
2018-08-06 11:52:18 -04:00
|
|
|
comments: PropTypes.arrayOf(PropTypes.object),
|
2018-05-24 09:57:06 -04:00
|
|
|
editable: PropTypes.bool,
|
2018-06-20 09:28:41 -04:00
|
|
|
extensions: PropTypes.arrayOf(PropTypes.object),
|
2018-05-24 09:57:06 -04:00
|
|
|
faved: PropTypes.bool,
|
|
|
|
favoriteCount: PropTypes.number,
|
2018-09-04 14:29:59 -04:00
|
|
|
intl: intlShape,
|
2018-05-24 09:57:06 -04:00
|
|
|
isFullScreen: PropTypes.bool,
|
2018-06-01 14:25:45 -04:00
|
|
|
isLoggedIn: PropTypes.bool,
|
2018-05-31 16:49:17 -04:00
|
|
|
isShared: PropTypes.bool,
|
2018-05-24 09:57:06 -04:00
|
|
|
loveCount: PropTypes.number,
|
|
|
|
loved: PropTypes.bool,
|
2018-07-25 15:08:12 -04:00
|
|
|
onAddToStudioClicked: PropTypes.func,
|
|
|
|
onAddToStudioClosed: PropTypes.func,
|
2018-10-03 13:21:36 -04:00
|
|
|
onDeleteComment: PropTypes.func,
|
2018-05-24 09:57:06 -04:00
|
|
|
onFavoriteClicked: PropTypes.func,
|
2018-08-06 11:52:18 -04:00
|
|
|
onLoadMore: PropTypes.func,
|
2018-05-24 09:57:06 -04:00
|
|
|
onLoveClicked: PropTypes.func,
|
2018-05-31 16:49:17 -04:00
|
|
|
onReportClicked: PropTypes.func.isRequired,
|
|
|
|
onReportClose: PropTypes.func.isRequired,
|
|
|
|
onReportSubmit: PropTypes.func.isRequired,
|
2018-05-24 09:57:06 -04:00
|
|
|
onSeeInside: PropTypes.func,
|
2018-07-25 15:08:12 -04:00
|
|
|
onToggleStudio: PropTypes.func,
|
2018-05-24 09:57:06 -04:00
|
|
|
onUpdate: PropTypes.func,
|
2018-05-28 15:32:23 -04:00
|
|
|
originalInfo: projectShape,
|
|
|
|
parentInfo: projectShape,
|
2018-07-12 10:01:27 -04:00
|
|
|
projectHost: PropTypes.string,
|
2018-05-24 16:23:07 -04:00
|
|
|
projectId: PropTypes.string,
|
2018-05-28 15:32:23 -04:00
|
|
|
projectInfo: projectShape,
|
2018-07-25 15:08:12 -04:00
|
|
|
projectStudios: PropTypes.arrayOf(PropTypes.object),
|
2018-04-24 11:00:47 -04:00
|
|
|
remixes: PropTypes.arrayOf(PropTypes.object),
|
2018-08-06 11:52:18 -04:00
|
|
|
replies: PropTypes.objectOf(PropTypes.array),
|
2018-08-02 17:54:43 -04:00
|
|
|
reportOpen: PropTypes.bool,
|
2018-07-18 18:52:15 -04:00
|
|
|
studios: PropTypes.arrayOf(PropTypes.object),
|
2018-05-31 16:49:17 -04:00
|
|
|
userOwnsProject: PropTypes.bool
|
2018-03-15 17:40:16 -04:00
|
|
|
};
|
2018-03-08 15:57:19 -05:00
|
|
|
|
2018-03-15 17:40:16 -04:00
|
|
|
module.exports = injectIntl(PreviewPresentation);
|