From e037edcc9aae4fbd5c40232f62b0ead612f5cb1a Mon Sep 17 00:00:00 2001 From: Martina Date: Thu, 28 Jan 2021 16:57:02 -0800 Subject: [PATCH] will no longer be blank profile after fast refresh --- components/core/Application.js | 1 + scenes/SceneProfile.js | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/core/Application.js b/components/core/Application.js index 35827c40..ec8ec03c 100644 --- a/components/core/Application.js +++ b/components/core/Application.js @@ -189,6 +189,7 @@ export default class ApplicationPage extends React.Component { }; _handleUpdateData = ({ data }) => { + //TODO(martina): maybe add a default window.history.replacestate where it pushes the new data to browser? this.setState({ data }); }; diff --git a/scenes/SceneProfile.js b/scenes/SceneProfile.js index 0bf18cfe..d0386e1a 100644 --- a/scenes/SceneProfile.js +++ b/scenes/SceneProfile.js @@ -24,6 +24,7 @@ export default class SceneProfile extends React.Component { }; componentDidMount = async () => { + console.log("component did mount called"); await this.fetchProfile(); }; @@ -34,7 +35,7 @@ export default class SceneProfile extends React.Component { }; fetchProfile = async () => { - const username = this.props.page.user; + const username = this.props.page.user || this.props.page.data?.username; let query; let targetUser; if (username) { @@ -65,7 +66,11 @@ export default class SceneProfile extends React.Component { targetUser = response.data; } - window.history.replaceState(window.history.state, "A slate user", `/${targetUser.username}`); + window.history.replaceState( + { ...window.history.state, data: targetUser }, + "A slate user", + `/${targetUser.username}` + ); this.props.onUpdateData({ data: targetUser }); this.setState({ profile: targetUser });