Skip to content

Commit

Permalink
fix: #codio-16210 broken projects: no save, no reload
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyNikitin committed Nov 19, 2024
1 parent e9400f7 commit 23fb64c
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 277 deletions.
370 changes: 140 additions & 230 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@
"scratch-paint": "^2.2.151",
"scratch-render": "^1.0.233",
"scratch-render-fonts": "^1.0.2",
"scratch-storage": "codio/scratch-storage#develop",
"scratch-storage": "file:/media/user/BigL/codio/scratch-storage",
"scratch-svg-renderer": "^2.3.102",
"scratch-vm": "codio/scratch-vm#develop",
"scratch-vm": "file:/media/user/BigL/codio/scratch-vm",
"startaudiocontext": "^1.2.1",
"style-loader": "4.0.0",
"to-style": "^1.3.3",
Expand Down
24 changes: 13 additions & 11 deletions src/components/crash-message/crash-message.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,25 @@ 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>
{props.onReload && (
<button
className={styles.reloadButton}
onClick={props.onReload}
>
<FormattedMessage
defaultMessage="Reload"
description="Button to reload the page when page crashes"
id="gui.crashMessage.reload"
/>
</button>
)}
</Box>
</div>
);

CrashMessage.propTypes = {
eventId: PropTypes.string,
onReload: PropTypes.func.isRequired
onReload: PropTypes.func
};

export default CrashMessage;
8 changes: 4 additions & 4 deletions src/containers/error-boundary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ class ErrorBoundary extends React.Component {
}

handleReload () {
window.location.replace(window.location.origin + window.location.pathname);
// do nothing. maybe in the future create new default project.
// window.location.replace(window.location.origin + window.location.pathname);
return;
}

render () {
if (this.state.error) {
if (recommendedBrowser()) {
return (
<CrashMessageComponent
onReload={this.handleReload}
/>
<CrashMessageComponent />
);
}
return (<BrowserModalComponent
Expand Down
2 changes: 1 addition & 1 deletion src/containers/library-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ LibraryItem.propTypes = {
md5ext: PropTypes.string // 3.0 library format
})
),
id: PropTypes.number.isRequired,
id: PropTypes.string.isRequired,
insetIconURL: PropTypes.string,
internetConnectionRequired: PropTypes.bool,
isPlaying: PropTypes.bool,
Expand Down
32 changes: 6 additions & 26 deletions src/lib/project-saver-hoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ const ProjectSaverHOC = function (WrappedComponent) {
if (codio) {
codio.loaded()
.then(() => {
codio.subscribe('callSave', () => this.storeProjectToCodio());
codio.subscribe('callSave', () => this.storeProjectToCodio()
.catch(msg => {
/* eslint-disable-next-line no-console */
console.log(`error on save codio project: ${msg}`);
})
);
})
.fail(msg => {
/* eslint-disable-next-line no-console */
Expand Down Expand Up @@ -249,31 +254,6 @@ const ProjectSaverHOC = function (WrappedComponent) {
this.props.onSetProjectUnchanged();
});
}
saveCodioFile (data) {
return new Promise((resolve, reject) => {
const {codio} = window;
if (codio) {
codio.loaded()
.then(() => {
const saveFile = codio.getFileName();
window.codio.saveFile(saveFile, data)
.then(resolve)
.fail(msg => {
const err = `saveCodioFile - error saving scratch file: ${msg}`;
/* eslint-disable-next-line no-console */
console.log(err);
reject(new Error(err));
});
})
.fail(msg => {
const err = `codio loaded - error: ${msg}`;
/* eslint-disable-next-line no-console */
console.log(err);
reject(new Error(err));
});
}
});
}
/**
* storeProject:
* @param {number|string|undefined} projectId - defined value will PUT/update; undefined/null will POST/create
Expand Down
3 changes: 2 additions & 1 deletion test/unit/util/project-saver-hoc.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ describe('projectSaverHOC', () => {
expect(mockedShowCreatingAlert).not.toHaveBeenCalled();
});

test('if user saves, inline saving alert should show', () => {
// skipped due to not allowing empty projects (without targets) to save
test.skip('if user saves, inline saving alert should show', () => {
const mockedShowSavingAlert = jest.fn();
const Component = () => <div />;
const WrappedComponent = projectSaverHOC(Component);
Expand Down
8 changes: 6 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ const ScratchWebpackConfigBuilder = require('scratch-webpack-configuration');
const baseConfig = new ScratchWebpackConfigBuilder(
{
rootPath: path.resolve(__dirname),
enableReact: true,
shouldSplitChunks: false
enableReact: true
})
.setTarget('browserslist')
.merge({
Expand Down Expand Up @@ -64,6 +63,11 @@ const baseConfig = new ScratchWebpackConfigBuilder(
context: 'node_modules/scratch-vm/dist/web',
from: 'extension-worker.{js,js.map}',
noErrorOnMissing: true
},
{
context: 'node_modules/scratch-storage/dist/web/',
from: '**/*',
noErrorOnMissing: true
}
]
}));
Expand Down

0 comments on commit 23fb64c

Please sign in to comment.