Move window title management out of project meta fetcher

Window title will now update when using projects from files.
This commit is contained in:
Thomas Weber committed 2021-01-27 16:04:39 -06:00
1 parent b93b8a4b72
commit a138ef9663
3 files changed
+14 -7

No files matched your search

+4 -2
View File
@@ -34,13 +34,15 @@ const TitledHOC = function (WrappedComponent) {
if (this.props.isShowingWithoutId && prevProps.isAnyCreatingNewState) {
// reset title to default
const defaultProjectTitle = this.handleReceivedProjectTitle();
this.props.onUpdateProjectTitle(defaultProjectTitle);
// tw: inform callback whether this title is a default title like "Project"
this.props.onUpdateProjectTitle(defaultProjectTitle, true);
}
// if the projectTitle hasn't changed, but the reduxProjectTitle
// HAS changed, we need to report that change to the projectTitle's owner
if (this.props.reduxProjectTitle !== prevProps.reduxProjectTitle &&
this.props.reduxProjectTitle !== this.props.projectTitle) {
this.props.onUpdateProjectTitle(this.props.reduxProjectTitle);
// tw: inform callback whether this title is a default title like "Project"
this.props.onUpdateProjectTitle(this.props.reduxProjectTitle, false);
}
}
handleReceivedProjectTitle (requestedTitle) {
-5
View File
@@ -18,9 +18,6 @@ const fetchProjectMeta = projectId => fetch(API_URL.replace('$id', projectId))
const TWProjectMetaFetcherHOC = function (WrappedComponent) {
class ProjectMetaFetcherComponent extends React.Component {
componentDidMount () {
this.initialTitle = document.title;
}
shouldComponentUpdate (nextProps) {
return this.props.projectId !== nextProps.projectId;
}
@@ -29,7 +26,6 @@ const TWProjectMetaFetcherHOC = function (WrappedComponent) {
this.props.onSetAuthor('', '');
this.props.onSetDescription('', '');
const projectId = this.props.projectId;
document.title = this.initialTitle;
// Don't try to load metadata for empty projects.
if (projectId === '0') {
return;
@@ -42,7 +38,6 @@ const TWProjectMetaFetcherHOC = function (WrappedComponent) {
}
const title = data.title;
if (title) {
document.title = `${title} - TurboWarp`;
this.props.onSetProjectTitle(title);
}
const authorName = data.author.username;
+10
View File
@@ -68,6 +68,15 @@ const handleLoadAddons = () => {
import(/* webpackChunkName: "addons" */ '../addons/entry');
};
const initialTitle = document.title;
const handleUpdateProjectTitle = (title, isDefault) => {
if (isDefault) {
document.title = initialTitle;
} else {
document.title = `${title} - TurboWarp`;
}
};
const WrappedMenuBar = compose(
SBFileUploaderHOC
)(MenuBar);
@@ -96,6 +105,7 @@ const Interface = ({
<GUI
onClickAddonSettings={handleClickAddonSettings}
onLoadAddons={handleLoadAddons}
onUpdateProjectTitle={handleUpdateProjectTitle}
onClickTheme={onClickTheme}
/>
{isHomepage ? (