2020-07-27 12:50:25 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Constants from "~/common/constants";
|
2020-07-30 04:00:45 +03:00
|
|
|
import * as System from "~/components/system";
|
2020-07-27 12:50:25 +03:00
|
|
|
|
|
|
|
import { css } from "@emotion/react";
|
|
|
|
|
|
|
|
import WebsitePrototypeWrapper from "~/components/core/WebsitePrototypeWrapper";
|
2020-07-30 04:00:45 +03:00
|
|
|
import Slate from "~/components/core/Slate";
|
2020-07-27 12:50:25 +03:00
|
|
|
|
2020-08-02 09:41:18 +03:00
|
|
|
import MediaObject from "~/components/core/MediaObject";
|
|
|
|
|
2020-07-27 12:50:25 +03:00
|
|
|
const STYLES_ROOT = css`
|
|
|
|
padding: 128px 88px 256px 88px;
|
2020-07-30 04:00:45 +03:00
|
|
|
max-width: 1328px;
|
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
margin: 0 auto 0 auto;
|
2020-07-27 12:50:25 +03:00
|
|
|
|
|
|
|
@media (max-width: 768px) {
|
|
|
|
padding: 128px 24px 128px 24px;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2020-07-31 12:47:37 +03:00
|
|
|
export const getServerSideProps = async (context) => {
|
|
|
|
return {
|
|
|
|
props: { ...context.query },
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-07-27 12:50:25 +03:00
|
|
|
export default class SlatePage extends React.Component {
|
2020-07-31 12:47:37 +03:00
|
|
|
componentDidMount() {
|
2020-07-31 13:05:29 +03:00
|
|
|
if (!this.props.slate) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-07-31 12:47:37 +03:00
|
|
|
System.dispatchCustomEvent({
|
|
|
|
name: "slate-global-create-carousel",
|
|
|
|
detail: {
|
|
|
|
slides: this.props.slate.data.objects.map((each) => {
|
2020-08-02 09:41:18 +03:00
|
|
|
return <MediaObject useImageFallback data={each} />;
|
2020-07-31 12:47:37 +03:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_handleSelect = (index) =>
|
|
|
|
System.dispatchCustomEvent({
|
|
|
|
name: "slate-global-open-carousel",
|
|
|
|
detail: { index },
|
|
|
|
});
|
|
|
|
|
2020-07-27 12:50:25 +03:00
|
|
|
render() {
|
2020-08-02 01:46:54 +03:00
|
|
|
const title = this.props.slate ? `@${this.props.slate.ownername}/${this.props.slate.slatename}` : "404";
|
2020-07-27 12:50:25 +03:00
|
|
|
const url = `https://slate.host/${title}`;
|
|
|
|
const description = "A slate.";
|
|
|
|
|
2020-07-30 04:00:45 +03:00
|
|
|
let image;
|
|
|
|
if (this.props.slate.data.objects.length) {
|
|
|
|
image = this.props.slate.data.objects[0].url;
|
|
|
|
}
|
|
|
|
|
2020-07-27 12:50:25 +03:00
|
|
|
return (
|
2020-08-02 01:46:54 +03:00
|
|
|
<WebsitePrototypeWrapper title={title} description={description} url={url} image={image}>
|
2020-07-27 12:50:25 +03:00
|
|
|
<div css={STYLES_ROOT}>
|
2020-08-02 01:46:54 +03:00
|
|
|
<Slate items={this.props.slate.data.objects} onSelect={this._handleSelect} />
|
2020-07-27 12:50:25 +03:00
|
|
|
</div>
|
2020-07-31 12:47:37 +03:00
|
|
|
<System.GlobalCarousel />
|
2020-07-27 12:50:25 +03:00
|
|
|
</WebsitePrototypeWrapper>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|