import * as React from "react"; import * as Actions from "~/common/actions"; import * as Constants from "~/common/constants"; import * as System from "~/components/system"; import * as Strings from "~/common/strings"; import * as Validations from "~/common/validations"; import * as Events from "~/common/custom-events"; import * as SVG from "~/common/svg"; import * as UserBehaviors from "~/common/user-behaviors"; import { RadioGroup } from "~/components/system/components/RadioGroup"; import { css } from "@emotion/react"; import { ConfirmationModal } from "~/components/core/ConfirmationModal"; import { Link } from "~/components/core/Link"; const DEFAULT_IMAGE = "https://slate.textile.io/ipfs/bafkreiaow45dlq5xaydaeqocdxvffudibrzh2c6qandpqkb6t3ahbvh6re"; const STYLES_HEADER = css` font-family: ${Constants.font.semiBold}; `; const STYLES_TEXT = css` color: ${Constants.semantic.textGray}; font-size: ${Constants.typescale.lvl0}; `; 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); background-color: ${Constants.system.white}; border-radius: 6px; padding: 16px; margin-bottom: 24px; `; export default class SidebarSingleSlateSettings extends React.Component { state = { slatename: this.props.data.slatename, isPublic: this.props.data.isPublic, body: this.props.data.data.body, name: this.props.data.data.name, tags: this.props.data.data?.tags || [], suggestions: this.props.viewer?.tags || [], modalShow: false, }; componentDidMount = () => { this.updateSuggestions(); }; updateSuggestions = () => { let newSuggestions = new Set([...this.state.suggestions, ...this.state.tags]); this.setState({ suggestions: Array.from(newSuggestions) }); }; _handleSubmit = async () => { let slates = this.props.viewer.slates; for (let slate of slates) { if (slate.id === this.props.data.id) { slate.data.name = this.state.name; slate.isPublic = this.state.isPublic; slate.data.body = this.state.body; slate.data.tags = this.state.tags; let newSuggestions = new Set([...this.state.suggestions, ...this.state.tags]); this.props.onAction({ type: "UPDATE_VIEWER", viewer: { slates, tags: Array.from(newSuggestions) }, }); break; } } this.props.onCancel(); const response = await Actions.updateSlate({ id: this.props.data.id, isPublic: this.state.isPublic, data: { name: this.state.name, body: this.state.body, tags: this.state.tags, }, }); if (Events.hasError(response)) { return; } }; _handleCancel = () => { this.props.onCancel(); }; _handleChange = (e) => { this.setState({ [e.target.name]: e.target.value }, () => { if (e.target.name === "tags") { this.updateSuggestions(); } }); }; _handleDelete = async (res) => { if (!res) { this.setState({ modalShow: false }); return; } this.props.onAction({ type: "NAVIGATE", href: "/_/collections", }); let slates = this.props.viewer.slates.filter((slate) => slate.id !== this.props.data.id); this.props.onAction({ type: "UPDATE_VIEWER", viewer: { slates } }); const response = await Actions.deleteSlate({ id: this.props.data.id, }); if (Events.hasError(response)) { return; } this.setState({ modalShow: false }); }; render() { const slug = Strings.createSlug(this.state.name); const url = `/${this.props.viewer.username}/${slug}`; let preview = this.props.data.data.preview; if (!preview) { for (let object of this.props.data.objects) { if ( object.data.type && Validations.isPreviewableImage(object.data.type) && object.data.size && object.data.size < Constants.linkPreviewSizeLimit ) { preview = Strings.getURLfromCID(object.cid); break; } } } if (!preview) { preview = DEFAULT_IMAGE; } return ( Collection settings
Name Give your collection a name so you and others can find it on Slate and on the web. https://slate.host{url}
Description Give your collection a description, add links, and connect it to other collections.
Tags Add tags to a collection to categorize it.
Cover image This is the cover image for your collection. You can select a different cover image using the "Make cover image" button.
Privacy All collections 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.isPublic} onChange={this._handleChange} />
Save changes
this.setState({ modalShow: true })} style={{ overflow: "hidden" }} > Delete collection
{this.state.modalShow && ( )}
); } }