diff --git a/Cargo.toml b/Cargo.toml index ff24bf7..a8e4be9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,9 @@ js-sys = "0.3" [dependencies.web-sys] version = "0.3" features = [ + 'console', 'Document', + 'DomTokenList', 'Element', 'HtmlCollection', 'HtmlInputElement', diff --git a/default.nix b/default.nix index 508abb9..d3f87a2 100644 --- a/default.nix +++ b/default.nix @@ -2,7 +2,7 @@ pkgs.callPackage ./Cargo.nix { defaultCrateOverrides = pkgs.defaultCrateOverrides // { - lixiangyuan = attrs: { + kikikoz = attrs: { buildInputs = [ pkgs.wasm-pack ]; }; }; diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..bb1c407 --- /dev/null +++ b/flake.lock @@ -0,0 +1,78 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1637014545, + "narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1649809588, + "narHash": "sha256-f6sgDj9A8FXTVyA2zkxA66YX+j6BftxE9VHTeIMhEKE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ff9efb0724de5ae0f9db9df2debefced7eb1571d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1637453606, + "narHash": "sha256-Gy6cwUswft9xqsjWxFYEnx/63/qzaFUwatcbV5GF/GQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8afc4e543663ca0a6a4f496262cd05233737e732", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1649903781, + "narHash": "sha256-m+3EZo0a4iS8IwHQhkM/riPuFpu76505xKqmN9j5O+E=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "e45696bedc4a13a5970376b8fc09660fdd0e6f6c", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index 289b8de..fadced7 100644 --- a/flake.nix +++ b/flake.nix @@ -14,8 +14,7 @@ inherit system; overlays = [ rust-overlay.overlay ]; }; - in (({ pkgs, ... }: - pkgs.mkShell { + in pkgs.mkShell { buildInputs = with pkgs; [ cargo cargo-watch @@ -31,6 +30,6 @@ ]; shellHook = ""; - }) { pkgs = pkgs; }); + }; }; } diff --git a/index.html b/index.html index 7a21594..05bde48 100644 --- a/index.html +++ b/index.html @@ -13,12 +13,16 @@ window.ajoute = ajoute; window.ajoute_kp = ajoute_kp; window.next = next; + window.intervalle_orateurice = intervalle_orateurice; window.setInterval(intervalle_orateurice, 1000); -

Kikikoz

+
+

Kikikoz

+ +

Personne

@@ -42,6 +46,11 @@

+
+ diff --git a/kikikoz.css b/kikikoz.css index e56ffe0..5705b56 100644 --- a/kikikoz.css +++ b/kikikoz.css @@ -1,5 +1,6 @@ body { background-color: aliceblue; + display: flex; } p.orateurice { @@ -7,6 +8,10 @@ p.orateurice { text-align: center; } +li.dernier_arrive { + font-style: italic; +} + .personne { color: darkgrey; } @@ -43,3 +48,15 @@ section#queues { h1 { text-align: center; } + +main { + flex-grow: 1; +} + +aside#configuration { + max-width: 30%; + background-color: lightgrey; + padding: 15px; + border-radius: 5px; + height: 100%; +} diff --git a/src/lib.rs b/src/lib.rs index d4d1cb0..cf2f366 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -mod utils; - use js_sys::Date; use rand::prelude::*; use wasm_bindgen::prelude::*; @@ -16,29 +14,37 @@ extern "C" { fn alert(s: &str); } +fn le_document() -> web_sys::Document { + let window = web_sys::window().expect("pas de window"); + window.document().expect("pas_de_document") +} + #[wasm_bindgen] pub fn intervalle_orateurice() { let document = le_document(); let now: f64 = Date::new_0().get_time(); - let prochain = document.get_element_by_id("orateurice").expect("blu"); - let compte = document.get_element_by_id("compte").expect("blaou"); - match js_sys::Reflect::get(&prochain, &JsValue::from("debut")) { - Err(_) => return, - Ok(date_debut) => { - let date_debut = date_debut.as_f64().expect("tut tut"); - let diff = ((now - date_debut) / 1000.0) as u64; - let sec = diff % 60; - let min = diff / 60; - compte.set_inner_html(&format!("{}:{:02}", min, sec)); - } + let prochain = document + .get_element_by_id("orateurice") + .expect("pas de prochain"); + let compte = document.get_element_by_id("compte"); + match compte { + None => return, + Some(compte) => match js_sys::Reflect::get(&prochain, &JsValue::from("debut")) { + Err(_) => return, + Ok(date_debut) => { + if date_debut == JsValue::UNDEFINED { + return; + }; + let date_debut = date_debut.as_f64().expect("tut tut"); + let diff = ((now - date_debut) / 1000.0) as u64; + let sec = diff % 60; + let min = diff / 60; + compte.set_inner_html(&format!("{}:{:02}", min, sec)); + } + }, } } -fn le_document() -> web_sys::Document { - let window = web_sys::window().expect("no global `window` exists"); - window.document().expect("should have a document on window") -} - #[wasm_bindgen] pub fn next() { let document = le_document(); @@ -66,12 +72,13 @@ pub fn next() { let nom_prochain = li.text_content().expect(""); let temps_debut = Date::new_0().get_time(); prochain.set_text_content(Some(nom_prochain.as_str())); - js_sys::Reflect::set( + let _ = js_sys::Reflect::set( &prochain, &JsValue::from("debut"), &JsValue::from(temps_debut), - ); - li.parent_element().expect("").remove_child(&li); + ) + .unwrap(); + li.parent_element().expect("").remove_child(&li).unwrap(); prochain.set_class_name(""); } None => { @@ -113,12 +120,19 @@ pub fn ajoute(id: &str) { let n = lis.length(); let mut rng = thread_rng(); let k = rng.gen_range(0, n + 1); + let old_new_lis = document.get_elements_by_class_name("dernier_arrive"); + for i in 0..old_new_lis.length() { + if let Some(li) = old_new_lis.item(i) { + li.class_list().remove_1("dernier_arrive").unwrap(); + } + } let new_li = document.create_element("li").unwrap(); new_li.set_inner_html(&content); + new_li.set_class_name("dernier_arrive"); if k == n { - ol.append_child(&new_li); + ol.append_child(&new_li).unwrap(); } else { let li = lis.item(k).unwrap(); - li.after_with_node_1(&new_li); + li.after_with_node_1(&new_li).unwrap(); } }