@@ -67,9 +67,7 @@ export default function EditorTabs({
6767 hasPassword = false ,
6868 pid = null ,
6969} : TabInfo ) {
70- const [ value , setValue ] = useState < Record < string , string > [ ] > ( [
71- { title : "file.txt" , content : "" , image : null } ,
72- ] ) ;
70+ const [ value , setValue ] = useState ( [ { title : "file.txt" , content : "" , image : "" } , ] ) ;
7371 const [ currTab , setCurrTab ] = useState ( 0 ) ;
7472 const [ charCountToast , setCharCountToast ] = useState ( false ) ;
7573 const [ passwordModal , setPasswordModal ] = useState ( ! ! hasPassword ) ;
@@ -86,9 +84,10 @@ export default function EditorTabs({
8684 const tabRef = useRef ( ) ;
8785 const imageRef = useRef ( ) ;
8886
87+
8988 function handleSetImage ( e ) {
9089 let file = e . currentTarget . files [ 0 ]
91- let allowed = [ 'image/gif' , 'image/jpeg' , 'image/png' , 'image/webp' ] ;
90+ let allowed = [ 'image/gif' , 'image/jpeg' , 'image/png' ] ;
9291
9392 if ( ! ! file && ! allowed . includes ( file [ 'type' ] ) ) {
9493 alert ( 'Only images are currently supported.' )
@@ -111,10 +110,12 @@ export default function EditorTabs({
111110 pasteDispatcher . dispatch ( { paste : value } ) ;
112111 const maxCharCount = config [ "paste" ] [ "character_limit" ] ;
113112
114- if ( initialData !== null && ! initialState ) {
115- setValue ( initialData ) ;
116- setInitialState ( true ) ;
117- }
113+ useEffect ( ( ) => {
114+ if ( initialData !== null && ! initialState ) {
115+ setValue ( initialData ) ;
116+ setInitialState ( true ) ;
117+ }
118+ } , [ ] )
118119
119120 useEffect ( ( ) => {
120121 if ( sessionStorage . getItem ( "pasteCopy" ) !== null ) {
@@ -185,12 +186,13 @@ export default function EditorTabs({
185186
186187 return (
187188 < >
188- { showImage ?
189- < div className = { styles . attachmentImageBackdrop } onClick = { ( e ) => setShowImage ( false ) } >
190- < img className = { styles . attachmentImage } src = { "https://mystbin.b-cdn.net/images/0-OffSpecificationCharm-9a0f0b7719a4f55a5e104922e4d42204.png" } />
189+ < div >
190+ { value . map ( ( v , i ) => (
191+ < div className = { styles . attachmentImageBackdrop } onClick = { ( e ) => setShowImage ( - 1 ) } style = { { display : showImage === i ? "block" : "none" , } } >
192+ < img className = { styles . attachmentImage } src = { value [ i ] [ 'image' ] } style = { { display : showImage === i ? "block" : "none" , } } />
191193 </ div >
192- : null }
193- < input ref = { imageRef } type = "file" style = { { display : 'none' } } onChange = { e => handleSetImage ( e ) } / >
194+ ) ) }
195+ </ div >
194196
195197 < PasswordModal
196198 show = { passwordModal }
@@ -220,17 +222,19 @@ export default function EditorTabs({
220222 setValue ( newValue ) ;
221223 } }
222224 >
223- { ! pid && value [ i ] [ 'image' ] === null ?
224- < div className = { styles . addImageButtonContainer } onClick = { ( ( e ) => {
225+ < input ref = { imageRef } type = "file" style = { { display : 'none' } } onChange = { e => ( handleSetImage ( e ) ) } />
226+ { ! pid && value [ i ] [ 'image' ] === null || value [ i ] [ 'image' ] === "" ?
227+ < div className = { styles . addImageButtonContainer } onClick = { ( e ) => {
225228 e . preventDefault ( ) ;
226- imageRef . current . click ( ) ;
229+ // @ts -ignore
230+ imageRef . current . click ( ) ;
227231
228- } ) } >
232+ } } >
229233 < AddBoxIcon className = { styles . addImagesButtonNS } > </ AddBoxIcon >
230234 </ div > : null }
231235
232236 { value [ i ] [ 'image' ] ?
233- < div className = { styles . addImageButtonContainer } onClick = { ( e ) => setShowImage ( true ) } >
237+ < div className = { styles . addImageButtonContainer } onClick = { ( e ) => setShowImage ( i ) } >
234238 < LibraryAddCheckIcon style = { { color : "#E3E3E3" } } />
235239 </ div >
236240 : null }
@@ -277,7 +281,7 @@ export default function EditorTabs({
277281 < NewTabButton
278282 onClick = { ( ) => {
279283 let newValue = [ ...value ] ;
280- newValue . push ( { title : "default_name.ext " , content : "" } ) ;
284+ newValue . push ( { title : "file.txt " , content : "" , image : "" } ) ;
281285 setValue ( newValue ) ;
282286 setCurrTab ( value . length ) ;
283287 } }
0 commit comments