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 { ...@@ -333,7 +333,7 @@ class MenuBar extends React.Component {
)} )}
</MenuSection> </MenuSection>
<MenuSection> <MenuSection>
<SBFileUploader> <SBFileUploader onUpdateProjectTitle={this.props.onUpdateProjectTitle}>
{(renderFileInput, loadProject) => ( {(renderFileInput, loadProject) => (
<MenuItem <MenuItem
onClick={loadProject} onClick={loadProject}
......
...@@ -79,10 +79,13 @@ class SBFileUploader extends React.Component { ...@@ -79,10 +79,13 @@ class SBFileUploader extends React.Component {
reader.readAsArrayBuffer(thisFileInput.files[0]); reader.readAsArrayBuffer(thisFileInput.files[0]);
// extract the title from the file and set it as current project title // extract the title from the file and set it as current project title
if (thisFileInput.files[0].name) { if (thisFileInput.files[0].name) {
const matches = thisFileInput.files[0].name.match(/^(.*)\.sb3$/); const matches = thisFileInput.files[0].name.match(/^(.*?)(\.sb[23]?)?$/);
if (matches) { if (matches) {
const truncatedProjectTitle = matches[1].substring(0, 100); 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 = { ...@@ -116,7 +119,8 @@ SBFileUploader.propTypes = {
loadingState: PropTypes.oneOf(LoadingStates), loadingState: PropTypes.oneOf(LoadingStates),
onLoadingFinished: PropTypes.func, onLoadingFinished: PropTypes.func,
onLoadingStarted: PropTypes.func, onLoadingStarted: PropTypes.func,
onSetProjectTitle: PropTypes.func, onSetReduxProjectTitle: PropTypes.func,
onUpdateProjectTitle: PropTypes.func,
vm: PropTypes.shape({ vm: PropTypes.shape({
loadProject: PropTypes.func loadProject: PropTypes.func
}) })
...@@ -131,7 +135,7 @@ const mapDispatchToProps = dispatch => ({ ...@@ -131,7 +135,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(onLoadedProject(loadingState)); dispatch(onLoadedProject(loadingState));
dispatch(closeLoadingProject()); dispatch(closeLoadingProject());
}, },
onSetProjectTitle: title => dispatch(setProjectTitle(title)), onSetReduxProjectTitle: title => dispatch(setProjectTitle(title)),
onLoadingStarted: () => { onLoadingStarted: () => {
dispatch(openLoadingProject()); dispatch(openLoadingProject());
dispatch(onProjectUploadStarted()); 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