Skip to content

Commit

Permalink
Merge pull request #427 from thematters/feat/limits
Browse files Browse the repository at this point in the history
feat: title & summary limitations
  • Loading branch information
robertu7 authored May 22, 2023
2 parents eb0ed43 + a48ff15 commit a6b52fa
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ sources.list
src/themes/*.json

.parcel-cache
types/**/*
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@matters/matters-editor",
"version": "0.1.27-alpha.3",
"version": "0.1.28",
"description": "The editor component.",
"author": "https://github.com/thematters",
"homepage": "https://github.com/thematters/matters-editor",
Expand Down
8 changes: 5 additions & 3 deletions src/components/Summary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import autosize from 'autosize'
import classNames from 'classnames'
import React from 'react'

import { KEYCODES } from '../../enums/common'
import { KEYCODES, MAX_ARTICE_SUMMARY_LENGTH } from '../../enums/common'
import { Texts } from '../../enums/text'

/**
Expand Down Expand Up @@ -72,7 +72,7 @@ const MattersEditorSummary: React.FC<Props> = ({
})
const counterClasses = classNames({
counter: true,
error: length > 200,
error: length > MAX_ARTICE_SUMMARY_LENGTH,
})

return (
Expand All @@ -88,7 +88,9 @@ const MattersEditorSummary: React.FC<Props> = ({
onKeyPress={handleKeyPress}
/>
{!readOnly && (
<section className={counterClasses}>({length}/200)</section>
<section className={counterClasses}>
({length}/{MAX_ARTICE_SUMMARY_LENGTH})
</section>
)}
</section>
)
Expand Down
9 changes: 4 additions & 5 deletions src/components/Title/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import classNames from 'classnames'
import React from 'react'
import { Texts } from '../../enums/text'
import { MAX_ARTICE_TITLE_LENGTH } from '../../enums/common'

/**
* This is an optional component belonged to the edoitor.
Expand All @@ -21,10 +22,6 @@ interface Props {
update: (params: { title: any }) => void
}

const getValidTitleValue = (value: any, fallback: any): string => {
return value && value !== fallback ? value : ''
}

const MattersEditorTitle: React.FC<Props> = ({
defaultValue,
readOnly,
Expand All @@ -43,6 +40,8 @@ const MattersEditorTitle: React.FC<Props> = ({

React.useEffect(() => setValue(defaultValue), [defaultValue])

const title = value.slice(0, MAX_ARTICE_TITLE_LENGTH)

return (
<header className={classes}>
<input
Expand All @@ -51,7 +50,7 @@ const MattersEditorTitle: React.FC<Props> = ({
placeholder={texts.TITLE_PLACEHOLDER}
onChange={handleChange}
onBlur={handleBlur}
value={getValidTitleValue(value, texts.TITLE_FALLBACK)}
value={title}
/>
</header>
)
Expand Down
4 changes: 4 additions & 0 deletions src/enums/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ export const UPLOAD_IMAGE_SIZE_LIMIT: number = 5 * 1024 * 1024
export const UPLOAD_AUDIO_SIZE_LIMIT: number = 100 * 1024 * 1024

export const URL_LIKE_BUTTON: string = 'url_like_button'

export const MAX_ARTICE_TITLE_LENGTH = 100
export const MAX_ARTICE_SUMMARY_LENGTH = 200
export const MAX_ARTICLE_CONTENT_LENGTH = 50e3

0 comments on commit a6b52fa

Please sign in to comment.