1- import { useEffect , useState } from "react" ;
1+ import { useEffect , useRef , useState } from "react" ;
22import MonacoEditor from "./MonacoEditor" ;
33import styles from "../styles/EditorTabs.module.css" ;
4- import { Toast } from "react-bootstrap" ;
4+ import { Dropdown , Toast } from "react-bootstrap" ;
55import PasswordModal from "./PasswordModal" ;
66import Tab from "./Tab" ;
77import 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" ;
12+ import { Button } from "@material-ui/core" ;
13+ import DropdownItem from "react-bootstrap/DropdownItem" ;
14+ import React from "react" ;
15+ import InsertPhotoIcon from '@material-ui/icons/InsertPhoto' ;
16+
17+ const languages = {
18+ py : "python" ,
19+ python : "python" ,
20+ pyi : "python" ,
21+ js : "javascript" ,
22+ javascript : "javascript" ,
23+ jsx : "javascript" ,
24+ ts : "typescript" ,
25+ typescript : "typescript" ,
26+ tsx : "typescript" ,
27+ html : "html" ,
28+ swift : "swift" ,
29+ json : "json" ,
30+ rs : "rust" ,
31+ rust : "rust" ,
32+ ex : "elixir" ,
33+ elixir : "elixir" ,
34+ md : "markdown" ,
35+ markdown : "markdown" ,
36+ go : "go" ,
37+ cpp : "cpp" ,
38+ c : "cpp" ,
39+ h : "cpp" ,
40+ cs : "csharp" ,
41+ css : "css" ,
42+ hs : "haskell" ,
43+ perl : "perl" ,
44+ pl : "perl" ,
45+ pm : "perl" ,
46+ bash : "bash" ,
47+ zsh : "bash" ,
48+ sh : "bash" ,
49+ sql : "sql" ,
50+ nginx : "nginx" ,
51+ ini : "ini" ,
52+ toml : "toml" ,
53+ xml : "xml" ,
54+ yml : "yml" ,
55+ yaml : "yml" ,
56+ } ;
1157
1258interface TabInfo {
1359 initialData ?: any ;
@@ -31,6 +77,10 @@ export default function EditorTabs({
3177 const [ lang , setLang ] = useState < string [ ] > ( [ ] ) ;
3278 const id = pid ;
3379 const [ initialState , setInitialState ] = useState ( false ) ;
80+ const [ langDropDown , setLangDropDown ] = useState ( false ) ;
81+ const [ dropLang , setDropLang ] = useState ( null )
82+
83+ const tabRef = useRef ( ) ;
3484
3585 pasteDispatcher . dispatch ( { paste : value } ) ;
3686 const maxCharCount = config [ "paste" ] [ "character_limit" ] ;
@@ -59,6 +109,13 @@ export default function EditorTabs({
59109 }
60110 } , [ value ] ) ;
61111
112+ useEffect ( ( ) => {
113+ let newLang = [ ...lang ]
114+ newLang . splice ( currTab , 1 , dropLang )
115+ setLang ( newLang )
116+
117+ } , [ langDropDown ] ) ;
118+
62119 useEffect ( ( ) => {
63120 let initialLangs = [ ] ;
64121 value . map ( function ( v ) {
@@ -129,8 +186,33 @@ export default function EditorTabs({
129186 let newValue = [ ...value ] ;
130187 newValue . splice ( i , 1 ) ;
131188 setValue ( newValue ) ;
132- } }
133- />
189+ } } >
190+ { ! ! pid ?
191+ < div className = { styles . dropdownContainer } ref = { tabRef } >
192+ < Button type = "submit" className = { styles . langButton } onClick = { ( ) => setLangDropDown ( ! langDropDown ) } >
193+ < ArrowDownwardIcon />
194+ </ Button >
195+ { langDropDown ?
196+ < div className = { styles . langParent } >
197+ < Dropdown className = { styles . dropDown } autoClose >
198+ { Object . keys ( languages ) . map ( ( v , index ) => {
199+ if ( i !== currTab ) {
200+ return < > </ >
201+ }
202+ return ( < DropdownItem
203+ key = { v }
204+ className = { styles . dropdownItem }
205+ onBlur = { ( e ) => { e . preventDefault ( ) } }
206+ onClick = { ( ) => {
207+ setLangDropDown ( false )
208+ setDropLang ( v )
209+ } } > { v } </ DropdownItem > ) } ) }
210+ </ Dropdown >
211+ </ div >
212+ : null }
213+ </ div >
214+ : null }
215+ </ Tab >
134216 ) ) }
135217 < NewTabButton
136218 onClick = { ( ) => {
@@ -141,6 +223,14 @@ export default function EditorTabs({
141223 } }
142224 enabled = { value . length <= 4 && ! id }
143225 />
226+ { ! pid ?
227+ < div className = { styles . addAttachmentIconContainer } >
228+ < Button >
229+ < InsertPhotoIcon className = { styles . addAttachmentIcon } />
230+ </ Button >
231+ < span className = { styles . addAttachmentsText } > Add Images</ span >
232+ </ div >
233+ : null }
144234 </ div >
145235
146236 { value . map ( ( v , i , arr ) => (
0 commit comments