slate/scenes/ScenePublicProfile.js

65 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-09-04 01:42:08 +03:00
import * as React from "react";
import * as Actions from "~/common/actions";
import { LoaderSpinner } from "~/components/system/components/Loaders";
import EmptyState from "~/components/core/EmptyState";
import SceneProfile from "~/scenes/SceneProfile";
export default class ScenePublicProfile extends React.Component {
state = {
profile: null,
};
componentDidMount = async () => {
await this.renderProfile();
2020-09-04 01:42:08 +03:00
};
componentDidUpdate = async (prevProps) => {
if (!this.props.data) {
return null;
2020-09-04 01:42:08 +03:00
}
if (this.props.data.id === prevProps.data.id) {
return null;
}
await this.renderProfile();
2020-09-04 01:42:08 +03:00
};
renderProfile = async () => {
let id;
if (this.props.data && this.props.data.id) {
id = this.props.data.id;
}
if (!id && this.props.viewer.id) {
id = this.props.viewer.id;
}
if (id === this.props.viewer.id) {
2020-09-04 01:42:08 +03:00
this.setState({ profile: this.props.viewer });
return;
}
2020-09-04 01:42:08 +03:00
let profile = await Actions.getSerializedProfile({
id: id,
2020-09-04 01:42:08 +03:00
});
2020-09-04 01:42:08 +03:00
this.setState({ profile: profile.data });
};
render() {
if (!this.state.profile) {
return (
<EmptyState style={{ marginTop: "88px" }}>
<LoaderSpinner />
</EmptyState>
);
}
2020-09-04 01:42:08 +03:00
return <SceneProfile {...this.props} data={this.state.profile} />;
}
}