remove some warnings, add configuration pane

master
Florent Becker 2022-04-14 18:24:22 +02:00
parent 0834a86d49
commit 0feca4f8da
7 changed files with 147 additions and 28 deletions

View File

@ -31,7 +31,9 @@ js-sys = "0.3"
[dependencies.web-sys]
version = "0.3"
features = [
'console',
'Document',
'DomTokenList',
'Element',
'HtmlCollection',
'HtmlInputElement',

View File

@ -2,7 +2,7 @@
pkgs.callPackage ./Cargo.nix {
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
lixiangyuan = attrs: {
kikikoz = attrs: {
buildInputs = [ pkgs.wasm-pack ];
};
};

78
flake.lock Normal file
View File

@ -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
}

View File

@ -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; });
};
};
}

View File

@ -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);
</script>
<link rel="stylesheet" href="kikikoz.css"/>
</head>
<body>
<main>
<h1>Kikikoz</h1>
<button>Configuration</button>
<p class="orateurice">
<span id="orateurice" class="personne" onclick="intervalle_orateurice()">Personne</span> <span id="compte"></span> <button onclick="next()">Hop!</button>
</p>
@ -42,6 +46,11 @@
<button onclick='ajoute("queue_b")'>+</button></p>
</section>
</section>
</main>
<aside id="configuration">
<h2>Configuration</h2>
<p> Pas d'options pour le moment, revenez dans une version ultérieure.</p>
</aside>
</body>
</html>

View File

@ -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%;
}

View File

@ -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")) {
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();
}
}