Skip to content

Commit

Permalink
respect max post size, closes steemit#3717
Browse files Browse the repository at this point in the history
  • Loading branch information
gl2748 committed Feb 21, 2020
1 parent f2656a6 commit cebadb1
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/app/components/elements/ReplyEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,27 +231,36 @@ class ReplyEditor extends React.Component {
initForm(props) {
const { isStory, type, fields } = props;
const isEdit = type === 'edit';
const maxKb = isStory ? 65 : 16;
const maxKb = isStory ? 64 : 16;
reactForm({
fields,
instance: this,
name: 'replyForm',
initialValues: props.initialValues,
validation: values => ({
title:
isStory &&
(!values.title || values.title.trim() === ''
? tt('g.required')
: values.title.length > 255
? tt('reply_editor.shorten_title')
: null),
tags: isStory && validateTagInput(values.tags, !isEdit),
body: !values.body
? tt('g.required')
: values.body.length > maxKb * 1024
? tt('reply_editor.exceeds_maximum_length', { maxKb })
: null,
}),
validation: values => {
let bodyValidation = null;
if (!values.body) {
bodyValidation = tt('g.required');
}
if (
values.body &&
new Blob([values.body]).size >= maxKb * 1024 - 256
) {
bodyValidation = `Post body exceeds ${maxKb * 1024 -
256} bytes.`;
}
return {
title:
isStory &&
(!values.title || values.title.trim() === ''
? tt('g.required')
: values.title.length > 255
? tt('reply_editor.shorten_title')
: null),
tags: isStory && validateTagInput(values.tags, !isEdit),
body: bodyValidation,
};
},
});
}

Expand Down

0 comments on commit cebadb1

Please sign in to comment.