Made web app a bit more useful
This commit is contained in:
parent
89482e5b5a
commit
29d307ff53
@ -13,7 +13,7 @@ fn js_bundle() -> Result<NamedFile, ()> {
|
|||||||
NamedFile::open("static/bundle.js").map_err(|_| ())
|
NamedFile::open("static/bundle.js").map_err(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct Input {
|
struct Input {
|
||||||
source: String,
|
source: String,
|
||||||
}
|
}
|
||||||
@ -25,6 +25,7 @@ struct Output {
|
|||||||
|
|
||||||
#[post("/input", format = "application/json", data = "<input>")]
|
#[post("/input", format = "application/json", data = "<input>")]
|
||||||
fn interpreter_input(input: Json<Input>) -> Json<Output> {
|
fn interpreter_input(input: Json<Input>) -> Json<Output> {
|
||||||
|
println!("INPUT {:?}", input);
|
||||||
let output = Output { text: "test interpreter output".to_string() };
|
let output = Output { text: "test interpreter output".to_string() };
|
||||||
Json(output)
|
Json(output)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<title>Schala Metainterpreter Web Evaluator</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="main">
|
<div id="main">
|
||||||
|
@ -7,7 +7,7 @@ const serverAddress = "http://localhost:8000";
|
|||||||
class CodeArea extends React.Component {
|
class CodeArea extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {value: ""};
|
this.state = {value: "", lastOutput: null};
|
||||||
this.handleChange = this.handleChange.bind(this);
|
this.handleChange = this.handleChange.bind(this);
|
||||||
this.submit = this.submit.bind(this);
|
this.submit = this.submit.bind(this);
|
||||||
}
|
}
|
||||||
@ -17,25 +17,36 @@ class CodeArea extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
submit(event) {
|
submit(event) {
|
||||||
/*
|
console.log("Event", this.state.value);
|
||||||
console.log("This", this.state.value);
|
const source = this.state.value;
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
url: `${serverAddress}/input`,
|
url: `${serverAddress}/input`,
|
||||||
json: true,
|
json: true,
|
||||||
body: {source: this.state.value}
|
body: { source }
|
||||||
};
|
};
|
||||||
request.post(options, (error, response, body) => {
|
request.post(options, (error, response, body) => {
|
||||||
console.log("resp", response);
|
this.setState({lastOutput: body.text})
|
||||||
console.log("body", body);
|
|
||||||
});
|
});
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
renderOutput() {
|
||||||
|
if (!this.state.lastOutput) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return <textarea readOnly value={ this.state.lastOutput } />;
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (<div>
|
return (<div>
|
||||||
<textarea value={ this.state.value } onChange={this.handleChange}>
|
<div className="input">
|
||||||
</textarea>
|
<textarea value={ this.state.value } onChange={this.handleChange}>
|
||||||
<button onClick={ this.submit }>Run!</button>
|
</textarea>
|
||||||
|
<button onClick={ this.submit }>Run!</button>
|
||||||
|
</div>
|
||||||
|
<div className="output">
|
||||||
|
{ this.renderOutput() }
|
||||||
|
</div>
|
||||||
</div>);
|
</div>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user