slate/components/core/Profile.js

301 lines
8.1 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";
2020-11-13 01:27:50 +03:00
import * as SVG from "~/common/svg";
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%;
2020-11-05 21:31:48 +03:00
padding: 64px 64px 0px 64px;
2020-11-01 21:40:03 +03:00
overflow-wrap: break-word;
white-space: pre-wrap;
flex-shrink: 0;
display: block;
2020-11-08 05:36:29 +03:00
2020-11-01 21:40:03 +03:00
@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-08 05:36:29 +03:00
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;
width: 100%;
max-width: calc(100% - 104px);
text-align: left;
margin-bottom: 48px;
overflow-wrap: break-word;
white-space: pre-wrap;
2020-11-08 05:36:29 +03:00
2020-11-01 21:40:03 +03:00
@media (max-width: ${Constants.sizes.mobile}px) {
max-width: calc(100% - 64px);
}
`;
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;
2020-11-08 05:36:29 +03:00
2020-11-01 21:40:03 +03:00
@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-01 21:40:03 +03:00
margin-right: 24px;
2020-11-08 05:36:29 +03:00
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-01 21:40:03 +03:00
font-size: ${Constants.typescale.lvl4};
font-family: ${Constants.font.medium};
max-width: 100%;
font-weight: 400;
margin-top: 8px;
margin-right: 24px;
overflow-wrap: break-word;
white-space: pre-wrap;
2020-11-08 05:36:29 +03:00
2020-11-01 21:40:03 +03:00
@media (max-width: ${Constants.sizes.mobile}px) {
2020-11-06 01:47:45 +03:00
margin-bottom: 8px;
2020-11-01 21:40:03 +03:00
margin-right: 0;
}
`;
const STYLES_NAME_INTERNAL = css`
font-size: ${Constants.typescale.lvl3};
2020-09-04 07:16:19 +03:00
font-family: ${Constants.font.medium};
2020-11-01 21:40:03 +03:00
font-weight: 400;
max-width: 100%;
margin-top: 8px;
overflow-wrap: break-word;
white-space: pre-wrap;
2020-09-03 00:08:32 +03:00
`;
const STYLES_DESCRIPTION = css`
font-size: ${Constants.typescale.lvl1};
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};
line-height: 1.5;
2020-11-06 01:33:00 +03:00
margin: 12px 0 24px 0;
2020-11-01 21:40:03 +03:00
display: flex;
width: 100%;
flex-wrap: wrap;
`;
const STYLES_STAT = css`
margin-right: 16px;
width: 112px;
flex-shrink: 0;
`;
2020-11-01 21:40:03 +03:00
const STYLES_BUTTON = css`
padding: 10px 24px;
cursor: pointer;
font-family: ${Constants.font.semiBold};
font-weight: 400;
font-size: 14px;
text-align: center;
text-decoration: none;
2020-11-01 21:40:03 +03:00
height: 40px;
width: 160px;
border-radius: 4px;
color: ${Constants.system.white};
background-color: ${Constants.system.brand};
2020-11-08 05:36:29 +03:00
2020-11-01 21:40:03 +03:00
:visited {
color: ${Constants.system.white};
}
`;
const STYLES_FLEX = css`
display: flex;
margin-bottom: 12px;
align-items: baseline;
2020-11-06 01:33:00 +03:00
justify-content: space-between;
2020-11-06 01:47:45 +03:00
flex-wrap: wrap;
2020-11-08 05:36:29 +03:00
2020-11-06 01:47:45 +03:00
@media (max-width: ${Constants.sizes.tablet}px) {
2020-11-01 21:40:03 +03:00
display: block;
}
`;
export default class Profile extends React.Component {
2020-11-13 01:27:50 +03:00
state = {
visible: false,
};
render() {
let data = this.props.creator ? this.props.creator : this.props.data;
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}>
<div style={{ color: `${Constants.system.darkGray}` }}>Public data</div>
<div style={{ fontFamily: `${Constants.font.medium}` }}>{total}</div>
</div>
<div css={STYLES_STAT}>
<div style={{ color: `${Constants.system.darkGray}` }}>Public slates</div>
<div style={{ fontFamily: `${Constants.font.medium}` }}>{data.slates.length}</div>
</div>
</div>
2020-11-06 01:33:00 +03:00
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-06 01:33:00 +03:00
<div css={STYLES_BUTTON}>
2020-11-13 01:27:50 +03:00
<a css={STYLES_BUTTON} onClick={() => this.setState({ visible: true })}>
2020-11-06 01:33:00 +03:00
Follow
</a>
</div>
2020-11-01 21:40:03 +03:00
</div>
<div css={STYLES_STATS}>
<div css={STYLES_STAT}>
<div style={{ color: `${Constants.system.darkGray}` }}>Public data</div>
<div style={{ fontFamily: `${Constants.font.medium}` }}>{total}</div>
</div>
<div css={STYLES_STAT}>
<div style={{ color: `${Constants.system.darkGray}` }}>Public slates</div>
<div style={{ fontFamily: `${Constants.font.medium}` }}>
{data.slates.length}
</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}
/>
) : null}
</div>
)}
</div>
);
}
}