2020-08-09 11:08:46 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Actions from "~/common/actions";
|
|
|
|
import * as Constants from "~/common/constants";
|
|
|
|
import * as System from "~/components/system";
|
2020-08-26 07:41:05 +03:00
|
|
|
import * as Strings from "~/common/strings";
|
2020-11-11 04:44:21 +03:00
|
|
|
import * as Validations from "~/common/validations";
|
2020-11-28 07:39:01 +03:00
|
|
|
import * as Events from "~/common/custom-events";
|
2020-12-11 05:59:17 +03:00
|
|
|
import * as SVG from "~/common/svg";
|
2020-08-09 11:08:46 +03:00
|
|
|
|
2020-12-11 05:59:17 +03:00
|
|
|
import { RadioGroup } from "~/components/system/components/RadioGroup";
|
2020-11-30 08:24:22 +03:00
|
|
|
import { css } from "@emotion/react";
|
2020-10-05 00:30:28 +03:00
|
|
|
|
|
|
|
const SIZE_LIMIT = 1000000;
|
2020-11-10 03:03:04 +03:00
|
|
|
const DEFAULT_IMAGE =
|
|
|
|
"https://slate.textile.io/ipfs/bafkreiaow45dlq5xaydaeqocdxvffudibrzh2c6qandpqkb6t3ahbvh6re";
|
2020-08-09 11:08:46 +03:00
|
|
|
|
2020-09-10 06:28:48 +03:00
|
|
|
const STYLES_HEADER = css`
|
|
|
|
font-family: ${Constants.font.semiBold};
|
2020-10-05 00:30:28 +03:00
|
|
|
`;
|
|
|
|
|
2020-12-11 05:59:17 +03:00
|
|
|
const STYLES_TEXT = css`
|
|
|
|
color: ${Constants.system.textGray};
|
|
|
|
font-size: ${Constants.typescale.lvl0};
|
|
|
|
`;
|
|
|
|
|
2020-10-05 00:30:28 +03:00
|
|
|
const STYLES_IMAGE_BOX = css`
|
|
|
|
max-width: 368px;
|
|
|
|
max-height: 368px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
background-color: ${Constants.system.white};
|
|
|
|
overflow: hidden;
|
|
|
|
border-radius: 4px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_GROUPING = css`
|
|
|
|
width: 100%;
|
|
|
|
border: 1px solid rgba(196, 196, 196, 0.5);
|
2020-12-11 05:59:17 +03:00
|
|
|
background-color: ${Constants.system.white};
|
2020-10-05 00:30:28 +03:00
|
|
|
border-radius: 6px;
|
|
|
|
padding: 16px;
|
|
|
|
margin-bottom: 24px;
|
2020-09-10 06:28:48 +03:00
|
|
|
`;
|
|
|
|
|
2020-08-09 11:08:46 +03:00
|
|
|
export default class SidebarSingleSlateSettings extends React.Component {
|
|
|
|
state = {
|
2020-09-03 03:35:41 +03:00
|
|
|
slatename: this.props.current.slatename,
|
|
|
|
public: this.props.current.data.public,
|
|
|
|
body: this.props.current.data.body,
|
|
|
|
name: this.props.current.data.name,
|
2020-08-09 11:08:46 +03:00
|
|
|
loading: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleSubmit = async () => {
|
2020-12-15 04:43:16 +03:00
|
|
|
// this.setState({ loading: true });
|
|
|
|
|
|
|
|
let slates = this.props.viewer.slates;
|
|
|
|
for (let slate of slates) {
|
|
|
|
if (slate.id === this.props.current.id) {
|
|
|
|
slate.data.name = this.state.name;
|
|
|
|
slate.data.public = this.state.public;
|
|
|
|
slate.data.body = this.state.body;
|
|
|
|
this.props.onUpdateViewer({ slates });
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-08-09 11:08:46 +03:00
|
|
|
|
2020-12-15 04:43:16 +03:00
|
|
|
this.props.onCancel();
|
2020-08-09 11:08:46 +03:00
|
|
|
const response = await Actions.updateSlate({
|
2020-09-03 03:35:41 +03:00
|
|
|
id: this.props.current.id,
|
2020-08-09 11:08:46 +03:00
|
|
|
data: {
|
2020-08-26 07:41:05 +03:00
|
|
|
name: this.state.name,
|
2020-08-09 11:08:46 +03:00
|
|
|
public: this.state.public,
|
2020-08-22 08:19:11 +03:00
|
|
|
body: this.state.body,
|
2020-08-09 11:08:46 +03:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-11-28 07:39:01 +03:00
|
|
|
if (Events.hasError(response)) {
|
2020-12-15 04:43:16 +03:00
|
|
|
// this.setState({ loading: false });
|
2020-11-28 07:39:01 +03:00
|
|
|
return;
|
2020-08-09 11:08:46 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleCancel = () => {
|
|
|
|
this.props.onCancel();
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleChange = (e) => {
|
|
|
|
this.setState({ [e.target.name]: e.target.value });
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleDelete = async (e) => {
|
2020-12-18 05:59:41 +03:00
|
|
|
// this.setState({ loading: true });
|
2020-08-09 11:08:46 +03:00
|
|
|
|
2020-08-26 07:41:05 +03:00
|
|
|
if (
|
2020-10-31 02:12:20 +03:00
|
|
|
!window.confirm("Are you sure you want to delete this Slate? This action is irreversible.")
|
2020-08-26 07:41:05 +03:00
|
|
|
) {
|
2020-12-18 05:59:41 +03:00
|
|
|
return;
|
|
|
|
// return this.setState({ loading: false });
|
2020-08-09 11:08:46 +03:00
|
|
|
}
|
|
|
|
|
2020-12-18 05:59:41 +03:00
|
|
|
let slates = this.props.viewer.slates.filter((slate) => slate.id !== this.props.current.id);
|
|
|
|
this.props.onUpdateViewer({ slates });
|
|
|
|
|
|
|
|
this.props.onAction({
|
|
|
|
type: "NAVIGATE",
|
2020-12-19 08:25:50 +03:00
|
|
|
value: "NAV_SLATES",
|
2020-12-18 05:59:41 +03:00
|
|
|
});
|
|
|
|
|
2020-08-09 11:08:46 +03:00
|
|
|
const response = await Actions.deleteSlate({
|
2020-09-03 03:35:41 +03:00
|
|
|
id: this.props.current.id,
|
2020-08-09 11:08:46 +03:00
|
|
|
});
|
|
|
|
|
2020-11-28 07:39:01 +03:00
|
|
|
if (Events.hasError(response)) {
|
2020-12-18 05:59:41 +03:00
|
|
|
// this.setState({ loading: false });
|
2020-11-28 07:39:01 +03:00
|
|
|
return;
|
2020-08-09 11:08:46 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2020-08-26 07:41:05 +03:00
|
|
|
const slug = Strings.createSlug(this.state.name);
|
|
|
|
const url = `/${this.props.viewer.username}/${slug}`;
|
2020-10-05 00:30:28 +03:00
|
|
|
let preview = this.props.current.data.preview;
|
|
|
|
if (!preview) {
|
|
|
|
for (let object of this.props.current.data.objects) {
|
|
|
|
if (
|
|
|
|
object.type &&
|
2020-11-11 04:44:21 +03:00
|
|
|
Validations.isPreviewableImage(object.type) &&
|
2020-11-11 00:06:26 +03:00
|
|
|
object.size &&
|
|
|
|
object.size < SIZE_LIMIT
|
2020-10-05 00:30:28 +03:00
|
|
|
) {
|
2020-11-28 04:19:30 +03:00
|
|
|
preview = object.url;
|
2020-10-05 00:30:28 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!preview) {
|
|
|
|
preview = DEFAULT_IMAGE;
|
|
|
|
}
|
2020-08-09 11:08:46 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2020-09-08 02:28:50 +03:00
|
|
|
<System.P
|
|
|
|
style={{
|
|
|
|
fontFamily: Constants.font.semiBold,
|
|
|
|
fontSize: Constants.typescale.lvl3,
|
2020-12-11 05:59:17 +03:00
|
|
|
marginBottom: 36,
|
2020-09-08 02:28:50 +03:00
|
|
|
}}
|
|
|
|
>
|
2020-09-13 04:12:56 +03:00
|
|
|
Slate settings
|
2020-08-26 07:41:05 +03:00
|
|
|
</System.P>
|
2020-08-09 11:08:46 +03:00
|
|
|
|
2020-10-05 00:30:28 +03:00
|
|
|
<div css={STYLES_GROUPING}>
|
|
|
|
<System.P css={STYLES_HEADER}>Name</System.P>
|
|
|
|
<System.P
|
2020-12-11 05:59:17 +03:00
|
|
|
css={STYLES_TEXT}
|
2020-10-05 00:30:28 +03:00
|
|
|
style={{
|
|
|
|
marginTop: 12,
|
|
|
|
}}
|
|
|
|
>
|
2020-12-11 05:59:17 +03:00
|
|
|
Give your slate a name so you and others can find it on Slate and on the web.
|
2020-09-25 09:31:56 +03:00
|
|
|
</System.P>
|
2020-10-05 00:30:28 +03:00
|
|
|
|
|
|
|
<System.Input
|
|
|
|
placeholder="Slate name..."
|
2020-12-11 05:59:17 +03:00
|
|
|
style={{ marginTop: 12 }}
|
2020-10-05 00:30:28 +03:00
|
|
|
name="name"
|
|
|
|
value={this.state.name}
|
|
|
|
onChange={this._handleChange}
|
|
|
|
onSubmit={this._handleSubmit}
|
|
|
|
descriptionStyle={{ fontSize: "20px !important" }}
|
|
|
|
labelStyle={{ fontSize: "20px" }}
|
|
|
|
/>
|
2020-12-11 05:59:17 +03:00
|
|
|
<System.P
|
|
|
|
style={{
|
|
|
|
marginTop: 12,
|
|
|
|
color: Constants.system.textGrayLight,
|
|
|
|
fontSize: Constants.typescale.lvl0,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
https://slate.host{url}
|
|
|
|
</System.P>
|
2020-10-05 00:30:28 +03:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div css={STYLES_GROUPING}>
|
|
|
|
<System.P css={STYLES_HEADER}>Description</System.P>
|
2020-12-11 05:59:17 +03:00
|
|
|
<System.P
|
|
|
|
css={STYLES_TEXT}
|
|
|
|
style={{
|
|
|
|
marginTop: 12,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Give your slate a description, add links, and connect it to other slates.
|
|
|
|
</System.P>
|
2020-10-05 00:30:28 +03:00
|
|
|
|
|
|
|
<System.Textarea
|
2020-12-11 05:59:17 +03:00
|
|
|
style={{ marginTop: 12 }}
|
2020-10-05 00:30:28 +03:00
|
|
|
name="body"
|
2020-12-11 05:59:17 +03:00
|
|
|
placeholder="Slate description..."
|
2020-10-05 00:30:28 +03:00
|
|
|
value={this.state.body}
|
2020-09-14 08:22:19 +03:00
|
|
|
onChange={this._handleChange}
|
2020-10-05 00:30:28 +03:00
|
|
|
onSubmit={this._handleSubmit}
|
2020-09-14 08:22:19 +03:00
|
|
|
/>
|
2020-08-09 11:08:46 +03:00
|
|
|
</div>
|
|
|
|
|
2020-11-10 03:03:04 +03:00
|
|
|
{this.state.public ? (
|
|
|
|
<div css={STYLES_GROUPING}>
|
|
|
|
<System.P css={STYLES_HEADER}>Preview image</System.P>
|
2020-10-05 00:30:28 +03:00
|
|
|
|
2020-11-10 03:03:04 +03:00
|
|
|
<System.P
|
2020-12-11 05:59:17 +03:00
|
|
|
css={STYLES_TEXT}
|
2020-11-10 03:03:04 +03:00
|
|
|
style={{
|
|
|
|
marginTop: 12,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
This is the image that shows when you share a link to your slate.
|
|
|
|
</System.P>
|
2020-10-05 00:30:28 +03:00
|
|
|
|
2020-11-10 03:03:04 +03:00
|
|
|
<div css={STYLES_IMAGE_BOX} style={{ marginTop: 24 }}>
|
|
|
|
<img src={preview} alt="" style={{ maxWidth: "368px", maxHeight: "368px" }} />
|
|
|
|
</div>
|
2020-10-05 00:30:28 +03:00
|
|
|
</div>
|
2020-11-10 03:03:04 +03:00
|
|
|
) : null}
|
2020-10-05 00:30:28 +03:00
|
|
|
|
|
|
|
<div css={STYLES_GROUPING}>
|
2020-12-11 05:59:17 +03:00
|
|
|
<System.P css={STYLES_HEADER} style={{ marginBottom: 12 }}>
|
|
|
|
Privacy
|
|
|
|
</System.P>
|
|
|
|
<System.P
|
|
|
|
css={STYLES_TEXT}
|
|
|
|
style={{
|
|
|
|
marginTop: 12,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
All slates are public by default. This means they can be discovered and seen by anyone
|
|
|
|
on the internet. If you make it private, only you will be able to see it.
|
|
|
|
</System.P>
|
|
|
|
<RadioGroup
|
|
|
|
name="public"
|
|
|
|
options={[
|
|
|
|
{
|
|
|
|
value: true,
|
|
|
|
label: (
|
|
|
|
<div style={{ display: "flex", alignItems: "center" }}>
|
|
|
|
<SVG.Globe height="16px" style={{ marginRight: 8 }} />
|
|
|
|
Public
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: false,
|
|
|
|
label: (
|
|
|
|
<div style={{ display: "flex", alignItems: "center" }}>
|
|
|
|
<SVG.SecurityLock height="16px" style={{ marginRight: 8 }} />
|
|
|
|
Private
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
style={{ marginTop: 12 }}
|
|
|
|
labelStyle={{ fontFamily: Constants.font.medium }}
|
|
|
|
selected={this.state.public}
|
|
|
|
onChange={this._handleChange}
|
|
|
|
/>
|
2020-10-05 00:30:28 +03:00
|
|
|
</div>
|
|
|
|
|
2020-09-14 08:22:19 +03:00
|
|
|
<div style={{ marginTop: 40 }}>
|
2020-10-31 02:12:20 +03:00
|
|
|
<System.ButtonPrimary full onClick={this._handleSubmit} loading={this.state.loading}>
|
2020-09-13 03:00:58 +03:00
|
|
|
Save changes
|
2020-08-09 11:08:46 +03:00
|
|
|
</System.ButtonPrimary>
|
|
|
|
|
|
|
|
{!this.state.loading ? (
|
2020-12-11 05:59:17 +03:00
|
|
|
<div style={{ marginTop: 16 }}>
|
|
|
|
<System.ButtonWarning
|
|
|
|
full
|
|
|
|
onClick={this._handleDelete}
|
|
|
|
style={{ overflow: "hidden" }}
|
|
|
|
>
|
|
|
|
Delete slate
|
|
|
|
</System.ButtonWarning>
|
|
|
|
</div>
|
2020-08-09 11:08:46 +03:00
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|