-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (65 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
export function submitCode(sourceCode, problemID, argInput) {
return dispatch => {
fetch("http://localhost:3000/submissions?base64_encoded=false&wait=true", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
source_code: sourceCode,
language_id: "35",
problem_id: problemID,
command_line_arguments: argInput
// expected_output: "[0.0]"
})
})
.then(response => response.json())
.then(result => {
console.log(result);
dispatch({
type: "SUBMIT_CODE",
submission_result: {
status: result.status.description,
message: result.message,
stdout: result.stdout,
stderr: result.stderr
}
});
return result;
});
};
}
export function loadProblems(){
return dispatch => {
fetch("http://localhost:3000/problems")
.then(response => response.json())
.then(problems => {
console.log(problems);
dispatch({
type: "LOAD_PROBLEMS",
problems: { ...problems }
})
})
}
}
export function addNewProblem(title, description, args, inputs, outputs, functionName){
return dispatch => {
fetch("http://localhost:3000/problems", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
title: title,
description: description,
arguments: args,
inputs: inputs,
outputs: outputs,
solution_function: functionName
})
})
.then(() => {return dispatch(loadProblems())})
}
}