slate/scenes/ScenePublicSlate.js

78 lines
1.6 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/react";
2020-09-04 01:42:08 +03:00
import EmptyState from "~/components/core/EmptyState";
import SceneSlate from "~/scenes/SceneSlate";
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 ScenePublicSlate extends React.Component {
state = {
slate: null,
};
componentDidMount = async () => {
await this.renderSlate();
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.renderSlate();
2020-09-04 01:42:08 +03:00
};
renderSlate = async () => {
for (let slate of this.props.viewer.slates) {
if (!this.props.data) {
this.props.onAction({
type: "NAVIGATE",
value: slate.id,
});
return;
}
2020-09-04 01:42:08 +03:00
if (slate.id === this.props.data.id) {
this.props.onAction({
type: "NAVIGATE",
value: this.props.data.id,
2020-10-02 02:44:22 +03:00
redirect: true,
2020-09-04 01:42:08 +03:00
});
return;
}
}
2020-09-04 01:42:08 +03:00
let slate = await Actions.getSerializedSlate({ id: this.props.data.id });
this.setState({ slate: slate.data });
};
render() {
if (!this.state.slate) {
return (
<div css={STYLES_LOADER}>
2020-09-04 01:42:08 +03:00
<LoaderSpinner />
</div>
2020-09-04 01:42:08 +03:00
);
}
return <SceneSlate {...this.props} current={this.state.slate} />;
}
}