Skip to content
Snippets Groups Projects
Commit 33f5aaf3 authored by Ben Wheeler's avatar Ben Wheeler
Browse files

sb-file-uploader gets title of any Scratch file; calls onUpdateProjectTitle

parent 20b43aac
No related branches found
No related tags found
No related merge requests found
......@@ -333,7 +333,7 @@ class MenuBar extends React.Component {
)}
</MenuSection>
<MenuSection>
<SBFileUploader>
<SBFileUploader onUpdateProjectTitle={this.props.onUpdateProjectTitle}>
{(renderFileInput, loadProject) => (
<MenuItem
onClick={loadProject}
......
......@@ -79,10 +79,13 @@ class SBFileUploader extends React.Component {
reader.readAsArrayBuffer(thisFileInput.files[0]);
// extract the title from the file and set it as current project title
if (thisFileInput.files[0].name) {
const matches = thisFileInput.files[0].name.match(/^(.*)\.sb3$/);
const matches = thisFileInput.files[0].name.match(/^(.*?)(\.sb[23]?)?$/);
if (matches) {
const truncatedProjectTitle = matches[1].substring(0, 100);
this.props.onSetProjectTitle(truncatedProjectTitle);
this.props.onSetReduxProjectTitle(truncatedProjectTitle);
if (this.props.onUpdateProjectTitle) {
this.props.onUpdateProjectTitle(truncatedProjectTitle);
}
}
}
}
......@@ -116,7 +119,8 @@ SBFileUploader.propTypes = {
loadingState: PropTypes.oneOf(LoadingStates),
onLoadingFinished: PropTypes.func,
onLoadingStarted: PropTypes.func,
onSetProjectTitle: PropTypes.func,
onSetReduxProjectTitle: PropTypes.func,
onUpdateProjectTitle: PropTypes.func,
vm: PropTypes.shape({
loadProject: PropTypes.func
})
......@@ -131,7 +135,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(onLoadedProject(loadingState));
dispatch(closeLoadingProject());
},
onSetProjectTitle: title => dispatch(setProjectTitle(title)),
onSetReduxProjectTitle: title => dispatch(setProjectTitle(title)),
onLoadingStarted: () => {
dispatch(openLoadingProject());
dispatch(onProjectUploadStarted());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment