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-09-14 03:34:58 +03:00
|
|
|
import * as Strings from "~/common/strings";
|
2020-10-05 00:30:28 +03:00
|
|
|
import * as Actions from "~/common/actions";
|
2020-07-27 12:50:25 +03:00
|
|
|
|
2020-11-04 20:55:48 +03:00
|
|
|
import { css } from "@emotion/core";
|
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-10-23 09:25:19 +03:00
|
|
|
import { ViewAllButton } from "~/components/core/ViewAll";
|
2020-07-27 12:50:25 +03:00
|
|
|
|
|
|
|
import WebsitePrototypeWrapper from "~/components/core/WebsitePrototypeWrapper";
|
2020-10-25 22:09:21 +03:00
|
|
|
import WebsitePrototypeHeader from "~/components/core/WebsitePrototypeHeader";
|
2020-08-03 07:17:22 +03:00
|
|
|
import WebsitePrototypeFooter from "~/components/core/WebsitePrototypeFooter";
|
2020-10-05 00:30:28 +03:00
|
|
|
import { SlateLayout } from "~/components/core/SlateLayout";
|
2020-10-24 22:55:19 +03:00
|
|
|
import { SlateLayoutMobile } from "~/components/core/SlateLayoutMobile";
|
2020-08-20 23:33:08 +03:00
|
|
|
import SlateMediaObject from "~/components/core/SlateMediaObject";
|
2020-08-02 09:41:18 +03:00
|
|
|
|
2020-10-05 00:30:28 +03:00
|
|
|
const SIZE_LIMIT = 1000000; //NOTE(martina): 1mb limit for twitter preview images
|
|
|
|
const DEFAULT_IMAGE = "";
|
|
|
|
|
2020-07-27 12:50:25 +03:00
|
|
|
const STYLES_ROOT = css`
|
2020-10-26 03:18:55 +03:00
|
|
|
display: block;
|
2020-08-03 07:17:22 +03:00
|
|
|
min-height: 100vh;
|
2020-10-23 08:56:20 +03:00
|
|
|
background-color: ${Constants.system.white};
|
2020-08-03 07:17:22 +03:00
|
|
|
`;
|
|
|
|
|
2020-10-26 03:18:55 +03:00
|
|
|
const STYLES_SLATE_INTRO = css`
|
|
|
|
display: flex;
|
2020-11-01 21:40:03 +03:00
|
|
|
padding: 32px 64px;
|
2020-10-26 03:18:55 +03:00
|
|
|
align-items: baseline;
|
|
|
|
line-height: 1.3;
|
2020-10-27 00:14:10 +03:00
|
|
|
word-wrap: break-word;
|
2020-10-26 03:18:55 +03:00
|
|
|
@media (max-width: ${Constants.sizes.mobile}px) {
|
2020-11-01 21:40:03 +03:00
|
|
|
padding: 32px 24px;
|
2020-10-26 03:18:55 +03:00
|
|
|
display: block;
|
|
|
|
font-size: 14px;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_CREATOR = css`
|
|
|
|
flex-shrink: 0;
|
|
|
|
margin-right: 4px;
|
|
|
|
text-decoration: none;
|
2020-10-26 22:46:37 +03:00
|
|
|
color: ${Constants.system.black};
|
2020-10-26 03:18:55 +03:00
|
|
|
:hover {
|
|
|
|
color: ${Constants.system.brand};
|
|
|
|
}
|
|
|
|
:visited {
|
|
|
|
color: ${Constants.system.black};
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_DESCTIPTION = css`
|
|
|
|
font-size: ${Constants.typescale.lvl1};
|
|
|
|
font-family: ${Constants.font.text};
|
|
|
|
width: 50%;
|
2020-10-27 00:14:10 +03:00
|
|
|
word-wrap: break-word;
|
2020-10-26 08:03:41 +03:00
|
|
|
@media (max-width: ${Constants.sizes.mobile}px) {
|
2020-11-01 21:40:03 +03:00
|
|
|
width: 100%;
|
2020-10-26 03:18:55 +03:00
|
|
|
margin-top: 4px;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_TITLE = css`
|
|
|
|
font-size: ${Constants.typescale.lvl3};
|
|
|
|
font-family: ${Constants.font.medium};
|
|
|
|
font-weight: 400;
|
|
|
|
color: ${Constants.system.black};
|
2020-10-26 22:46:37 +03:00
|
|
|
width: auto;
|
2020-10-27 00:14:10 +03:00
|
|
|
max-width: 100%;
|
2020-10-26 22:46:37 +03:00
|
|
|
margin-right: 24px;
|
2020-10-27 00:14:10 +03:00
|
|
|
word-wrap: break-word;
|
2020-10-26 03:18:55 +03:00
|
|
|
@media (max-width: ${Constants.sizes.mobile}px) {
|
2020-11-01 21:40:03 +03:00
|
|
|
font-size: ${Constants.typescale.lvl3};
|
2020-10-26 03:18:55 +03:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_FLEX = css`
|
|
|
|
display: flex;
|
2020-10-26 22:46:37 +03:00
|
|
|
margin-bottom: 12px;
|
2020-10-26 03:18:55 +03:00
|
|
|
@media (max-width: ${Constants.sizes.mobile}px) {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_STATS = css`
|
|
|
|
font-size: ${Constants.typescale.lvl0};
|
2020-10-26 22:46:37 +03:00
|
|
|
margin-top: 24px;
|
2020-10-26 03:18:55 +03:00
|
|
|
display: flex;
|
2020-10-26 22:46:37 +03:00
|
|
|
line-height: 1.5;
|
2020-10-26 03:18:55 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_STAT = css`
|
|
|
|
margin-right: 48px;
|
2020-11-01 21:40:03 +03:00
|
|
|
width: 88px;
|
2020-10-26 03:18:55 +03:00
|
|
|
${"" /* border-left: 1px solid ${Constants.system.darkGray};
|
|
|
|
padding-left: 12px; */};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_BUTTONS = css`
|
|
|
|
display: flex;
|
2020-10-26 22:46:37 +03:00
|
|
|
width: 200px;
|
|
|
|
height: 36px;
|
2020-10-26 03:18:55 +03:00
|
|
|
border-radius: 4px;
|
|
|
|
border: 1px solid ${Constants.system.gray};
|
2020-10-26 22:46:37 +03:00
|
|
|
flex-shrink: 0;
|
2020-10-26 03:18:55 +03:00
|
|
|
@media (max-width: ${Constants.sizes.mobile}px) {
|
|
|
|
margin: 12px 0;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_BUTTON = css`
|
|
|
|
border-right: 1px solid ${Constants.system.gray};
|
2020-10-26 22:46:37 +03:00
|
|
|
padding: 8px 4px;
|
2020-10-26 03:18:55 +03:00
|
|
|
cursor: pointer;
|
|
|
|
width: 50%;
|
|
|
|
font-family: ${Constants.font.medium};
|
|
|
|
font-weight: 400;
|
|
|
|
font-size: 14px;
|
|
|
|
text-align: center;
|
|
|
|
text-decoration: none;
|
2020-10-26 08:07:50 +03:00
|
|
|
color: ${Constants.system.black};
|
2020-10-26 03:18:55 +03:00
|
|
|
:last-child {
|
|
|
|
border-right: none;
|
|
|
|
}
|
|
|
|
:hover {
|
|
|
|
background-color: ${Constants.system.gray};
|
|
|
|
transition: 200ms background-color linear;
|
|
|
|
}
|
|
|
|
:visited {
|
|
|
|
color: ${Constants.system.black};
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2020-08-03 07:17:22 +03:00
|
|
|
const STYLES_SLATE = css`
|
2020-10-23 08:56:20 +03:00
|
|
|
padding: 0 64px 0 64px;
|
2020-10-22 01:54:01 +03:00
|
|
|
${"" /* max-width: 1660px; */}
|
2020-07-30 04:00:45 +03:00
|
|
|
display: block;
|
|
|
|
width: 100%;
|
2020-10-05 00:30:28 +03:00
|
|
|
margin: 48px auto 0 auto;
|
2020-08-03 07:17:22 +03:00
|
|
|
min-height: 10%;
|
|
|
|
height: 100%;
|
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-07-31 12:47:37 +03:00
|
|
|
componentDidMount() {
|
2020-07-31 13:05:29 +03:00
|
|
|
if (!this.props.slate) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-09-14 05:58:33 +03:00
|
|
|
let CIDMap = {};
|
2020-07-31 12:47:37 +03:00
|
|
|
System.dispatchCustomEvent({
|
|
|
|
name: "slate-global-create-carousel",
|
|
|
|
detail: {
|
2020-10-24 00:28:53 +03:00
|
|
|
carouselType: "slate",
|
2020-09-14 05:58:33 +03:00
|
|
|
slides: this.props.slate.data.objects.map((each, index) => {
|
2020-09-14 03:34:58 +03:00
|
|
|
// NOTE(jim):
|
|
|
|
// This is a hack to catch this undefined case I don't want to track down yet.
|
|
|
|
const url = each.url.replace("https://undefined", "https://");
|
|
|
|
const cid = Strings.getCIDFromIPFS(url);
|
2020-09-14 05:58:33 +03:00
|
|
|
CIDMap[cid] = index;
|
2020-09-14 03:34:58 +03:00
|
|
|
|
2020-08-09 11:08:46 +03:00
|
|
|
return {
|
2020-09-14 03:34:58 +03:00
|
|
|
cid,
|
2020-08-09 11:08:46 +03:00
|
|
|
id: each.id,
|
2020-08-21 10:42:29 +03:00
|
|
|
data: each,
|
2020-10-05 00:30:28 +03:00
|
|
|
isOwner: false,
|
2020-10-22 01:54:01 +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
|
|
|
}),
|
|
|
|
},
|
|
|
|
});
|
2020-09-14 05:58:33 +03:00
|
|
|
|
2020-09-14 06:14:23 +03:00
|
|
|
if (!Strings.isEmpty(this.props.cid)) {
|
2020-09-14 05:58:33 +03:00
|
|
|
const index = CIDMap[this.props.cid];
|
|
|
|
|
|
|
|
if (index || index === 0) {
|
|
|
|
System.dispatchCustomEvent({
|
|
|
|
name: "slate-global-open-carousel",
|
|
|
|
detail: {
|
|
|
|
index,
|
2020-10-05 00:30:28 +03:00
|
|
|
baseURL: `${this.props.creator.username}/${this.props.slate.slatename}`,
|
2020-09-14 05:58:33 +03:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-07-31 12:47:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_handleSelect = (index) =>
|
|
|
|
System.dispatchCustomEvent({
|
|
|
|
name: "slate-global-open-carousel",
|
2020-09-14 05:58:33 +03:00
|
|
|
detail: {
|
|
|
|
index,
|
|
|
|
baseURL: `${this.props.creator.username}/${this.props.slate.slatename}`,
|
|
|
|
},
|
2020-07-31 12:47:37 +03:00
|
|
|
});
|
|
|
|
|
2020-10-05 00:30:28 +03:00
|
|
|
_handleSave = async (layouts) => {
|
|
|
|
await Actions.updateSlate({
|
|
|
|
id: this.props.slate.id,
|
|
|
|
layoutOnly: true,
|
|
|
|
data: { layouts },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-07-27 12:50:25 +03:00
|
|
|
render() {
|
2020-09-14 06:14:23 +03:00
|
|
|
let title = `${this.props.creator.username}/${this.props.slate.slatename}`;
|
2020-10-05 00:30:28 +03:00
|
|
|
let url = `https://slate.host/${this.props.creator.username}/${this.props.slate.slatename}`;
|
2020-09-14 08:02:33 +03:00
|
|
|
let headerURL = `https://slate.host/${this.props.creator.username}`;
|
2020-07-27 12:50:25 +03:00
|
|
|
|
2020-10-05 00:30:28 +03:00
|
|
|
let { objects, layouts, body, preview } = this.props.slate.data;
|
|
|
|
|
|
|
|
let image = preview;
|
|
|
|
if (!image) {
|
|
|
|
for (let i = 0; i < objects.length; i++) {
|
|
|
|
if (
|
|
|
|
objects[i].type &&
|
|
|
|
objects[i].type.startsWith("image/") &&
|
|
|
|
(!objects[i].size || objects[i].size < SIZE_LIMIT)
|
|
|
|
) {
|
|
|
|
image = objects[i].url.replace("https://undefined", "https://");
|
|
|
|
break;
|
|
|
|
}
|
2020-08-02 10:33:03 +03:00
|
|
|
}
|
2020-09-08 08:08:10 +03:00
|
|
|
}
|
2020-10-05 00:30:28 +03:00
|
|
|
if (!image) {
|
|
|
|
image = DEFAULT_IMAGE;
|
|
|
|
}
|
2020-07-30 04:00:45 +03:00
|
|
|
|
2020-09-14 06:14:23 +03:00
|
|
|
if (!Strings.isEmpty(this.props.cid)) {
|
|
|
|
let object = objects.find((each) => {
|
|
|
|
const url = each.url.replace("https://undefined", "https://");
|
|
|
|
const cid = Strings.getCIDFromIPFS(url);
|
|
|
|
return cid === this.props.cid;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (object) {
|
|
|
|
title = !Strings.isEmpty(object.title) ? object.title : this.props.cid;
|
2020-10-22 01:54:01 +03:00
|
|
|
body = !Strings.isEmpty(object.body) ? Strings.elide(object.body) : `An object on ${url}`;
|
2020-09-14 06:14:23 +03:00
|
|
|
image = object.type.includes("image/") ? object.url : image;
|
|
|
|
url = `${url}/cid:${this.props.cid}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 03:18:55 +03:00
|
|
|
const slateCreator = `${this.props.creator.username} / `;
|
|
|
|
const slateTitle = `${this.props.slate.slatename}`;
|
2020-09-08 03:40:49 +03:00
|
|
|
|
2020-10-26 08:01:40 +03:00
|
|
|
const counts = objects.reduce((counts, { ownerId }) => {
|
|
|
|
counts[ownerId] = (counts[ownerId] || 0) + 1;
|
|
|
|
return counts;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
const contributorsCount = Object.keys(counts).length;
|
|
|
|
|
2020-07-27 12:50:25 +03:00
|
|
|
return (
|
2020-10-22 01:54:01 +03:00
|
|
|
<WebsitePrototypeWrapper title={title} description={body} url={url} image={image}>
|
2020-07-27 12:50:25 +03:00
|
|
|
<div css={STYLES_ROOT}>
|
2020-10-25 22:09:21 +03:00
|
|
|
<WebsitePrototypeHeader />
|
2020-10-26 03:18:55 +03:00
|
|
|
<div css={STYLES_SLATE_INTRO}>
|
|
|
|
<a css={STYLES_CREATOR} href={headerURL}>
|
|
|
|
{slateCreator}
|
|
|
|
</a>
|
|
|
|
<div css={STYLES_DESCTIPTION}>
|
|
|
|
<div css={STYLES_FLEX}>
|
|
|
|
<div css={STYLES_TITLE}>{slateTitle} </div>
|
|
|
|
<div css={STYLES_BUTTONS}>
|
|
|
|
<a css={STYLES_BUTTON} href={"http://slate.host/_"}>
|
|
|
|
Follow
|
|
|
|
</a>
|
|
|
|
<a css={STYLES_BUTTON} href={"http://slate.host/_"}>
|
|
|
|
Download
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<ViewAllButton fullText={this.props.slate.data.body} maxCharacter={208}>
|
|
|
|
<ProcessedText text={this.props.slate.data.body} />
|
|
|
|
</ViewAllButton>
|
2020-10-26 08:01:40 +03:00
|
|
|
<div css={STYLES_STATS}>
|
2020-10-26 03:18:55 +03:00
|
|
|
<div css={STYLES_STAT}>
|
2020-11-01 21:44:49 +03:00
|
|
|
<div style={{ color: `${Constants.system.darkGray}` }}>Data</div>
|
2020-10-26 22:46:37 +03:00
|
|
|
<div style={{ fontFamily: `${Constants.font.medium}` }}>
|
2020-10-26 08:01:40 +03:00
|
|
|
{this.props.slate.data.objects.length}
|
|
|
|
</div>
|
2020-10-26 03:18:55 +03:00
|
|
|
</div>
|
|
|
|
<div css={STYLES_STAT}>
|
2020-11-01 21:44:49 +03:00
|
|
|
<div style={{ color: `${Constants.system.darkGray}` }}>Contributors</div>
|
2020-10-26 22:46:37 +03:00
|
|
|
<div style={{ fontFamily: `${Constants.font.medium}` }}>{contributorsCount}</div>
|
2020-10-26 03:18:55 +03:00
|
|
|
</div>
|
2020-10-26 08:01:40 +03:00
|
|
|
{/* <div css={STYLES_STAT}>
|
2020-11-01 21:44:49 +03:00
|
|
|
<div style={{ color: `${Constants.system.darkGray}` }}>Followers</div>
|
2020-10-26 22:46:37 +03:00
|
|
|
<div style={{ fontFamily: `${Constants.font.medium}` }}>0</div>
|
2020-10-26 08:01:40 +03:00
|
|
|
</div> */}
|
|
|
|
</div>
|
2020-10-26 03:18:55 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-08-03 07:17:22 +03:00
|
|
|
<div css={STYLES_SLATE}>
|
2020-10-24 22:55:19 +03:00
|
|
|
{this.props.mobile ? (
|
|
|
|
<SlateLayoutMobile
|
|
|
|
isOwner={false}
|
|
|
|
items={objects}
|
|
|
|
fileNames={layouts && layouts.ver === "2.0" ? layouts.fileNames : false}
|
|
|
|
onSelect={this._handleSelect}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<SlateLayout
|
|
|
|
external
|
|
|
|
slateId={this.props.slate.id}
|
|
|
|
layout={layouts && layouts.ver === "2.0" ? layouts.layout : null}
|
|
|
|
onSaveLayout={this._handleSave}
|
|
|
|
isOwner={false}
|
|
|
|
fileNames={layouts && layouts.ver === "2.0" ? layouts.fileNames : false}
|
|
|
|
items={objects}
|
|
|
|
onSelect={this._handleSelect}
|
|
|
|
defaultLayout={layouts && layouts.ver === "2.0" ? layouts.defaultLayout : true}
|
|
|
|
/>
|
|
|
|
)}
|
2020-08-03 07:17:22 +03:00
|
|
|
</div>
|
2020-07-27 12:50:25 +03:00
|
|
|
</div>
|
2020-10-24 09:36:52 +03:00
|
|
|
<System.GlobalCarousel external current={this.props.slate} viewer={this.props.creator} />
|
2020-10-05 00:30:28 +03:00
|
|
|
<System.GlobalModal />
|
2020-10-26 03:18:55 +03:00
|
|
|
<WebsitePrototypeFooter />
|
2020-07-27 12:50:25 +03:00
|
|
|
</WebsitePrototypeWrapper>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|