ScratchDesktopHOC manages project title, rather than wrapping with TitledHOC

This commit is contained in:
Ben Wheeler 2019-09-14 23:13:18 -04:00
parent de6a271311
commit f9e77bc508

View file

@ -36,8 +36,12 @@ const ScratchDesktopHOC = function (WrappedComponent) {
'handleSetTitleFromSave',
'handleStorageInit',
'handleTelemetryModalOptIn',
'handleTelemetryModalOptOut'
'handleTelemetryModalOptOut',
'handleUpdateProjectTitle'
]);
this.state = {
projectTitle: null
};
}
componentDidMount () {
ipcRenderer.on('setTitleFromSave', this.handleSetTitleFromSave);
@ -52,7 +56,7 @@ const ScratchDesktopHOC = function (WrappedComponent) {
ipcRenderer.send(event, metadata);
}
handleSetTitleFromSave (event, args) {
this.props.onUpdateProjectTitle(args.title);
this.handleUpdateProjectTitle(args.title);
}
handleStorageInit (storageInstance) {
storageInstance.addHelper(new ElectronStorageHelper(storageInstance));
@ -63,6 +67,9 @@ const ScratchDesktopHOC = function (WrappedComponent) {
handleTelemetryModalOptOut () {
ipcRenderer.send('setTelemetryDidOptIn', false);
}
handleUpdateProjectTitle (newTitle) {
this.setState({projectTitle: newTitle});
}
render () {
const shouldShowTelemetryModal = (typeof ipcRenderer.sendSync('getTelemetryDidOptIn') !== 'boolean');
return (<WrappedComponent
@ -74,15 +81,12 @@ const ScratchDesktopHOC = function (WrappedComponent) {
onStorageInit={this.handleStorageInit}
onTelemetryModalOptIn={this.handleTelemetryModalOptIn}
onTelemetryModalOptOut={this.handleTelemetryModalOptOut}
onUpdateProjectTitle={this.handleUpdateProjectTitle}
{...this.props}
/>);
}
}
ScratchDesktopComponent.propTypes = {
onUpdateProjectTitle: PropTypes.func
};
return ScratchDesktopComponent;
};
@ -91,8 +95,7 @@ const ScratchDesktopHOC = function (WrappedComponent) {
// ability to compose reducers.
const WrappedGui = compose(
AppStateHOC,
TitledHOC,
ScratchDesktopHOC // must come after `TitledHOC` so it has access to `onUpdateProjectTitle`
ScratchDesktopHOC
)(GUI);
ReactDOM.render(<WrappedGui />, appTarget);