slate/pages/_/profile.js

104 lines
3.1 KiB
JavaScript
Raw Normal View History

import * as React from "react";
import * as Constants from "~/common/constants";
2020-11-10 02:51:05 +03:00
import * as Strings from "~/common/strings";
import * as Events from "~/common/custom-events";
2020-11-30 08:24:22 +03:00
import { css } from "@emotion/react";
2021-01-06 02:09:59 +03:00
import { ButtonPrimary } from "~/components/system/components/Buttons";
2020-09-03 06:26:56 +03:00
import Profile from "~/components/core/Profile";
import WebsitePrototypeWrapper from "~/components/core/WebsitePrototypeWrapper";
2020-08-03 07:29:34 +03:00
import WebsitePrototypeHeader from "~/components/core/WebsitePrototypeHeader";
import WebsitePrototypeFooter from "~/components/core/WebsitePrototypeFooter";
2020-12-13 04:16:55 +03:00
import CTATransition from "~/components/core/CTATransition";
const DEFAULT_IMAGE =
"https://slate.textile.io/ipfs/bafkreiaow45dlq5xaydaeqocdxvffudibrzh2c6qandpqkb6t3ahbvh6re";
export const getServerSideProps = async (context) => {
return {
props: { ...context.query },
};
};
const STYLES_ROOT = css`
2020-11-01 21:40:03 +03:00
display: block;
grid-template-rows: auto 1fr auto;
2020-08-03 07:29:34 +03:00
text-align: center;
font-size: 1rem;
min-height: 100vh;
2020-12-11 05:59:17 +03:00
background-color: ${Constants.system.foreground};
2020-08-03 07:29:34 +03:00
`;
2020-08-25 00:15:51 +03:00
export default class ProfilePage extends React.Component {
2020-12-13 04:16:55 +03:00
state = {
visible: false,
2021-01-29 22:48:31 +03:00
page: null,
};
componentDidMount = () => {
window.onpopstate = this._handleBackForward;
if (!Strings.isEmpty(this.props.cid)) {
let files = this.props.creator.library[0]?.children || [];
let index = files.findIndex((object) => object.cid === this.props.cid);
if (index !== -1) {
Events.dispatchCustomEvent({
name: "slate-global-open-carousel",
detail: { index },
});
}
}
2021-01-29 22:48:31 +03:00
};
_handleBackForward = (e) => {
let page = window.history.state;
this.setState({ page });
Events.dispatchCustomEvent({ name: "slate-global-close-carousel", detail: {} });
2020-12-13 04:16:55 +03:00
};
render() {
const title = this.props.creator ? `${this.props.creator.username}` : "404";
const url = `https://slate.host/${title}`;
2020-08-22 08:45:50 +03:00
const description = this.props.creator.data.body;
const image = this.props.creator.data.photo;
2020-12-13 04:16:55 +03:00
const buttons = (
2021-01-06 02:09:59 +03:00
<ButtonPrimary onClick={() => this.setState({ visible: true })}>Follow</ButtonPrimary>
2020-12-13 04:16:55 +03:00
);
2020-11-10 02:51:05 +03:00
if (Strings.isEmpty(image)) {
image = DEFAULT_IMAGE;
}
return (
<WebsitePrototypeWrapper title={title} description={description} url={url} image={image}>
2020-11-05 21:31:48 +03:00
<WebsitePrototypeHeader />
<div css={STYLES_ROOT}>
2021-01-29 22:48:31 +03:00
<Profile
{...this.props}
tab={this.props.cid ? 0 : 1}
2021-01-29 22:48:31 +03:00
page={this.state.page}
buttons={buttons}
isOwner={false}
2021-02-05 16:10:50 +03:00
isAuthenticated={this.props.viewer !== null}
2021-01-29 22:48:31 +03:00
external
/>
</div>
2020-12-13 04:16:55 +03:00
{this.state.visible && (
<div>
<CTATransition
onClose={() => this.setState({ visible: false })}
viewer={this.props.viewer}
open={this.state.visible}
redirectURL={`/_${Strings.createQueryParams({
2020-12-19 08:25:50 +03:00
scene: "NAV_PROFILE",
2020-12-13 04:16:55 +03:00
user: this.props.creator.username,
})}`}
/>
</div>
)}
2020-11-05 21:31:48 +03:00
<WebsitePrototypeFooter />
</WebsitePrototypeWrapper>
);
}
}