@@ -2,13 +2,12 @@ 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
+
5
6
compileButton . addEventListener ( "click" , function ( ) {
6
7
const code = editorTextArea . value ;
7
8
8
-
9
9
const data = { "code" : code , "file" : "code.py" } ;
10
10
11
-
12
11
fetch ( 'http://127.0.0.1:30410/build' , {
13
12
method : 'POST' ,
14
13
headers : {
@@ -20,40 +19,31 @@ document.addEventListener("DOMContentLoaded", function() {
20
19
. then ( responseData => {
21
20
console . log ( "Server response:" , responseData ) ;
22
21
23
-
24
- const outputArea = document . getElementById ( "output" ) ;
25
- outputArea . textContent = `\n${ responseData . message } \n\n${ responseData . stdout } \n\n${ responseData . stderr } ` ;
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
+ } ) ;
26
42
} )
27
43
. catch ( error => {
28
44
console . error ( 'Error sending data to endpoint:' , error ) ;
29
45
} ) ;
30
46
} ) ;
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
-
59
47
48
+
49
+ } ) ;
0 commit comments