import * as React from "react"; import * as Strings from "~/common/strings"; import * as Constants from "~/common/constants"; import * as System from "~/components/system"; import * as Validations from "~/common/validations"; import * as Actions from "~/common/actions"; import * as Events from "~/common/custom-events"; import * as SVG from "~/common/svg"; import { RadioGroup } from "~/components/system/components/RadioGroup"; import { css } from "@emotion/react"; const SLATE_LIMIT = 50; const STYLES_TEXT = css` color: ${Constants.system.textGray}; font-size: ${Constants.typescale.lvl0}; `; const STYLES_HEADER = css` font-family: ${Constants.font.semiBold}; `; const STYLES_GROUPING = css` width: 100%; border: 1px solid rgba(196, 196, 196, 0.5); background-color: ${Constants.system.white}; border-radius: 6px; padding: 16px; margin-bottom: 24px; `; export default class SidebarCreateSlate extends React.Component { state = { name: "", public: true, body: "", loading: false, }; _handleSubmit = async () => { if (this.props.viewer.slates.length >= SLATE_LIMIT) { Events.dispatchMessage({ message: `You have reached the limit of ${SLATE_LIMIT} Slates!` }); return; } this.setState({ loading: true }); if (!Validations.slatename(this.state.name)) { Events.dispatchMessage({ message: "Please provide a name between 1-48 characters." }); this.setState({ loading: false }); return; } const response = await Actions.createSlate({ name: this.state.name, public: this.state.public, body: this.state.body, }); if (Events.hasError(response)) { this.setState({ loading: false }); return; } if (this.props.sidebarData && this.props.sidebarData.files) { let data = this.props.sidebarData.files.map((file) => { return { title: file.title || file.name, ...file }; }); const addResponse = await Actions.addFileToSlate({ slate: response.slate, data, fromSlate: this.props.sidebarData.fromSlate, }); if (Events.hasError(addResponse)) { this.setState({ loading: false }); return; } const { added, skipped } = addResponse; let message = Strings.formatAsUploadMessage(added, skipped, true); if (message) { Events.dispatchMessage({ message, status: !added ? null : "INFO" }); } } this.setState({ loading: false }); window.setTimeout( () => this.props.onAction({ type: "NAVIGATE", value: "NAV_SLATE", data: { id: response.slate.id, }, }), 200 ); }; _handleCancel = () => { this.props.onCancel(); }; _handleChange = (e) => { this.setState({ [e.target.name]: e.target.value }); }; render() { const slug = Strings.createSlug(this.state.name); const url = `/${this.props.viewer.username}/${slug}`; return (
Create slate
Name Give your slate a name so you and others can find it on Slate and on the web. https://slate.host{url}
Description Give your slate a description, add links, and connect it to other slates.
Privacy 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. Public
), }, { value: false, label: (
Private
), }, ]} style={{ marginTop: 12 }} labelStyle={{ fontFamily: Constants.font.medium }} selected={this.state.public} onChange={this._handleChange} />
Create {this.state.name} ); } }