@@ -213,6 +213,12 @@ const compareContracts = (prev: Account[], current: Account[]) => {
213
213
214
214
let monacoServicesInstalled = false ;
215
215
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
+
216
222
const EditorContainer : React . FC < EditorContainerProps > = ( {
217
223
isLoading,
218
224
project,
@@ -231,6 +237,8 @@ const EditorContainer: React.FC<EditorContainerProps> = ({
231
237
232
238
const projectAccess = useProject ( )
233
239
240
+ const [ descriptionOverflow , setDescriptionOverflow ] = useState ( calculateSize ( project . readme ) )
241
+
234
242
useEffect ( ( ) => {
235
243
if ( isLoading ) {
236
244
setCode ( '' ) ;
@@ -350,6 +358,10 @@ const EditorContainer: React.FC<EditorContainerProps> = ({
350
358
} ;
351
359
352
360
const isReadmeEditor = active . type === 4 ;
361
+ const readmeLabel = `README.md${ descriptionOverflow
362
+ ? " - Content can't be more than 1Mb in size"
363
+ : ""
364
+ } `
353
365
354
366
return (
355
367
< MainRoot >
@@ -395,13 +407,18 @@ const EditorContainer: React.FC<EditorContainerProps> = ({
395
407
} }
396
408
/>
397
409
</ InputBlock >
398
- < Label > README.md </ Label >
410
+ < Label error = { descriptionOverflow } > { readmeLabel } </ Label >
399
411
< MdeEditor
400
412
value = { readme }
401
413
onChange = { ( readme : string ) => {
414
+ const overflow = calculateSize ( readme )
415
+ setDescriptionOverflow ( overflow )
402
416
setReadme ( readme ) ;
403
- updateProject ( title , description , readme ) ;
417
+ if ( ! overflow ) {
418
+ updateProject ( title , description , readme ) ;
419
+ }
404
420
} }
421
+ overflow = { descriptionOverflow }
405
422
/>
406
423
</ >
407
424
) }
0 commit comments