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-08-09 11:08:46 +03:00
|
|
|
|
|
|
|
import { css } from "@emotion/react";
|
2020-09-12 01:25:33 +03:00
|
|
|
import { dispatchCustomEvent } from "~/common/custom-events";
|
2020-10-05 00:30:28 +03:00
|
|
|
|
|
|
|
const SIZE_LIMIT = 1000000;
|
|
|
|
const DEFAULT_IMAGE = "";
|
2020-08-09 11:08:46 +03:00
|
|
|
|
|
|
|
const STYLES_GROUP = css`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
width: 100%;
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
white-space: pre-wrap;
|
2020-09-14 08:22:19 +03:00
|
|
|
margin-top: 8px;
|
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
|
|
|
${"" /* margin-top: 32px; */}
|
|
|
|
`;
|
|
|
|
|
|
|
|
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;
|
|
|
|
${"" /* box-shadow: 0 0 0 1px ${Constants.system.border} inset; */}
|
|
|
|
border-radius: 4px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_GROUPING = css`
|
|
|
|
width: 100%;
|
|
|
|
border: 1px solid rgba(196, 196, 196, 0.5);
|
|
|
|
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 () => {
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
|
|
|
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-10-05 00:30:28 +03:00
|
|
|
console.log(response);
|
2020-08-09 11:08:46 +03:00
|
|
|
|
|
|
|
if (!response) {
|
2020-09-12 01:25:33 +03:00
|
|
|
dispatchCustomEvent({
|
|
|
|
name: "create-alert",
|
|
|
|
detail: {
|
|
|
|
alert: {
|
|
|
|
message:
|
|
|
|
"We're having trouble connecting right now. Please try again later",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-08-09 11:08:46 +03:00
|
|
|
return this.setState({ loading: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.error) {
|
2020-09-12 01:25:33 +03:00
|
|
|
dispatchCustomEvent({
|
|
|
|
name: "create-alert",
|
|
|
|
detail: { alert: { decorator: response.decorator } },
|
|
|
|
});
|
2020-08-09 11:08:46 +03:00
|
|
|
return this.setState({ loading: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.props.onSubmit({});
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleCancel = () => {
|
|
|
|
this.props.onCancel();
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleChange = (e) => {
|
|
|
|
this.setState({ [e.target.name]: e.target.value });
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleDelete = async (e) => {
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
2020-08-26 07:41:05 +03:00
|
|
|
if (
|
|
|
|
!window.confirm(
|
|
|
|
"Are you sure you want to delete this Slate? This action is irreversible."
|
|
|
|
)
|
|
|
|
) {
|
2020-08-09 11:08:46 +03:00
|
|
|
return this.setState({ loading: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
if (!response) {
|
2020-09-12 01:25:33 +03:00
|
|
|
dispatchCustomEvent({
|
|
|
|
name: "create-alert",
|
|
|
|
detail: {
|
|
|
|
alert: {
|
|
|
|
message:
|
|
|
|
"We're having trouble connecting right now. Please try again later",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-08-09 11:08:46 +03:00
|
|
|
return this.setState({ loading: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.error) {
|
2020-09-12 01:25:33 +03:00
|
|
|
dispatchCustomEvent({
|
|
|
|
name: "create-alert",
|
|
|
|
detail: { alert: { decorator: response.decorator } },
|
|
|
|
});
|
2020-08-09 11:08:46 +03:00
|
|
|
return this.setState({ loading: false });
|
|
|
|
}
|
|
|
|
|
2020-08-18 22:28:33 +03:00
|
|
|
await this.props.onAction({
|
|
|
|
type: "NAVIGATE",
|
|
|
|
value: "V1_NAVIGATION_SLATES",
|
|
|
|
});
|
2020-08-22 08:19:11 +03:00
|
|
|
|
2020-08-09 11:08:46 +03:00
|
|
|
return await this.props.onRehydrate();
|
|
|
|
};
|
|
|
|
|
|
|
|
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 &&
|
|
|
|
object.type.startsWith("image/") &&
|
|
|
|
(!object.size || object.size < SIZE_LIMIT)
|
|
|
|
) {
|
|
|
|
preview = object.url.replace("https://undefined", "https://");
|
|
|
|
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-09-10 06:28:48 +03:00
|
|
|
marginBottom: 64,
|
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
|
|
|
|
style={{
|
|
|
|
marginTop: 12,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Changing the slatename will change your public slate URL. Your slate
|
|
|
|
URL is:{" "}
|
|
|
|
</System.P>
|
|
|
|
<System.P
|
|
|
|
style={{
|
|
|
|
marginTop: 12,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<a
|
|
|
|
href={url}
|
|
|
|
target="_blank"
|
|
|
|
style={{ color: Constants.system.brand }}
|
|
|
|
>
|
|
|
|
https://slate.host{url}
|
|
|
|
</a>
|
2020-09-25 09:31:56 +03:00
|
|
|
</System.P>
|
2020-10-05 00:30:28 +03:00
|
|
|
|
|
|
|
<System.Input
|
|
|
|
placeholder="Slate name..."
|
|
|
|
style={{ marginTop: 8, boxShadow: "none" }}
|
|
|
|
name="name"
|
|
|
|
value={this.state.name}
|
|
|
|
placeholder="Name"
|
|
|
|
onChange={this._handleChange}
|
|
|
|
onSubmit={this._handleSubmit}
|
|
|
|
descriptionStyle={{ fontSize: "20px !important" }}
|
|
|
|
labelStyle={{ fontSize: "20px" }}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div css={STYLES_GROUPING}>
|
|
|
|
<System.P css={STYLES_HEADER}>Description</System.P>
|
|
|
|
|
|
|
|
<System.Textarea
|
|
|
|
style={{ marginTop: 12, boxShadow: "none" }}
|
|
|
|
name="body"
|
|
|
|
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-10-05 00:30:28 +03:00
|
|
|
<div css={STYLES_GROUPING}>
|
|
|
|
<System.P css={STYLES_HEADER}>Preview image</System.P>
|
|
|
|
|
|
|
|
<System.P
|
|
|
|
style={{
|
|
|
|
marginTop: 12,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
This is the image that shows when you share a link to your slate.
|
|
|
|
</System.P>
|
|
|
|
|
|
|
|
<div css={STYLES_IMAGE_BOX} style={{ marginTop: 24 }}>
|
|
|
|
<img
|
|
|
|
src={preview}
|
|
|
|
alt=""
|
|
|
|
style={{ maxWidth: "368px", maxHeight: "368px" }}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div css={STYLES_GROUPING}>
|
|
|
|
<System.P css={STYLES_HEADER}>Privacy</System.P>
|
|
|
|
<div css={STYLES_GROUP}>
|
|
|
|
<System.P style={{ marginRight: 16 }}>
|
|
|
|
{this.state.public
|
|
|
|
? "Public. Anyone can search for and view this slate."
|
|
|
|
: "Private. Only you can view this slate."}
|
|
|
|
</System.P>
|
|
|
|
<System.Toggle
|
|
|
|
name="public"
|
|
|
|
onChange={this._handleChange}
|
|
|
|
active={this.state.public}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2020-09-14 08:22:19 +03:00
|
|
|
<div style={{ marginTop: 40 }}>
|
2020-08-26 07:41:05 +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-09-21 00:34:31 +03:00
|
|
|
<System.ButtonWarning
|
|
|
|
full
|
2020-09-09 22:35:39 +03:00
|
|
|
style={{
|
|
|
|
marginTop: 16,
|
|
|
|
}}
|
2020-08-26 07:41:05 +03:00
|
|
|
onClick={this._handleCancel}
|
|
|
|
>
|
2020-08-09 11:08:46 +03:00
|
|
|
Cancel
|
2020-09-21 00:34:31 +03:00
|
|
|
</System.ButtonWarning>
|
2020-08-09 11:08:46 +03:00
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{!this.state.loading ? (
|
2020-09-09 23:08:12 +03:00
|
|
|
<div style={{ marginTop: 48 }}>
|
2020-09-21 00:34:31 +03:00
|
|
|
<System.ButtonWarning
|
2020-08-26 07:41:05 +03:00
|
|
|
full
|
|
|
|
onClick={this._handleDelete}
|
2020-09-14 08:22:19 +03:00
|
|
|
style={{ overflow: "hidden" }}
|
2020-08-26 07:41:05 +03:00
|
|
|
>
|
2020-09-09 22:35:39 +03:00
|
|
|
Delete{" "}
|
|
|
|
{this.props.current.data && this.props.current.data.name
|
|
|
|
? this.props.current.data.name
|
|
|
|
: this.props.current.slatename}
|
2020-09-21 00:34:31 +03:00
|
|
|
</System.ButtonWarning>
|
2020-08-09 11:08:46 +03:00
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|