import * as React from "react";
import * as System from "~/components/system";
import * as Actions from "~/common/actions";
import * as Validations from "~/common/validations";
import * as Constants from "~/common/constants";
import * as SVG from "~/common/svg";
import * as Strings from "~/common/strings";
import * as UserBehaviors from "~/common/user-behaviors";
import * as Events from "~/common/custom-events";
import { Link } from "~/components/core/Link";
import { LoaderSpinner } from "~/components/system/components/Loaders";
import { css } from "@emotion/react";
import { SlateLayout } from "~/components/core/SlateLayout";
import { SlateLayoutMobile } from "~/components/core/SlateLayoutMobile";
import { FileTypeGroup } from "~/components/core/FileTypeIcon";
import { ButtonPrimary, ButtonSecondary } from "~/components/system/components/Buttons";
import { GlobalCarousel } from "~/components/system/components/GlobalCarousel";
import WebsitePrototypeWrapper from "~/components/core/WebsitePrototypeWrapper";
import ProcessedText from "~/components/core/ProcessedText";
import ScenePage from "~/components/core/ScenePage";
import ScenePageHeader from "~/components/core/ScenePageHeader";
import SquareButtonGray from "~/components/core/SquareButtonGray";
import EmptyState from "~/components/core/EmptyState";
const STYLES_LOADER = css`
display: flex;
align-items: center;
justify-content: center;
height: 90vh;
width: 100%;
`;
const STYLES_COPY_INPUT = css`
pointer-events: none;
position: absolute;
opacity: 0;
`;
const STYLES_USERNAME = css`
cursor: pointer;
:hover {
color: ${Constants.system.brand};
}
`;
const STYLES_MOBILE_HIDDEN = css`
@media (max-width: ${Constants.sizes.mobile}px) {
display: none;
}
`;
const STYLES_MOBILE_ONLY = css`
@media (min-width: ${Constants.sizes.mobile}px) {
display: none;
}
`;
export default class SceneSlate extends React.Component {
state = {
loading: true,
notFound: false,
accessDenied: false,
};
// componentDidMount = async () => {
// if (this.props.data) {
// this.openCarouselToItem();
// }
// };
// componentDidUpdate = async (prevProps) => {
// // if (!this.props.data?.objects && !this.state.notFound) {
// // await this.fetchSlate();
// // } else
// if (this.props.data !== prevProps.data || this.props.page.params !== prevProps.page.params) {
// this.openCarouselToItem();
// }
// };
// fetchSlate = async () => {
// const { username, slatename, slateId } = this.props.page;
// if (!this.props.data && (!username || !slatename)) {
// this.setState({ notFound: true });
// return;
// }
// let id = slateId || this.props.data?.id;
// //NOTE(martina): look for the slate in the user's slates
// let slate;
// if (this.props.viewer) {
// if (id) {
// for (let s of this.props.viewer.slates) {
// if (id && id === s.id) {
// slate = s;
// break;
// }
// }
// } else if (slatename && username === this.props.viewer.username) {
// for (let s of this.props.viewer.slates) {
// if (username && slatename === s.slatename) {
// slate = s;
// break;
// }
// }
// if (!slate) {
// Events.dispatchMessage({
// message: "We're having trouble fetching that slate right now.",
// });
// this.setState({ notFound: true });
// return;
// }
// }
// if (slate) {
// window.history.replaceState(
// { ...window.history.state, data: slate },
// "Slate",
// `/${this.props.viewer.username}/${slate.slatename}`
// );
// }
// }
// if (!slate) {
// let query;
// if (username && slatename) {
// query = { username, slatename };
// } else if (id) {
// query = { id };
// }
// let response;
// if (query) {
// response = await Actions.getSerializedSlate(query);
// }
// if (response?.decorator == "SLATE_PRIVATE_ACCESS_DENIED") {
// this.setState({ accessDenied: true, loading: false });
// return;
// }
// if (Events.hasError(response)) {
// this.setState({ notFound: true, loading: false });
// return;
// }
// slate = response.slate;
// window.history.replaceState(
// { ...window.history.state, data: slate },
// "Slate",
// `/${slate.user.username}/${slate.slatename}`
// );
// }
// this.props.onUpdateData(slate, () => {
// this.setState({ loading: false });
// this.openCarouselToItem();
// });
// };
// openCarouselToItem = () => {
// if (!this.props.data?.objects?.length || !this.props.page?.params) {
// return;
// }
// let objects = this.props.data.objects;
// const { cid, fileId, index } = this.props.page.params;
// if (Strings.isEmpty(cid) && Strings.isEmpty(fileId) && typeof index === "undefined") {
// return;
// }
// let foundIndex = -1;
// if (index) {
// foundIndex = index;
// } else if (cid) {
// foundIndex = objects.findIndex((object) => object.cid === cid);
// } else if (fileId) {
// foundIndex = objects.findIndex((object) => object.id === fileId);
// }
// if (typeof foundIndex !== "undefined" && foundIndex !== -1) {
// Events.dispatchCustomEvent({
// name: "slate-global-open-carousel",
// detail: { index: foundIndex },
// });
// }
// };
render() {
const slate = this.props.data;
if (!slate) {
return (