@@ -213,6 +213,12 @@ const compareContracts = (prev: Account[], current: Account[]) => {
213213
214214let monacoServicesInstalled = false ;
215215
216+ const MAX_DESCRIPTION_SIZE = Math . pow ( 1024 , 2 ) // 1mb of storage can be saved into readme field
217+ const calculateSize = ( readme : string ) => {
218+ const { size } = new Blob ( [ readme ] )
219+ return size >= MAX_DESCRIPTION_SIZE
220+ }
221+
216222const EditorContainer : React . FC < EditorContainerProps > = ( {
217223 isLoading,
218224 project,
@@ -231,6 +237,8 @@ const EditorContainer: React.FC<EditorContainerProps> = ({
231237
232238 const projectAccess = useProject ( )
233239
240+ const [ descriptionOverflow , setDescriptionOverflow ] = useState ( calculateSize ( project . readme ) )
241+
234242 useEffect ( ( ) => {
235243 if ( isLoading ) {
236244 setCode ( '' ) ;
@@ -350,6 +358,10 @@ const EditorContainer: React.FC<EditorContainerProps> = ({
350358 } ;
351359
352360 const isReadmeEditor = active . type === 4 ;
361+ const readmeLabel = `README.md${ descriptionOverflow
362+ ? " - Content can't be more than 1Mb in size"
363+ : ""
364+ } `
353365
354366 return (
355367 < MainRoot >
@@ -395,13 +407,18 @@ const EditorContainer: React.FC<EditorContainerProps> = ({
395407 } }
396408 />
397409 </ InputBlock >
398- < Label > README.md </ Label >
410+ < Label error = { descriptionOverflow } > { readmeLabel } </ Label >
399411 < MdeEditor
400412 value = { readme }
401413 onChange = { ( readme : string ) => {
414+ const overflow = calculateSize ( readme )
415+ setDescriptionOverflow ( overflow )
402416 setReadme ( readme ) ;
403- updateProject ( title , description , readme ) ;
417+ if ( ! overflow ) {
418+ updateProject ( title , description , readme ) ;
419+ }
404420 } }
421+ overflow = { descriptionOverflow }
405422 />
406423 </ >
407424 ) }
0 commit comments