Hello Programmers,
I hope you all are well. I am very well sure that many new developers are working on Steem and they want to build some useful tools for Steem Blockchain. Our team is working on SteemPro Mobile App for the last 6 months, During this time frame we also launch SteemPro
To educate the new developers and also to the whole steemit users, We arrange this bi-weekly post in which we explore the code of official Steemit. You can get the GitHub repository here.
We will also modify the code to convert it into TypeScript and make the necessary changes to work with the SDS APIs provided by @steemchiller.
File Path
steemit/condenser/src/app/components/elements/ReplyEditor.jsx
Class
ReplyEditor
Old Code
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,
};
},
Working
This function is used to check the length of a post/comment body in the Steem blockchain. There is a specific length for the Post body and the Comment body. Let's rewrite and make it simple to use in our SteemPro app development.
Code in Typescript
export const validateCommentBody = (
body: string,
isStory: boolean,
): true | string => {
const maxKb = isStory ? 64 : 16;
const maxLength = maxKb * 1024;
console.log(body.length);
if (new Blob([body]).size >= maxKb * 1024 - 256) {
return `Exceeds maximum length (${maxKb}KB)`;
}
return true;
};
What's new
We create a new function validateCommentBody to validate the both Post and Comment body length. We set two params body with the typed string and isStory with type boolean. If is story is true then we consider the body of the post or else the body of a comment. here is the simple usage in the SteemPro Mobile app.
SteemPro Official
Cc: @blacks
Cc: @rme
Cc: @hungry-griffin
Cc: @steemchiller
Cc: @steemcurator01
Best Regards @faisalamin