@@ -2,12 +2,13 @@ document.addEventListener("DOMContentLoaded", function() {
2
2
const compileButton = document . getElementById ( "compile-button" ) ;
3
3
const editorTextArea = document . getElementById ( "editor" ) ;
4
4
const optimizerButton = document . getElementById ( "optimizer-button" ) ;
5
-
6
5
compileButton . addEventListener ( "click" , function ( ) {
7
6
const code = editorTextArea . value ;
8
7
8
+
9
9
const data = { "code" : code , "file" : "code.py" } ;
10
10
11
+
11
12
fetch ( 'http://127.0.0.1:30410/build' , {
12
13
method : 'POST' ,
13
14
headers : {
@@ -19,31 +20,40 @@ document.addEventListener("DOMContentLoaded", function() {
19
20
. then ( responseData => {
20
21
console . log ( "Server response:" , responseData ) ;
21
22
22
- const outputBox = document . getElementById ( "output-box" ) ;
23
- outputBox . textContent = `${ responseData . message } \n\n${ responseData . stdout } \n\n${ responseData . stderr } \n` ;
24
-
25
-
26
- fetch ( 'http://127.0.0.1:30410/optimise' , {
27
- method : 'POST' ,
28
- headers : {
29
- 'Content-Type' : 'application/json'
30
- } ,
31
- body : JSON . stringify ( data )
32
- } )
33
- . then ( response => response . json ( ) )
34
- . then ( optimizedData => {
35
- console . log ( "Optimizer response:" , optimizedData ) ;
36
-
37
- outputBox . textContent += `\nOptimizer Message: ${ optimizedData . message } \n\nOptimized Code:\n${ optimizedData . result } ` ;
38
- } )
39
- . catch ( error => {
40
- console . error ( 'Error fetching optimizer data:' , error ) ;
41
- } ) ;
23
+
24
+ const outputArea = document . getElementById ( "output" ) ;
25
+ outputArea . textContent = `\n${ responseData . message } \n\n${ responseData . stdout } \n\n${ responseData . stderr } ` ;
42
26
} )
43
27
. catch ( error => {
44
28
console . error ( 'Error sending data to endpoint:' , error ) ;
45
29
} ) ;
46
30
} ) ;
31
+ optimizerButton . addEventListener ( "click" , function ( ) {
32
+ const code = editorTextArea . value ;
33
+
34
+ const data = { "code" : code , "file" : "code.py" } ;
35
+
36
+ fetch ( 'http://127.0.0.1:30410/optimise' , {
37
+ method : 'POST' ,
38
+ headers : {
39
+ 'Content-Type' : 'application/json'
40
+ } ,
41
+ body : JSON . stringify ( data )
42
+ } )
43
+ . then ( response => response . json ( ) )
44
+ . then ( responseData => {
45
+ console . log ( "Optimizer response:" , responseData ) ;
46
+
47
+
48
+ const outputArea = document . getElementById ( "output" ) ;
49
+ outputArea . textContent = `\n${ responseData . message } \n\n${ responseData . stdout } \n\n${ responseData . stderr } ` ;
50
+ } )
51
+ . catch ( error => {
52
+ console . error ( 'Error fetching optimizer data:' , error ) ;
53
+ } ) ;
54
+ } ) ;
55
+ } ) ;
56
+
57
+
58
+
47
59
48
-
49
- } ) ;
0 commit comments