will no longer be blank profile after fast refresh

This commit is contained in:
Martina 2021-01-28 16:57:02 -08:00
parent 5ab8f18870
commit e037edcc9a
2 changed files with 8 additions and 2 deletions

View File

@ -189,6 +189,7 @@ export default class ApplicationPage extends React.Component {
}; };
_handleUpdateData = ({ data }) => { _handleUpdateData = ({ data }) => {
//TODO(martina): maybe add a default window.history.replacestate where it pushes the new data to browser?
this.setState({ data }); this.setState({ data });
}; };

View File

@ -24,6 +24,7 @@ export default class SceneProfile extends React.Component {
}; };
componentDidMount = async () => { componentDidMount = async () => {
console.log("component did mount called");
await this.fetchProfile(); await this.fetchProfile();
}; };
@ -34,7 +35,7 @@ export default class SceneProfile extends React.Component {
}; };
fetchProfile = async () => { fetchProfile = async () => {
const username = this.props.page.user; const username = this.props.page.user || this.props.page.data?.username;
let query; let query;
let targetUser; let targetUser;
if (username) { if (username) {
@ -65,7 +66,11 @@ export default class SceneProfile extends React.Component {
targetUser = response.data; 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.props.onUpdateData({ data: targetUser });
this.setState({ profile: targetUser }); this.setState({ profile: targetUser });