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

POC: load project into editor when app starts #2

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
.then(response => {
this.props.onSetProjectUnchanged();
const id = response.id.toString();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/save-project-to-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function (projectId, vmState, params) {
headers: {
'Content-Type': 'application/json'
},
withCredentials: true
withCredentials: false // FIXME: check if this should be true
};
const creatingProject = projectId === null || typeof projectId === 'undefined';
const queryParams = {};
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