diff --git a/src/webapp.rs b/src/webapp.rs index 2ecc1c7..5538ddd 100644 --- a/src/webapp.rs +++ b/src/webapp.rs @@ -13,7 +13,7 @@ fn js_bundle() -> Result { NamedFile::open("static/bundle.js").map_err(|_| ()) } -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] struct Input { source: String, } @@ -25,6 +25,7 @@ struct Output { #[post("/input", format = "application/json", data = "")] fn interpreter_input(input: Json) -> Json { + println!("INPUT {:?}", input); let output = Output { text: "test interpreter output".to_string() }; Json(output) } diff --git a/static/index.html b/static/index.html index 5eefd01..6d97528 100644 --- a/static/index.html +++ b/static/index.html @@ -1,6 +1,7 @@ + Schala Metainterpreter Web Evaluator
diff --git a/static/main.jsx b/static/main.jsx index 0d41e1c..15c1433 100644 --- a/static/main.jsx +++ b/static/main.jsx @@ -7,7 +7,7 @@ const serverAddress = "http://localhost:8000"; class CodeArea extends React.Component { constructor(props) { super(props); - this.state = {value: ""}; + this.state = {value: "", lastOutput: null}; this.handleChange = this.handleChange.bind(this); this.submit = this.submit.bind(this); } @@ -17,25 +17,36 @@ class CodeArea extends React.Component { } submit(event) { - /* - console.log("This", this.state.value); + console.log("Event", this.state.value); + const source = this.state.value; + const options = { url: `${serverAddress}/input`, json: true, - body: {source: this.state.value} + body: { source } }; request.post(options, (error, response, body) => { - console.log("resp", response); - console.log("body", body); + this.setState({lastOutput: body.text}) }); - */ + } + + renderOutput() { + if (!this.state.lastOutput) { + return null; + } + return - +
+ + +
+
+ { this.renderOutput() } +
); } }