slate/components/core/Profile.js

312 lines
8.7 KiB
JavaScript
Raw Normal View History

import * as React from "react";
import * as Constants from "~/common/constants";
2020-09-27 23:11:04 +03:00
import * as Strings from "~/common/strings";
import { css } from "@emotion/core";
2020-09-03 00:08:32 +03:00
import { ProcessedText } from "~/components/system/components/Typography";
2020-10-02 02:44:22 +03:00
import SlatePreviewBlocks from "~/components/core/SlatePreviewBlock";
2020-11-05 00:44:28 +03:00
import SlatePreviewBlocksExternal from "~/components/core/SlatePreviewBlockExternal";
2020-11-13 01:27:50 +03:00
import CTATransition from "~/components/core/CTATransition";
2020-11-01 21:40:03 +03:00
const STYLES_PROFILE_INTERNAL = css`
width: 100%;
padding: 64px 0px 0px 0px;
overflow-wrap: break-word;
white-space: pre-wrap;
`;
const STYLES_PROFILE = css`
width: 100%;
padding: 64px 32px 0px 32px;
2020-11-01 21:40:03 +03:00
overflow-wrap: break-word;
white-space: pre-wrap;
flex-shrink: 0;
display: block;
@media (max-width: ${Constants.sizes.mobile}px) {
padding: 80px 24px 0px 24px;
}
`;
const STYLES_PROFILE_INFO = css`
display: flex;
line-height: 1.3;
2020-11-05 00:44:28 +03:00
width: 50%;
2020-11-01 21:40:03 +03:00
overflow-wrap: break-word;
white-space: pre-wrap;
2020-11-05 21:31:48 +03:00
@media (max-width: ${Constants.sizes.tablet}px) {
2020-11-05 00:44:28 +03:00
width: 100%;
}
2020-11-01 21:40:03 +03:00
`;
const STYLES_PROFILE_INFO_INTERNAL = css`
display: flex;
line-height: 1.3;
margin: 0 auto;
overflow-wrap: break-word;
white-space: pre-wrap;
`;
const STYLES_INFO_INTERNAL = css`
display: block;
2020-11-20 04:50:24 +03:00
width: 33.3%;
2020-11-01 21:40:03 +03:00
max-width: calc(100% - 104px);
text-align: left;
margin-bottom: 48px;
overflow-wrap: break-word;
white-space: pre-wrap;
@media (max-width: ${Constants.sizes.mobile}px) {
2020-11-20 05:02:45 +03:00
width: calc(100% - 64px);
2020-11-01 21:40:03 +03:00
}
`;
const STYLES_INFO = css`
display: block;
width: 100%;
max-width: calc(100% - 224px);
text-align: left;
margin-bottom: 48px;
overflow-wrap: break-word;
white-space: pre-wrap;
@media (max-width: ${Constants.sizes.mobile}px) {
max-width: calc(100% - 80px);
}
`;
const STYLES_PROFILE_IMAGE = css`
2020-09-10 06:28:48 +03:00
background-color: ${Constants.system.foreground};
background-size: cover;
background-position: 50% 50%;
2020-11-01 21:40:03 +03:00
width: 80px;
height: 80px;
flex-shrink: 0;
2020-09-05 04:40:23 +03:00
border-radius: 4px;
2020-11-17 10:12:35 +03:00
margin: 8px 24px 0 0;
2020-11-01 21:40:03 +03:00
@media (max-width: ${Constants.sizes.mobile}px) {
width: 64px;
height: 64px;
margin-right: 16px;
}
`;
const STYLES_NAME = css`
2020-11-17 10:12:35 +03:00
font-size: ${Constants.typescale.lvl3};
2020-11-01 21:40:03 +03:00
font-family: ${Constants.font.medium};
max-width: 100%;
font-weight: 400;
2020-11-17 10:12:35 +03:00
margin: 8px 24px 0px 0;
2020-11-01 21:40:03 +03:00
overflow-wrap: break-word;
white-space: pre-wrap;
2020-11-17 10:12:35 +03:00
color: ${Constants.system.black};
2020-11-01 21:40:03 +03:00
`;
const STYLES_NAME_INTERNAL = css`
font-size: ${Constants.typescale.lvl3};
2020-11-17 10:12:35 +03:00
font-family: ${Constants.font.semiBold};
2020-11-01 21:40:03 +03:00
max-width: 100%;
2020-11-17 10:12:35 +03:00
font-weight: 400;
margin: 8px 24px 0px 0;
2020-11-01 21:40:03 +03:00
overflow-wrap: break-word;
white-space: pre-wrap;
2020-11-17 10:12:35 +03:00
color: ${Constants.system.black};
@media (max-width: ${Constants.sizes.mobile}px) {
margin-bottom: 8px;
margin-right: 0;
}
2020-09-03 00:08:32 +03:00
`;
const STYLES_DESCRIPTION = css`
2020-11-17 10:12:35 +03:00
font-size: ${Constants.typescale.lvl0};
color: ${Constants.system.darkGray};
2020-09-03 00:08:32 +03:00
width: 100%;
2020-11-01 21:40:03 +03:00
overflow-wrap: break-word;
white-space: pre-wrap;
@media (max-width: ${Constants.sizes.mobile}px) {
margin-top: 24px;
}
`;
const STYLES_STATS = css`
font-size: ${Constants.typescale.lvl0};
2020-11-17 10:12:35 +03:00
margin: 16px 0 16px 0;
2020-11-01 21:40:03 +03:00
display: flex;
width: 100%;
2020-11-17 10:12:35 +03:00
color: ${Constants.system.grayBlack};
2020-11-01 21:40:03 +03:00
`;
const STYLES_STAT = css`
2020-11-17 10:12:35 +03:00
margin-right: 8px;
2020-11-01 21:40:03 +03:00
width: 112px;
flex-shrink: 0;
`;
2020-11-01 21:40:03 +03:00
const STYLES_BUTTON = css`
2020-11-17 10:12:35 +03:00
width: 96px;
height: 36px;
border-radius: 4px;
border: 1px solid ${Constants.system.gray};
padding: 8px 16px;
2020-11-01 21:40:03 +03:00
cursor: pointer;
2020-11-17 10:12:35 +03:00
margin-top: 8px;
font-family: ${Constants.font.medium};
2020-11-01 21:40:03 +03:00
font-weight: 400;
font-size: 14px;
text-align: center;
text-decoration: none;
2020-11-17 10:12:35 +03:00
color: ${Constants.system.black};
:hover {
background-color: ${Constants.system.gray};
transition: 200ms background-color linear;
}
2020-11-01 21:40:03 +03:00
:visited {
2020-11-17 10:12:35 +03:00
color: ${Constants.system.black};
2020-11-01 21:40:03 +03:00
}
`;
const STYLES_FLEX = css`
display: flex;
2020-11-17 10:12:35 +03:00
align-items: center;
2020-11-06 01:47:45 +03:00
flex-wrap: wrap;
2020-11-17 10:12:35 +03:00
`;
2020-11-08 05:36:29 +03:00
2020-11-17 10:12:35 +03:00
const STYLES_EXPLORE = css`
margin: 160px auto 64px auto;
height: 1px;
width: 80px;
background-color: ${Constants.system.gray};
`;
export default class Profile extends React.Component {
2020-11-13 01:27:50 +03:00
state = {
2020-11-17 10:12:35 +03:00
exploreSlates: [],
2020-11-13 01:27:50 +03:00
};
render() {
let data = this.props.creator ? this.props.creator : this.props.data;
2020-11-17 10:12:35 +03:00
let exploreSlates = this.props.exploreSlates;
2020-11-01 21:40:03 +03:00
let total = 0;
for (let slate of data.slates) {
total += slate.data.objects.length;
}
return (
2020-11-01 21:40:03 +03:00
<div>
{this.props.onAction ? (
<div css={STYLES_PROFILE_INFO_INTERNAL}>
<div
css={STYLES_PROFILE_IMAGE}
style={{ backgroundImage: `url('${data.data.photo}')` }}
/>
<div css={STYLES_INFO_INTERNAL}>
<div css={STYLES_FLEX}>
<div css={STYLES_NAME_INTERNAL}>{Strings.getPresentationName(data)}</div>
2020-11-06 01:33:00 +03:00
<div>{this.props.buttons}</div>
2020-11-01 21:40:03 +03:00
</div>
<div css={STYLES_STATS}>
<div css={STYLES_STAT}>
2020-11-17 10:12:35 +03:00
<div style={{ fontFamily: `${Constants.font.text}` }}>
{total}{" "}
<span style={{ color: `${Constants.system.darkGray}` }}>Public data</span>
</div>
2020-11-01 21:40:03 +03:00
</div>
<div css={STYLES_STAT}>
2020-11-17 10:12:35 +03:00
<div style={{ fontFamily: `${Constants.font.text}` }}>
{data.slates.length}{" "}
<span style={{ color: `${Constants.system.darkGray}` }}>Public slates</span>
</div>
2020-11-01 21:40:03 +03:00
</div>
</div>
2020-11-07 20:46:52 +03:00
{data.data.body ? (
<div css={STYLES_DESCRIPTION}>
<ProcessedText text={data.data.body} />
</div>
) : null}
2020-11-01 21:40:03 +03:00
</div>
</div>
) : (
<div css={STYLES_PROFILE}>
<div css={STYLES_PROFILE_INFO}>
<div
css={STYLES_PROFILE_IMAGE}
style={{ backgroundImage: `url('${data.data.photo}')` }}
/>
<div css={STYLES_INFO}>
<div css={STYLES_FLEX}>
<div css={STYLES_NAME}>{Strings.getPresentationName(data)}</div>
2020-11-17 10:12:35 +03:00
<a css={STYLES_BUTTON} href={"http://slate.host/_"}>
Follow
</a>
2020-11-01 21:40:03 +03:00
</div>
<div css={STYLES_STATS}>
<div css={STYLES_STAT}>
2020-11-17 10:12:35 +03:00
<div style={{ fontFamily: `${Constants.font.text}` }}>
{total}{" "}
<span style={{ color: `${Constants.system.darkGray}` }}>Public data</span>
</div>
2020-11-01 21:40:03 +03:00
</div>
<div css={STYLES_STAT}>
2020-11-17 10:12:35 +03:00
<div style={{ fontFamily: `${Constants.font.text}` }}>
{data.slates.length}{" "}
<span style={{ color: `${Constants.system.darkGray}` }}>Public slates</span>
2020-11-01 21:40:03 +03:00
</div>
</div>
</div>
2020-11-07 20:46:52 +03:00
{data.data.body ? (
<div css={STYLES_DESCRIPTION} style={{ marginBottom: 16 }}>
<ProcessedText text={data.data.body} />
</div>
) : null}
2020-11-01 21:40:03 +03:00
</div>
2020-09-03 00:08:32 +03:00
</div>
2020-11-01 21:40:03 +03:00
</div>
)}
2020-11-08 05:36:29 +03:00
2020-11-13 01:27:50 +03:00
{this.state.visible && (
<div>
<CTATransition
2020-11-17 06:17:56 +03:00
onClose={() => this.setState({ visible: false })}
viewer={this.props.viewer}
open={this.state.visible}
redirectURL={`/_?scene=V1_NAVIGATION_PROFILE&user=${data.username}`}
/>
2020-11-13 01:27:50 +03:00
</div>
)}
2020-11-01 21:40:03 +03:00
{this.props.onAction ? (
<div css={STYLES_PROFILE_INTERNAL} style={{ paddingTop: 0 }}>
{data.slates && data.slates.length ? (
<SlatePreviewBlocks
isOwner={this.props.isOwner}
external={this.props.onAction ? false : true}
slates={data.slates}
username={data.username}
onAction={this.props.onAction}
/>
) : null}
</div>
) : (
<div css={STYLES_PROFILE} style={{ paddingTop: 0 }}>
{data.slates && data.slates.length ? (
2020-11-05 00:44:28 +03:00
<SlatePreviewBlocksExternal
2020-11-01 21:40:03 +03:00
isOwner={this.props.isOwner}
slates={data.slates}
username={data.username}
onAction={this.props.onAction}
/>
2020-11-17 10:12:35 +03:00
) : (
<div>
{" "}
<p style={{ marginTop: 40, color: `${Constants.system.darkGray}` }}>
No publicly shared slates from @{data.username}.
</p>
<div css={STYLES_EXPLORE} />
<SlatePreviewBlocksExternal slates={exploreSlates} />
</div>
)}
2020-11-01 21:40:03 +03:00
</div>
)}
</div>
);
}
}