import React, { useEffect, useRef, useState } from 'react' import axios from 'axios' import Box from '@mui/material/Box' import { Button, Paper, Stack, Tab } from '@mui/material' import { makeStyles } from '@mui/styles' import Editor, { OnMount } from '@monaco-editor/react' import { useLocation } from 'react-router-dom' import { TabContext, TabList, TabPanel } from '@mui/lab' const useStyles = makeStyles(() => ({ root: { fontSize: '1rem', color: 'gray', '&.Mui-selected': { color: 'black' } } })) const Studio = () => { const location = useLocation() const [fileContent, setFileContent] = useState('') const [log, setLog] = useState('') const [webout, setWebout] = useState('') const [tab, setTab] = React.useState('1') const handleTabChange = (_e: any, newValue: string) => { setTab(newValue) } const editorRef = useRef(null as any) const handleEditorDidMount: OnMount = (editor) => { editor.focus() editorRef.current = editor } const getSelection = () => { const editor = editorRef.current as any const selection = editor?.getModel().getValueInRange(editor?.getSelection()) return selection ?? '' } const handleRunBtnClick = () => runCode(getSelection() || fileContent) const runCode = (code: string) => { axios .post(`/SASjsApi/code/execute`, { code }) .then((res: any) => { setLog(`
${res?.data?.log}${webout}`)
setTab('2')
})
.catch((err) => console.log(err))
}
useEffect(() => {
const content = localStorage.getItem('fileContent') ?? ''
setFileContent(content)
}, [])
useEffect(() => {
if (fileContent.length) {
localStorage.setItem('fileContent', fileContent)
}
}, [fileContent])
useEffect(() => {
const params = new URLSearchParams(location.search)
const programPath = params.get('_program')
if (programPath?.length)
axios
.get(`/SASjsApi/drive/file?filePath=${programPath}`)
.then((res: any) => setFileContent(res.data.fileContent))
.catch((err) => console.log(err))
}, [location.search])
const classes = useStyles()
return (
<>