Ajout d'un timer
parent
20889d9791
commit
6cbc951c59
|
|
@ -31,6 +31,95 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-executor",
|
||||||
|
"futures-io",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-channel"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-core"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-executor"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-task",
|
||||||
|
"futures-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-io"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-macro"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-sink"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-task"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-util"
|
||||||
|
version = "0.3.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"futures-io",
|
||||||
|
"futures-macro",
|
||||||
|
"futures-sink",
|
||||||
|
"futures-task",
|
||||||
|
"memchr",
|
||||||
|
"pin-project-lite",
|
||||||
|
"pin-utils",
|
||||||
|
"slab",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.1.16"
|
version = "0.1.16"
|
||||||
|
|
@ -57,6 +146,18 @@ dependencies = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gloo-timers"
|
||||||
|
version = "0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-core",
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.12.3"
|
version = "0.12.3"
|
||||||
|
|
@ -95,7 +196,10 @@ dependencies = [
|
||||||
name = "kikikoz"
|
name = "kikikoz"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"futures",
|
||||||
"getrandom 0.2.7",
|
"getrandom 0.2.7",
|
||||||
|
"gloo-timers",
|
||||||
|
"js-sys",
|
||||||
"rand",
|
"rand",
|
||||||
"sycamore",
|
"sycamore",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
|
|
@ -122,6 +226,12 @@ dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.13.0"
|
version = "1.13.0"
|
||||||
|
|
@ -134,6 +244,18 @@ version = "1.0.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc"
|
checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-project-lite"
|
||||||
|
version = "0.2.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-utils"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "ppv-lite86"
|
||||||
version = "0.2.16"
|
version = "0.2.16"
|
||||||
|
|
@ -199,6 +321,15 @@ dependencies = [
|
||||||
"rand_core",
|
"rand_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "slab"
|
||||||
|
version = "0.4.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slotmap"
|
name = "slotmap"
|
||||||
version = "1.0.6"
|
version = "1.0.6"
|
||||||
|
|
@ -221,14 +352,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3a3fad8d7500e6f00f7415f3f3b4d7c465b9edce7eaa9f2d725ced0f99fae3c2"
|
checksum = "3a3fad8d7500e6f00f7415f3f3b4d7c465b9edce7eaa9f2d725ced0f99fae3c2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
|
"futures",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"paste",
|
"paste",
|
||||||
"sycamore-core",
|
"sycamore-core",
|
||||||
|
"sycamore-futures",
|
||||||
"sycamore-macro",
|
"sycamore-macro",
|
||||||
"sycamore-reactive",
|
"sycamore-reactive",
|
||||||
"sycamore-web",
|
"sycamore-web",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
|
"wasm-bindgen-futures",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -242,6 +376,18 @@ dependencies = [
|
||||||
"sycamore-reactive",
|
"sycamore-reactive",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sycamore-futures"
|
||||||
|
version = "0.8.0-beta.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "faebade534e638217448ebc6b4cc7a52471ce055a04090e9e628e783bf629e4e"
|
||||||
|
dependencies = [
|
||||||
|
"futures",
|
||||||
|
"sycamore-reactive",
|
||||||
|
"tokio",
|
||||||
|
"wasm-bindgen-futures",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sycamore-macro"
|
name = "sycamore-macro"
|
||||||
version = "0.8.0-beta.7"
|
version = "0.8.0-beta.7"
|
||||||
|
|
@ -294,6 +440,17 @@ dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio"
|
||||||
|
version = "1.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "57aec3cfa4c296db7255446efb4928a6be304b431a806216105542a67b6ca82e"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"once_cell",
|
||||||
|
"pin-project-lite",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
|
|
@ -349,6 +506,18 @@ dependencies = [
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-futures"
|
||||||
|
version = "0.4.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"web-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro"
|
name = "wasm-bindgen-macro"
|
||||||
version = "0.2.81"
|
version = "0.2.81"
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,12 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sycamore = "0.8.0-beta.7"
|
sycamore = { version = "0.8.0-beta.7", features = ["suspense"]}
|
||||||
rand = {version = "0.7", features = ["wasm-bindgen"]}
|
rand = {version = "0.7", features = ["wasm-bindgen"]}
|
||||||
getrandom = { version = "0.2", features = ["js"] }
|
getrandom = { version = "0.2", features = ["js"] }
|
||||||
|
gloo-timers = { version = "0.2.3", features = ["futures"] }
|
||||||
|
js-sys = {version = "0.3"}
|
||||||
|
futures = {version = "0.3"}
|
||||||
|
|
||||||
[dependencies.web-sys]
|
[dependencies.web-sys]
|
||||||
version = "0.3"
|
version = "0.3"
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
wasm-bindgen-cli
|
wasm-bindgen-cli
|
||||||
trunk
|
trunk
|
||||||
nodePackages.sass
|
nodePackages.sass
|
||||||
|
rust-analyzer
|
||||||
|
|
||||||
(rust-bin.stable.latest.default.override {
|
(rust-bin.stable.latest.default.override {
|
||||||
extensions = [ "rust-src" ];
|
extensions = [ "rust-src" ];
|
||||||
|
|
|
||||||
37
src/main.rs
37
src/main.rs
|
|
@ -1,6 +1,10 @@
|
||||||
|
use futures::future;
|
||||||
|
use futures::stream::StreamExt;
|
||||||
|
use gloo_timers::future::IntervalStream;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use sycamore::builder::prelude::*;
|
use sycamore::builder::prelude::*;
|
||||||
|
use sycamore::futures::spawn_local_scoped;
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use sycamore::rt::JsCast;
|
use sycamore::rt::JsCast;
|
||||||
|
|
||||||
|
|
@ -116,6 +120,7 @@ fn ConfigQueue<'a, G: Html>(cx: Scope<'a>, q: QueueProp<'a>) -> View<G> {
|
||||||
.take(15)
|
.take(15)
|
||||||
.map(char::from)
|
.map(char::from)
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
|
|
||||||
create_effect(cx, || {
|
create_effect(cx, || {
|
||||||
if let Ok(p) = prio_str.get().parse::<u8>() {
|
if let Ok(p) = prio_str.get().parse::<u8>() {
|
||||||
queue.priorité.set(p)
|
queue.priorité.set(p)
|
||||||
|
|
@ -189,7 +194,19 @@ fn Queue<'a, G: Html>(cx: Scope<'a>, queue: QueueProp<'a>) -> View<G> {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
sycamore::render(|cx| {
|
sycamore::render(|cx| {
|
||||||
let prochainə = create_signal(cx, String::from("personne encore"));
|
let heure_courante = create_signal(cx, 0.0);
|
||||||
|
let _ = spawn_local_scoped(cx, async {
|
||||||
|
IntervalStream::new(1000)
|
||||||
|
.for_each(|_| {
|
||||||
|
heure_courante.set(js_sys::Date::now());
|
||||||
|
future::ready(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
});
|
||||||
|
|
||||||
|
let date_prise_parole = create_signal(cx, 0.0);
|
||||||
|
let courantə = create_signal(cx, None);
|
||||||
|
// let courantə2 = create_signal(cx, None).clone();
|
||||||
let conf_visible = create_signal(cx, false);
|
let conf_visible = create_signal(cx, false);
|
||||||
let queues = create_signal(
|
let queues = create_signal(
|
||||||
cx,
|
cx,
|
||||||
|
|
@ -238,7 +255,10 @@ fn main() {
|
||||||
//js_sys::alert("coucou");
|
//js_sys::alert("coucou");
|
||||||
let mut queue: ÉtatQueue = queues.get()[queue_courante.get().0].clone();
|
let mut queue: ÉtatQueue = queues.get()[queue_courante.get().0].clone();
|
||||||
match queue.dequeue() {
|
match queue.dequeue() {
|
||||||
Some(p) => prochainə.set(p),
|
Some(p) => {
|
||||||
|
courantə.set(Some(p));
|
||||||
|
date_prise_parole.set(js_sys::Date::now())
|
||||||
|
}
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
for q in queues.get().iter() {
|
for q in queues.get().iter() {
|
||||||
|
|
@ -259,7 +279,7 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
view! { cx,
|
view! { cx,
|
||||||
div(on:keypress= {let mut next = next.clone();
|
div(on:keypress= {let next = next.clone();
|
||||||
move |ev: web_sys::Event| {
|
move |ev: web_sys::Event| {
|
||||||
let event: web_sys::KeyboardEvent = ev.clone().unchecked_into();
|
let event: web_sys::KeyboardEvent = ev.clone().unchecked_into();
|
||||||
if event.key_code() == 13 && event.ctrl_key() {
|
if event.key_code() == 13 && event.ctrl_key() {
|
||||||
|
|
@ -270,7 +290,16 @@ fn main() {
|
||||||
main {
|
main {
|
||||||
h1 { "Kikikoz" }
|
h1 { "Kikikoz" }
|
||||||
p(class="orateurice") {
|
p(class="orateurice") {
|
||||||
"On écoute " (prochainə.get()) "."
|
(
|
||||||
|
match &*courantə.get() {
|
||||||
|
None => "En attente".into(),
|
||||||
|
Some(p) => {
|
||||||
|
let temps_parole = std::time::Duration::from_millis((*heure_courante.get() - *date_prise_parole.get()) as u64);
|
||||||
|
format!("On écoute {} depuis {:2}:{:02}", p, 0, temps_parole.as_secs())
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
br {}
|
br {}
|
||||||
button(on:click=next) { "Suivantə" }
|
button(on:click=next) { "Suivantə" }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue