Skip to content

Commit 0f3e386

Browse files
committed
Add code running UI
Inform users when code is running
1 parent 992ab6b commit 0f3e386

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Frontend/src/components/collab/CodeSpace.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react'
22
import { Editor } from '@monaco-editor/react'
3-
import { Container, Stack } from 'react-bootstrap'
3+
import { Container, Stack, Spinner } from 'react-bootstrap'
44

5-
const CodeSpace = ({ handleEditorChange, code, language, output }) => {
5+
const CodeSpace = ({ handleEditorChange, loading, code, language, output }) => {
66
return (
77

88
<Stack gap={3} className='h-100'>
@@ -16,7 +16,14 @@ const CodeSpace = ({ handleEditorChange, code, language, output }) => {
1616
/>
1717
<Container style={{ height: '200px', border: '1px solid #ccc', borderRadius: '0.5rem', padding: '1rem', backgroundColor: '#f8f9fa'}}>
1818
<h5>Output</h5>
19-
<p style={{ fontFamily: 'monospace', whiteSpace: 'pre-wrap'}}>{output}</p>
19+
{loading ? (
20+
<div className="d-flex justify-content-center align-items-center" style={{ height: '100%' }}>
21+
<Spinner animation="border" variant="primary" />
22+
<span className="ms-1">Running...</span>
23+
</div>
24+
): (
25+
<p style={{ fontFamily: 'monospace', whiteSpace: 'pre-wrap'}}>{output}</p>
26+
)}
2027
</Container>
2128
</Stack>
2229

Frontend/src/components/collab/CollaborationSpace.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const CollaborationSpace = () => {
2525
const [language, setLanguage] = useState("python") // set default language to python
2626
const [output, setOutput] = useState("")
2727
const [messages, setMessages] = useState([])
28+
const [outputLoading, setOutputLoading] = useState(false)
2829

2930
// use https://emkc.org/api/v2/piston/runtimes to GET other languages
3031
const LANGUAGEVERSIONS = {
@@ -165,6 +166,9 @@ const CollaborationSpace = () => {
165166
};
166167

167168
const handleCodeRun = () => {
169+
170+
setOutputLoading(true);
171+
168172
const code_message = {
169173
"language": language,
170174
"files": [
@@ -177,6 +181,7 @@ const CollaborationSpace = () => {
177181

178182
collabService.getCodeOutput(code_message)
179183
.then(result => {
184+
setOutputLoading(false);
180185
console.log(result.data.run.output)
181186
setOutput(result.data.run.output)
182187
})
@@ -239,7 +244,7 @@ const CollaborationSpace = () => {
239244
<Container fluid style={{ marginTop: '20px' }}>
240245
<Row>
241246
<Col md={8}>
242-
<CodeSpace handleEditorChange={handleEditorChange} code={code} language={language} output={output}/>
247+
<CodeSpace handleEditorChange={handleEditorChange} loading={outputLoading} code={code} language={language} output={output}/>
243248
</Col>
244249
<Col md={4}>
245250
<QuestionDisplay/>

0 commit comments

Comments
 (0)