@@ -6,8 +6,9 @@ import { getUserFromToken } from '../user/userAvatarBox';
6
6
import QuestionDisplay from './QuestionDisplay' ;
7
7
import Chat from './Chat' ;
8
8
import CollabNavigationBar from './CollabNavigationBar' ;
9
- import CodingSpace from './CodeSpace' ;
9
+ import CodeSpace from './CodeSpace' ;
10
10
import { Container , Row , Col } from 'react-bootstrap' ;
11
+ import collabService from '../../services/collab' ;
11
12
12
13
const CollaborationSpace = ( ) => {
13
14
const navigate = useNavigate ( ) ;
@@ -18,8 +19,17 @@ const CollaborationSpace = () => {
18
19
const [ code , setCode ] = useState ( '' ) ;
19
20
const [ users , setUsers ] = useState ( [ ] ) ; // track users in the room
20
21
const [ userId , setUserId ] = useState ( "" ) ; // current user
22
+ const [ language , setLanguage ] = useState ( "python" ) // set default language to python
23
+ const [ output , setOutput ] = useState ( "" )
24
+
25
+ // use https://emkc.org/api/v2/piston/runtimes to GET other languages
26
+ const LANGUAGEVERSIONS = {
27
+ "python" : "3.10.0" ,
28
+ "java" : "15.0.2" ,
29
+ "c++" : "10.2.0"
30
+ }
21
31
22
- // get the userid only once with useEffect
32
+ { /* Set up websockets for room management on client side, and collaboration for Yjs */ }
23
33
useEffect ( ( ) => {
24
34
const fetchUser = async ( ) => {
25
35
const user = await getUserFromToken ( ) ;
@@ -82,6 +92,8 @@ const CollaborationSpace = () => {
82
92
}
83
93
}
84
94
95
+ { /* Functions to handle interaction with UI elements */ }
96
+
85
97
const handleExit = ( ) => {
86
98
// Notify server 3004 user is leaving
87
99
websocket . send ( JSON . stringify ( { type : 'leaveRoom' , roomId, userId} ) ) ;
@@ -98,6 +110,26 @@ const CollaborationSpace = () => {
98
110
navigate ( "/home" )
99
111
} ;
100
112
113
+ const handleCodeRun = ( ) => {
114
+ const code_message = {
115
+ "language" : language ,
116
+ "files" : [
117
+ {
118
+ "content" : code
119
+ }
120
+ ] ,
121
+ "version" : LANGUAGEVERSIONS [ language ]
122
+ }
123
+
124
+ collabService . getCodeOutput ( code_message )
125
+ . then ( result => {
126
+ console . log ( result . data . run . output )
127
+ setOutput ( result . data . run . output )
128
+ } )
129
+ . catch ( err => console . log ( err ) ) ;
130
+
131
+ }
132
+
101
133
const handleEditorChange = ( value ) => {
102
134
const yText = yDoc . getText ( 'monacoEditor' ) ;
103
135
yText . delete ( 0 , yText . length ) ; // Clear existing content
@@ -106,11 +138,11 @@ const CollaborationSpace = () => {
106
138
107
139
return (
108
140
< div >
109
- < CollabNavigationBar handleExit = { handleExit } users = { users } />
141
+ < CollabNavigationBar handleExit = { handleExit } handleCodeRun = { handleCodeRun } users = { users } setLanguage = { setLanguage } language = { language } />
110
142
< Container fluid style = { { marginTop : '20px' } } >
111
143
< Row >
112
144
< Col md = { 8 } >
113
- < CodingSpace handleEditorChange = { handleEditorChange } code = { code } />
145
+ < CodeSpace handleEditorChange = { handleEditorChange } code = { code } language = { language } output = { output } />
114
146
</ Col >
115
147
< Col md = { 4 } >
116
148
< QuestionDisplay />
0 commit comments