slate/scenes/ScenePublicProfile.js

78 lines
1.5 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 { css } from "@emotion/core";
2020-09-04 01:42:08 +03:00
import EmptyState from "~/components/core/EmptyState";
import SceneProfile from "~/scenes/SceneProfile";
const STYLES_LOADER = css`
display: flex;
align-items: center;
justify-content: center;
height: 90vh;
width: 100%;
`;
2020-09-04 01:42:08 +03:00
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
}
2020-09-12 10:46:27 +03:00
if (!prevProps.data) {
return null;
}
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 (
<div css={STYLES_LOADER}>
2020-09-04 01:42:08 +03:00
<LoaderSpinner />
</div>
2020-09-04 01:42:08 +03:00
);
}
2020-09-04 01:42:08 +03:00
return <SceneProfile {...this.props} data={this.state.profile} />;
}
}