mirror of
https://github.com/sasjs/server.git
synced 2026-01-15 09:50:06 +00:00
fix(web): autosave and autofocus
This commit is contained in:
@@ -4,7 +4,7 @@ import axios from 'axios'
|
|||||||
import Box from '@mui/material/Box'
|
import Box from '@mui/material/Box'
|
||||||
import { Button, Paper, Stack, Tab } from '@mui/material'
|
import { Button, Paper, Stack, Tab } from '@mui/material'
|
||||||
import { makeStyles } from '@mui/styles'
|
import { makeStyles } from '@mui/styles'
|
||||||
import Editor from '@monaco-editor/react'
|
import Editor, { OnMount } from '@monaco-editor/react'
|
||||||
import { useLocation } from 'react-router-dom'
|
import { useLocation } from 'react-router-dom'
|
||||||
import { TabContext, TabList, TabPanel } from '@mui/lab'
|
import { TabContext, TabList, TabPanel } from '@mui/lab'
|
||||||
|
|
||||||
@@ -23,14 +23,16 @@ const Studio = () => {
|
|||||||
const [fileContent, setFileContent] = useState('')
|
const [fileContent, setFileContent] = useState('')
|
||||||
const [log, setLog] = useState('')
|
const [log, setLog] = useState('')
|
||||||
const [webout, setWebout] = useState('')
|
const [webout, setWebout] = useState('')
|
||||||
|
|
||||||
const [tab, setTab] = React.useState('1')
|
const [tab, setTab] = React.useState('1')
|
||||||
const handleTabChange = (_e: any, newValue: string) => {
|
const handleTabChange = (_e: any, newValue: string) => {
|
||||||
setTab(newValue)
|
setTab(newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
const editorRef = useRef(null)
|
const editorRef = useRef(null as any)
|
||||||
const handleEditorDidMount = (editor: any) => (editorRef.current = editor)
|
const handleEditorDidMount: OnMount = (editor) => {
|
||||||
|
editor.focus()
|
||||||
|
editorRef.current = editor
|
||||||
|
}
|
||||||
|
|
||||||
const getSelection = () => {
|
const getSelection = () => {
|
||||||
const editor = editorRef.current as any
|
const editor = editorRef.current as any
|
||||||
@@ -54,22 +56,33 @@ const Studio = () => {
|
|||||||
.split('>>weboutBEGIN<<')[1]
|
.split('>>weboutBEGIN<<')[1]
|
||||||
.split('>>weboutEND<<')[0]
|
.split('>>weboutEND<<')[0]
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
weboutString = res.data.webout
|
weboutString = res?.data?.webout ?? ''
|
||||||
}
|
}
|
||||||
|
|
||||||
let webout: any
|
let webout: string
|
||||||
try {
|
try {
|
||||||
webout = JSON.parse(weboutString)
|
webout = JSON.stringify(JSON.parse(weboutString), null, 4)
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
webout = weboutString
|
webout = weboutString
|
||||||
}
|
}
|
||||||
|
|
||||||
setWebout(`<pre><code>${JSON.stringify(webout, null, 4)}</code></pre>`)
|
setWebout(`<pre><code>${webout}</code></pre>`)
|
||||||
setTab('2')
|
setTab('2')
|
||||||
})
|
})
|
||||||
.catch((err) => console.log(err))
|
.catch((err) => console.log(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const content = localStorage.getItem('fileContent') ?? ''
|
||||||
|
setFileContent(content)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (fileContent.length) {
|
||||||
|
localStorage.setItem('fileContent', fileContent)
|
||||||
|
}
|
||||||
|
}, [fileContent])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const params = new URLSearchParams(location.search)
|
const params = new URLSearchParams(location.search)
|
||||||
const programPath = params.get('_program')
|
const programPath = params.get('_program')
|
||||||
|
|||||||
Reference in New Issue
Block a user