Update title fetching

- rename HOC
- ste project title to title
This commit is contained in:
Thomas Weber committed 2020-09-19 15:19:39 -05:00
1 parent 259c53af16
commit 60652645ce
2 files changed
+12 -9

No files matched your search

@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import {connect} from 'react-redux';
import {getIsShowingWithId} from '../reducers/project-state';
import {setProjectTitle} from '../reducers/project-title';
const API_URL = 'https://trampoline.turbowarp.org/proxy/projects/$id';
@@ -15,8 +16,8 @@ const fetchProjectTitle = projectId => fetch(API_URL.replace('$id', projectId))
return '';
});
const TWTitleHOC = function (WrappedComponent) {
class TitleComponent extends React.Component {
const TWTitleFetcherHOC = function (WrappedComponent) {
class TitleFetcherComponent extends React.Component {
componentDidMount () {
this.initialTitle = document.title;
}
@@ -35,6 +36,7 @@ const TWTitleHOC = function (WrappedComponent) {
return;
}
document.title = `${title} - TurboWarp`;
this.props.onSetProjectTitle(title);
})
.catch(() => {
// ignore errors
@@ -61,9 +63,10 @@ const TWTitleHOC = function (WrappedComponent) {
);
}
}
TitleComponent.propTypes = {
TitleFetcherComponent.propTypes = {
isShowingWithId: PropTypes.bool,
projectId: PropTypes.string
projectId: PropTypes.string,
onSetProjectTitle: PropTypes.func
};
const mapStateToProps = state => {
const loadingState = state.scratchGui.projectState.loadingState;
@@ -73,14 +76,14 @@ const TWTitleHOC = function (WrappedComponent) {
};
};
const mapDispatchToProps = dispatch => ({
onSetProjectTitle: title => dispatch(setProjectTitle(title))
});
return connect(
mapStateToProps,
mapDispatchToProps
)(TitleComponent);
)(TitleFetcherComponent);
};
export {
TWTitleHOC as default
TWTitleFetcherHOC as default
};
+2 -2
View File
@@ -5,7 +5,7 @@ import {connect} from 'react-redux';
import {compose} from 'redux';
import AppStateHOC from '../lib/app-state-hoc.jsx';
import TWParserHOC from '../lib/tw-parser-hoc.jsx';
import TWTitleHOC from '../lib/tw-title-hoc.jsx';
import TWTitleFetcherHOC from '../lib/tw-title-fetcher-hoc.jsx';
import TWEditorWarningHOC from '../lib/tw-editor-warning-hoc.jsx';
import GUI from './render-gui.jsx';
@@ -75,7 +75,7 @@ const ConnectedInterface = connect(
const WrappedInterface = compose(
AppStateHOC,
TWParserHOC,
TWTitleHOC,
TWTitleFetcherHOC,
TWEditorWarningHOC
)(ConnectedInterface);