diff --git a/app/scenes/Document/components/Editor.js b/app/scenes/Document/components/Editor.js index 9180f23a..e5425044 100644 --- a/app/scenes/Document/components/Editor.js +++ b/app/scenes/Document/components/Editor.js @@ -4,6 +4,7 @@ import { observer } from "mobx-react"; import * as React from "react"; import Textarea from "react-autosize-textarea"; import styled from "styled-components"; +import { MAX_TITLE_LENGTH } from "shared/constants"; import parseTitle from "shared/utils/parseTitle"; import Document from "models/Document"; import ClickablePadding from "components/ClickablePadding"; @@ -106,7 +107,7 @@ class DocumentEditor extends React.Component { readOnly={readOnly} disabled={readOnly} autoFocus={!title} - maxLength={100} + maxLength={MAX_TITLE_LENGTH} /> { @action duplicate = async (document: Document): * => { + const append = " (duplicate)"; + const res = await client.post("/documents.create", { publish: !!document.publishedAt, parentDocumentId: document.parentDocumentId, collectionId: document.collectionId, template: document.template, - title: `${document.title} (duplicate)`, + title: `${document.title.slice( + 0, + MAX_TITLE_LENGTH - append.length + )}${append}`, text: document.text, }); invariant(res && res.data, "Data should be available"); diff --git a/server/models/Document.js b/server/models/Document.js index a4932871..51207602 100644 --- a/server/models/Document.js +++ b/server/models/Document.js @@ -5,6 +5,7 @@ import randomstring from "randomstring"; import Sequelize, { Transaction } from "sequelize"; import MarkdownSerializer from "slate-md-serializer"; import isUUID from "validator/lib/isUUID"; +import { MAX_TITLE_LENGTH } from "../../shared/constants"; import parseTitle from "../../shared/utils/parseTitle"; import unescape from "../../shared/utils/unescape"; import { Collection, User } from "../models"; @@ -90,8 +91,8 @@ const Document = sequelize.define( type: DataTypes.STRING, validate: { len: { - args: [0, 100], - msg: "Document title must be less than 100 characters", + args: [0, MAX_TITLE_LENGTH], + msg: `Document title must be less than ${MAX_TITLE_LENGTH} characters`, }, }, }, diff --git a/shared/constants.js b/shared/constants.js index c4cca7aa..9f7c4faa 100644 --- a/shared/constants.js +++ b/shared/constants.js @@ -2,3 +2,4 @@ export const USER_PRESENCE_INTERVAL = 5000; export const MAX_AVATAR_DISPLAY = 6; +export const MAX_TITLE_LENGTH = 100;