Beginning of frontend + recipe editing

(it's a mess)
This commit is contained in:
Greg Burri 2022-12-13 21:01:18 +01:00
parent 642dd8a80c
commit cbe276fc06
16 changed files with 203 additions and 63 deletions

View file

@ -1,4 +1,5 @@
mod utils;
mod handles;
use wasm_bindgen::prelude::*;
use web_sys::console;
@ -22,14 +23,41 @@ pub fn greet(name: &str) {
#[wasm_bindgen(start)]
pub fn main() -> Result<(), JsValue> {
console_error_panic_hook::set_once();
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let body = document.body().expect("document should have a body");
//let body = document.body().expect("document should have a body");
let val = document.create_element("p")?;
val.set_inner_html("Hello from Rust!");
let location = window.location().pathname()?;
let path: Vec<&str> = location.split('/').skip(1).collect();
body.append_child(&val)?;
/*
* Todo:
* [ok] get url (/recipe/edit/{id}) and extract the id
* - Add a handle (event?) to the title field (when edited/changed?):
* - Call (as AJAR) /ron-api/set-title and set the body to a serialized RON of the type common::ron_api::SetTitle
* - Display error message if needed
*/
match path[..] {
["recipe", "edit", id] => {
let id = id.parse::<i64>().unwrap(); // TODO: remove unwrap.
console_log!("recipe edit ID: {}", id);
handles::edit_recipe(&document);
let title_input = document.get_element_by_id("title_field").unwrap();
},
_ => (),
}
//alert(&path);
// TEST
// let val = document.create_element("p")?;
// val.set_inner_html("Hello from Rust!");
// body.append_child(&val)?;
Ok(())
}