@@ -8,12 +8,12 @@ import NewTabButton from "./NewTabButton";
88import pasteDispatcher from "../dispatchers/PasteDispatcher" ;
99import getLanguage from "../stores/languageStore" ;
1010import config from "../config.json" ;
11- import ArrowDownwardIcon from "@material-ui/icons/ArrowDownward" ;
1211import { Button } from "@material-ui/core" ;
1312import DropdownItem from "react-bootstrap/DropdownItem" ;
1413import React from "react" ;
15- import InsertPhotoIcon from "@material-ui/icons/InsertPhoto" ;
1614import SettingsIcon from "@material-ui/icons/Settings" ;
15+ import AddBoxIcon from '@material-ui/icons/AddBox' ;
16+ import LibraryAddCheckIcon from '@material-ui/icons/LibraryAddCheck' ;
1717
1818const languages = {
1919 py : "python" ,
@@ -68,7 +68,7 @@ export default function EditorTabs({
6868 pid = null ,
6969} : TabInfo ) {
7070 const [ value , setValue ] = useState < Record < string , string > [ ] > ( [
71- { title : "file.txt" , content : "" } ,
71+ { title : "file.txt" , content : "" , image : null } ,
7272 ] ) ;
7373 const [ currTab , setCurrTab ] = useState ( 0 ) ;
7474 const [ charCountToast , setCharCountToast ] = useState ( false ) ;
@@ -80,8 +80,33 @@ export default function EditorTabs({
8080 const [ initialState , setInitialState ] = useState ( false ) ;
8181 const [ langDropDown , setLangDropDown ] = useState ( false ) ;
8282 const [ dropLang , setDropLang ] = useState ( null ) ;
83+ const [ image , setImage ] = useState ( null )
84+ const [ showImage , setShowImage ] = useState ( null )
8385
8486 const tabRef = useRef ( ) ;
87+ const imageRef = useRef ( ) ;
88+
89+ function handleSetImage ( e ) {
90+ let file = e . currentTarget . files [ 0 ]
91+ let allowed = [ 'image/gif' , 'image/jpeg' , 'image/png' , 'image/webp' ] ;
92+
93+ if ( ! ! file && ! allowed . includes ( file [ 'type' ] ) ) {
94+ alert ( 'Only images are currently supported.' )
95+ }
96+ else if ( file . size / 1024 / 1024 > 4 ) {
97+ alert ( 'You can only upload files 4Mb in size or less.' )
98+ }
99+ else {
100+ setImage ( file )
101+ }
102+ }
103+
104+ useEffect ( ( ) => {
105+ let newValue = [ ...value ] ;
106+ newValue [ currTab ] [ 'image' ] = image
107+
108+ setValue ( newValue )
109+ } , [ image ] )
85110
86111 pasteDispatcher . dispatch ( { paste : value } ) ;
87112 const maxCharCount = config [ "paste" ] [ "character_limit" ] ;
@@ -160,6 +185,13 @@ export default function EditorTabs({
160185
161186 return (
162187 < >
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" } />
191+ </ div >
192+ : null }
193+ < input ref = { imageRef } type = "file" style = { { display : 'none' } } onChange = { e => handleSetImage ( e ) } />
194+
163195 < PasswordModal
164196 show = { passwordModal }
165197 shake = { shake }
@@ -188,6 +220,21 @@ export default function EditorTabs({
188220 setValue ( newValue ) ;
189221 } }
190222 >
223+ { ! pid && value [ i ] [ 'image' ] === null ?
224+ < div className = { styles . addImageButtonContainer } onClick = { ( ( e ) => {
225+ e . preventDefault ( ) ;
226+ imageRef . current . click ( ) ;
227+
228+ } ) } >
229+ < AddBoxIcon className = { styles . addImagesButtonNS } > </ AddBoxIcon >
230+ </ div > : null }
231+
232+ { value [ i ] [ 'image' ] ?
233+ < div className = { styles . addImageButtonContainer } onClick = { ( e ) => setShowImage ( true ) } >
234+ < LibraryAddCheckIcon style = { { color : "#E3E3E3" } } />
235+ </ div >
236+ : null }
237+
191238 { ! ! pid ? (
192239 < div className = { styles . dropdownContainer } ref = { tabRef } >
193240 < Button
0 commit comments