Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load project into editor when app starts #2

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions src/components/crash-message/crash-message.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@
font-size: 0.875rem;
cursor: pointer;
}

.text-link {
color: white;
}
21 changes: 2 additions & 19 deletions src/components/crash-message/crash-message.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {FormattedMessage} from 'react-intl';

import styles from './crash-message.css';
import reloadIcon from './reload.svg';
import { BASE_API_URL } from '../../utils/constants.js';

const CrashMessage = props => (
<div className={styles.crashWrapper}>
Expand All @@ -20,15 +21,6 @@ const CrashMessage = props => (
id="gui.crashMessage.label"
/>
</h2>
<p>
<FormattedMessage
defaultMessage={'We are so sorry, but it looks like Scratch has crashed. This bug has been' +
' automatically reported to the Scratch Team. Please refresh your page to try' +
' again.'}
description="Message to inform the user that page has crashed."
id="gui.crashMessage.description"
/>
</p>
{props.eventId && (
<p>
<FormattedMessage
Expand All @@ -41,16 +33,7 @@ const CrashMessage = props => (
/>
</p>
)}
<button
className={styles.reloadButton}
onClick={props.onReload}
>
<FormattedMessage
defaultMessage="Reload"
description="Button to reload the page when page crashes"
id="gui.crashMessage.reload"
/>
</button>
<a href={`${BASE_API_URL}/`} className={styles.textLink}>Go back to project list</a>
</Box>
</div>
);
Expand Down
5 changes: 2 additions & 3 deletions src/components/menu-bar/menu-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,7 @@ class MenuBar extends React.Component {
<FormattedMessage {...ariaMessages.tutorials} />
</div>
<Divider className={classNames(styles.divider)} /> */}
{/* hide this code for first release */}
{/* {this.props.canEditTitle ? (
{this.props.canEditTitle ? (
<div className={classNames(styles.menuBarItem, styles.growable)}>
<MenuBarItemTooltip
enable
Expand All @@ -567,7 +566,7 @@ class MenuBar extends React.Component {
userId={this.props.authorId}
username={this.props.authorUsername}
/>
) : null)} */}
) : null)}
{/* hide share button for first release */}
{/* <div className={classNames(styles.menuBarItem)}>
{this.props.canShare ? (
Expand Down
6 changes: 5 additions & 1 deletion src/lib/hash-parser-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const HashParserHOC = function (WrappedComponent) {
}
componentDidMount () {
window.addEventListener('hashchange', this.handleHashChange);
// FIXME: replace mock projectId with real one
window.addEventListener('load', () => {
window.location.hash = '/project/1'
});
this.handleHashChange();
}
componentDidUpdate (prevProps) {
Expand All @@ -37,7 +41,7 @@ const HashParserHOC = function (WrappedComponent) {
window.removeEventListener('hashchange', this.handleHashChange);
}
handleHashChange () {
const hashMatch = window.location.hash.match(/#(\d+)/);
const hashMatch = window.location.hash.match(/\/(\d+)$/);
const hashProjectId = hashMatch === null ? defaultProjectId : hashMatch[1];
this.props.setProjectId(hashProjectId.toString());
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/project-fetcher-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const ProjectFetcherHOC = function (WrappedComponent) {
};
ProjectFetcherComponent.defaultProps = {
assetHost: 'https://assets.scratch.mit.edu',
projectHost: 'https://projects.scratch.mit.edu'
projectHost: 'http://localhost:3000/ccm/scratch-api/projects'
};

const mapStateToProps = state => ({
Expand Down
20 changes: 1 addition & 19 deletions src/lib/project-saver-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,25 +226,7 @@ const ProjectSaverHOC = function (WrappedComponent) {
// serialized project refers to a newer asset than what
// we just finished saving).
const savedVMState = this.props.vm.toJSON();
return Promise.all(this.props.vm.assets
.filter(asset => !asset.clean)
.map(
asset => storage.store(
asset.assetType,
asset.dataFormat,
asset.data,
asset.assetId
).then(response => {
// Asset servers respond with {status: ok} for successful POSTs
if (response.status !== 'ok') {
// Errors include a `code` property, e.g. "Forbidden"
return Promise.reject(response.code);
}
asset.clean = true;
})
)
)
.then(() => this.props.onUpdateProjectData(projectId, savedVMState, requestParams))
return this.props.onUpdateProjectData(projectId, savedVMState, requestParams, this.props.reduxProjectTitle)
.then(response => {
this.props.onSetProjectUnchanged();
const id = response.id.toString();
Expand Down
15 changes: 10 additions & 5 deletions src/lib/save-project-to-server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import queryString from 'query-string';
import xhr from 'xhr';
import storage from '../lib/storage';
import { BASE_API_URL } from '../utils/constants';

/**
* Save a project JSON to the project server.
Expand All @@ -14,14 +15,18 @@ import storage from '../lib/storage';
* @property {?string} params.title the title of the project.
* @return {Promise} A promise that resolves when the network request resolves.
*/
export default function (projectId, vmState, params) {
export default function (projectId, vmState, params, projectTitle) {
const opts = {
body: vmState,
body: JSON.stringify({
file: vmState,
name: projectTitle,
}),
// If we set json:true then the body is double-stringified, so don't
// FIXME: pass token to authorization header
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
'Authorization': `Bearer 123`
},
withCredentials: true
};
const creatingProject = projectId === null || typeof projectId === 'undefined';
const queryParams = {};
Expand All @@ -39,7 +44,7 @@ export default function (projectId, vmState, params) {
} else {
Object.assign(opts, {
method: 'put',
url: `${storage.projectHost}/${projectId}${qs}`
url: `${BASE_API_URL}/projects/${projectId}`
});
}
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion src/playground/render-gui.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default appTarget => {
backpackVisible
showComingSoon
backpackHost={backpackHost}
canSave={false}
canSave={true}
onClickLogo={onClickLogo}
/>,
appTarget);
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const BASE_API_URL = "http://adventure-lab-cms.docker.amazee.io/md/api";