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";
|
2020-08-27 09:03:30 +03:00
|
|
|
import { ProcessedText } from "~/components/system/components/Typography";
|
2020-09-13 03:00:58 +03:00
|
|
|
import { Alert } from "~/components/core/Alert";
|
2020-07-27 12:50:25 +03:00
|
|
|
|
|
|
|
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-08-23 07:14:27 +03:00
|
|
|
import Slate, { generateLayout } from "~/components/core/Slate";
|
2020-08-20 23:33:08 +03:00
|
|
|
import SlateMediaObject from "~/components/core/SlateMediaObject";
|
2020-08-02 09:41:18 +03:00
|
|
|
|
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-08-22 20:30:03 +03:00
|
|
|
max-width: 1660px;
|
2020-07-30 04:00:45 +03:00
|
|
|
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
|
|
|
|
2020-08-09 01:04:17 +03:00
|
|
|
@media (max-width: ${Constants.sizes.mobile}px) {
|
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-08-23 07:14:27 +03:00
|
|
|
state = {
|
|
|
|
layouts: this.props.slate.data.layouts
|
|
|
|
? this.props.slate.data.layouts
|
|
|
|
: { lg: generateLayout(this.props.slate.data.objects) },
|
|
|
|
};
|
|
|
|
|
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-09 11:08:46 +03:00
|
|
|
return {
|
|
|
|
id: each.id,
|
2020-08-21 10:42:29 +03:00
|
|
|
data: each,
|
2020-08-31 21:19:46 +03:00
|
|
|
editing: false,
|
2020-08-25 09:46:02 +03:00
|
|
|
component: (
|
|
|
|
<SlateMediaObject key={each.id} useImageFallback data={each} />
|
|
|
|
),
|
2020-08-09 11:08:46 +03:00
|
|
|
};
|
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-09-13 03:00:58 +03:00
|
|
|
const title = `${this.props.creator.username}/${this.props.slate.slatename}`;
|
2020-08-25 09:46:02 +03:00
|
|
|
const url = `https://slate.host/${this.props.creator.username}`;
|
2020-08-22 08:19:11 +03:00
|
|
|
const description = this.props.slate.data.body;
|
2020-07-27 12:50:25 +03:00
|
|
|
|
2020-09-08 08:08:10 +03:00
|
|
|
const { objects } = this.props.slate.data;
|
|
|
|
|
|
|
|
// TODO(jim): Takes the first image found
|
|
|
|
// but we want this to be a user choice.
|
2020-07-30 04:00:45 +03:00
|
|
|
let image;
|
2020-09-08 08:08:10 +03:00
|
|
|
for (let i = 0; i < objects.length; i++) {
|
|
|
|
if (objects[i].type && objects[i].type.startsWith("image/")) {
|
|
|
|
image = objects[i].url;
|
|
|
|
break;
|
2020-08-02 10:33:03 +03:00
|
|
|
}
|
2020-09-08 08:08:10 +03:00
|
|
|
}
|
2020-07-30 04:00:45 +03:00
|
|
|
|
2020-09-13 03:00:58 +03:00
|
|
|
const headerTitle = `${this.props.creator.username} / ${this.props.slate.slatename}`;
|
2020-09-08 03:40:49 +03:00
|
|
|
|
2020-07-27 12:50:25 +03:00
|
|
|
return (
|
2020-08-25 09:46:02 +03:00
|
|
|
<WebsitePrototypeWrapper
|
|
|
|
title={title}
|
|
|
|
description={description}
|
|
|
|
url={url}
|
|
|
|
image={image}
|
|
|
|
>
|
2020-07-27 12:50:25 +03:00
|
|
|
<div css={STYLES_ROOT}>
|
2020-09-08 03:40:49 +03:00
|
|
|
<WebsitePrototypeHeaderGeneric href={url} title={headerTitle}>
|
|
|
|
<ProcessedText text={this.props.slate.data.body} />
|
2020-08-24 03:28:51 +03:00
|
|
|
</WebsitePrototypeHeaderGeneric>
|
2020-09-13 03:00:58 +03:00
|
|
|
<Alert style={{ top: 0, width: "100%" }} />
|
2020-08-03 07:17:22 +03:00
|
|
|
<div css={STYLES_SLATE}>
|
2020-08-22 08:19:11 +03:00
|
|
|
<Slate
|
2020-08-31 21:19:46 +03:00
|
|
|
editing={false}
|
2020-08-23 07:14:27 +03:00
|
|
|
layouts={this.state.layouts}
|
2020-09-08 08:08:10 +03:00
|
|
|
items={objects}
|
2020-08-22 08:19:11 +03:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|