slate/pages/_/slate.js

101 lines
2.5 KiB
JavaScript
Raw Normal View History

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-08-03 07:17:22 +03:00
import WebsitePrototypeHeaderGeneric from "~/components/core/WebsitePrototypeHeaderGeneric";
import WebsitePrototypeFooter from "~/components/core/WebsitePrototypeFooter";
2020-07-30 04:00:45 +03:00
import Slate from "~/components/core/Slate";
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`
2020-08-03 07:17:22 +03:00
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
min-height: 100vh;
text-align: center;
font-size: 1rem;
`;
const STYLES_SLATE = css`
padding: 0 88px 0 88px;
2020-07-30 04:00:45 +03:00
max-width: 1328px;
display: block;
width: 100%;
margin: 0 auto 0 auto;
2020-08-03 07:17:22 +03:00
min-height: 10%;
height: 100%;
2020-07-27 12:50:25 +03:00
@media (max-width: 768px) {
2020-08-03 07:17:22 +03:00
padding: 0 24px 0 24px;
2020-07-27 12:50:25 +03:00
}
`;
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() {
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) => {
return <MediaObject key={each.id} 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() {
const title = `${this.props.slate.ownername}/${this.props.slate.slatename}`;
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;
this.props.slate.data.objects.forEach((o) => {
if (o.type && o.type.startsWith("image/")) {
image = o.url;
}
});
2020-07-30 04:00:45 +03:00
2020-07-27 12:50:25 +03:00
return (
<WebsitePrototypeWrapper
title={title}
description={description}
url={url}
image={image}
>
2020-07-27 12:50:25 +03:00
<div css={STYLES_ROOT}>
<WebsitePrototypeHeaderGeneric>
{this.props.slate.ownername}
</WebsitePrototypeHeaderGeneric>
2020-08-03 07:17:22 +03:00
<div css={STYLES_SLATE}>
<Slate
items={this.props.slate.data.objects}
onSelect={this._handleSelect}
/>
2020-08-03 07:17:22 +03:00
</div>
2020-08-03 19:44:25 +03:00
<WebsitePrototypeFooter style={{ marginTop: 88 }} />
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>
);
}
}