From b9383f26bb47320fb71a4d09e8ff73c3b5d4e73d Mon Sep 17 00:00:00 2001 From: Filipp Samoilov Date: Thu, 5 May 2022 12:23:15 +0300 Subject: [PATCH 01/14] Init front-end --- front-end/Cargo.toml | 8 ++++++++ front-end/src/main.rs | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 front-end/Cargo.toml create mode 100644 front-end/src/main.rs diff --git a/front-end/Cargo.toml b/front-end/Cargo.toml new file mode 100644 index 0000000..235cc28 --- /dev/null +++ b/front-end/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "front-end" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/front-end/src/main.rs b/front-end/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/front-end/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} From 569d99519a04517d159aa2b99b7d224bcda4a38e Mon Sep 17 00:00:00 2001 From: Filipp Samoilov Date: Thu, 5 May 2022 17:54:02 +0300 Subject: [PATCH 02/14] Ignore target and dist directories --- front-end/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 front-end/.gitignore diff --git a/front-end/.gitignore b/front-end/.gitignore new file mode 100644 index 0000000..4f96631 --- /dev/null +++ b/front-end/.gitignore @@ -0,0 +1,2 @@ +/target +/dist From 935f166515ba430f557a0a5332ecc21e73dc1aaa Mon Sep 17 00:00:00 2001 From: Filipp Samoilov Date: Thu, 5 May 2022 17:55:02 +0300 Subject: [PATCH 03/14] Add yew hello world --- front-end/Cargo.lock | 1155 +++++++++++++++++++++++++++++++++++++++++ front-end/Cargo.toml | 6 +- front-end/index.html | 0 front-end/src/main.rs | 11 +- 4 files changed, 1169 insertions(+), 3 deletions(-) create mode 100644 front-end/Cargo.lock create mode 100644 front-end/index.html diff --git a/front-end/Cargo.lock b/front-end/Cargo.lock new file mode 100644 index 0000000..b4bb353 --- /dev/null +++ b/front-end/Cargo.lock @@ -0,0 +1,1155 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "boolinator" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfa8873f51c92e232f9bac4065cddef41b714152812bfc5f7672ba16d6ef8cd9" + +[[package]] +name = "bumpalo" +version = "3.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "encoding_rs" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "fastrand" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +dependencies = [ + "instant", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "front-end" +version = "0.1.0" +dependencies = [ + "reqwest", + "serde", + "yew", + "yew-hooks", +] + +[[package]] +name = "futures-channel" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" + +[[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-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "gloo" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23947965eee55e3e97a5cd142dd4c10631cc349b48cecca0ed230fd296f568cd" +dependencies = [ + "gloo-console", + "gloo-dialogs", + "gloo-events", + "gloo-file", + "gloo-render", + "gloo-storage", + "gloo-timers", + "gloo-utils", +] + +[[package]] +name = "gloo-console" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3907f786f65bbb4f419e918b0c5674175ef1c231ecda93b2dbd65fd1e8882637" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gloo-dialogs" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67062364ac72d27f08445a46cab428188e2e224ec9e37efdba48ae8c289002e6" +dependencies = [ + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gloo-events" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b107f8abed8105e4182de63845afcc7b69c098b7852a813ea7462a320992fc" +dependencies = [ + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gloo-file" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa5d6084efa4a2b182ef3a8649cb6506cb4843f22cf907c6e0a799944248ae90" +dependencies = [ + "gloo-events", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gloo-render" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd9306aef67cfd4449823aadcd14e3958e0800aa2183955a309112a84ec7764" +dependencies = [ + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gloo-storage" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1caa4ba51c99de680dee3ad99c32ca45e9f13311be72079154d222c3f9a6b6f5" +dependencies = [ + "gloo-utils", + "js-sys", + "serde", + "serde_json", + "thiserror", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gloo-timers" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "gloo-utils" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c0bbef55e98d946adbd89f3c65a497cf9adb995a73b99573f30180e8813ab21" +dependencies = [ + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "h2" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] +name = "http" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "ipnet" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" + +[[package]] +name = "itoa" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" + +[[package]] +name = "js-sys" +version = "0.3.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.125" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mio" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "wasi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + +[[package]] +name = "native-tls" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "ntapi" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" +dependencies = [ + "winapi", +] + +[[package]] +name = "once_cell" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" + +[[package]] +name = "openssl" +version = "0.10.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5fd19fb3e0a8191c1e34935718976a3e70c112ab9a24af6d7cadccd9d90bc0" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[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]] +name = "pkg-config" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec757218438d5fda206afc041538b2f6d889286160d649a86a24d37e1235afd1" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +dependencies = [ + "bitflags", +] + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "reqwest" +version = "0.11.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "native-tls", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "ryu" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" + +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi", +] + +[[package]] +name = "scoped-tls-hkt" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e9d7eaddb227e8fbaaa71136ae0e1e913ca159b86c7da82f3e8f0044ad3a63" + +[[package]] +name = "security-framework" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "slab" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" + +[[package]] +name = "socket2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "1.0.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ff7c592601f11445996a06f8ad0c27f094a58857c2f89e97974ab9235b92c52" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "thiserror" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tokio" +version = "1.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce653fb475565de9f6fb0614b28bca8df2c430c0cf84bcd9c843f15de5414cc" +dependencies = [ + "bytes", + "libc", + "memchr", + "mio", + "once_cell", + "pin-project-lite", + "socket2", + "winapi", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + +[[package]] +name = "tracing" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "unicode-bidi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-xid" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" +dependencies = [ + "cfg-if", + "serde", + "serde_json", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" + +[[package]] +name = "web-sys" +version = "0.3.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + +[[package]] +name = "yew" +version = "0.19.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a1ccb53e57d3f7d847338cf5758befa811cabe207df07f543c06f502f9998cd" +dependencies = [ + "console_error_panic_hook", + "gloo", + "gloo-utils", + "indexmap", + "js-sys", + "scoped-tls-hkt", + "slab", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "yew-macro", +] + +[[package]] +name = "yew-hooks" +version = "0.1.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fa359dd6d6435dcfd13ea191701ac1df4d55eb8660b71ca24db81f005947cec" +dependencies = [ + "gloo", + "js-sys", + "log", + "serde", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "yew", +] + +[[package]] +name = "yew-macro" +version = "0.19.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fab79082b556d768d6e21811869c761893f0450e1d550a67892b9bce303b7bb" +dependencies = [ + "boolinator", + "lazy_static", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] diff --git a/front-end/Cargo.toml b/front-end/Cargo.toml index 235cc28..72c4f8d 100644 --- a/front-end/Cargo.toml +++ b/front-end/Cargo.toml @@ -3,6 +3,8 @@ name = "front-end" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] +reqwest = "0.11.10" +serde = { version = "1.0.137", features = ["derive"] } +yew = "0.19.3" +yew-hooks = "0.1.54" diff --git a/front-end/index.html b/front-end/index.html new file mode 100644 index 0000000..e69de29 diff --git a/front-end/src/main.rs b/front-end/src/main.rs index e7a11a9..aa06b32 100644 --- a/front-end/src/main.rs +++ b/front-end/src/main.rs @@ -1,3 +1,12 @@ +use yew::{function_component, html}; + +#[function_component(App)] +fn app() -> yew::Html { + html! { +

{ "Hi!" }

+ } +} + fn main() { - println!("Hello, world!"); + yew::start_app::(); } From f4575b24e0df38fd1ecf4e81a899dcb355674031 Mon Sep 17 00:00:00 2001 From: Filipp Samoilov Date: Thu, 5 May 2022 17:58:20 +0300 Subject: [PATCH 04/14] Add lto for release --- front-end/Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/front-end/Cargo.toml b/front-end/Cargo.toml index 72c4f8d..6e1b932 100644 --- a/front-end/Cargo.toml +++ b/front-end/Cargo.toml @@ -8,3 +8,6 @@ reqwest = "0.11.10" serde = { version = "1.0.137", features = ["derive"] } yew = "0.19.3" yew-hooks = "0.1.54" + +[profile.release] +lto = true From 4c20109f0b17946f6dedfa73fc27efc64c461c7b Mon Sep 17 00:00:00 2001 From: Filipp Samoilov Date: Thu, 5 May 2022 17:58:38 +0300 Subject: [PATCH 05/14] Add wasm-opt z directive for trunk --- front-end/index.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/front-end/index.html b/front-end/index.html index e69de29..204c47d 100644 --- a/front-end/index.html +++ b/front-end/index.html @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file From 9ef5e0b630cae08871d2a02d61ef83888d2961c9 Mon Sep 17 00:00:00 2001 From: Filipp Samoilov Date: Thu, 5 May 2022 18:51:42 +0300 Subject: [PATCH 06/14] WIP --- front-end/Cargo.lock | 24 ++++++++++++++ front-end/Cargo.toml | 9 ++++- front-end/src/main.rs | 65 ++++++++++++++++++++++++++++++++++--- front-end/src/server_api.rs | 25 ++++++++++++++ 4 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 front-end/src/server_api.rs diff --git a/front-end/Cargo.lock b/front-end/Cargo.lock index b4bb353..23d0a72 100644 --- a/front-end/Cargo.lock +++ b/front-end/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "anyhow" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" + [[package]] name = "autocfg" version = "1.1.0" @@ -129,8 +135,15 @@ dependencies = [ name = "front-end" version = "0.1.0" dependencies = [ + "anyhow", + "console_error_panic_hook", + "log", "reqwest", "serde", + "serde_json", + "wasm-bindgen-futures", + "wasm-logger", + "web-sys", "yew", "yew-hooks", ] @@ -1064,6 +1077,17 @@ version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" +[[package]] +name = "wasm-logger" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "074649a66bb306c8f2068c9016395fa65d8e08d2affcbf95acf3c24c3ab19718" +dependencies = [ + "log", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "web-sys" version = "0.3.57" diff --git a/front-end/Cargo.toml b/front-end/Cargo.toml index 6e1b932..9386729 100644 --- a/front-end/Cargo.toml +++ b/front-end/Cargo.toml @@ -4,8 +4,15 @@ version = "0.1.0" edition = "2021" [dependencies] -reqwest = "0.11.10" +anyhow = "1.0.57" +console_error_panic_hook = "0.1.7" +log = "0.4.17" +reqwest = {version="0.11.10", features=["json"]} serde = { version = "1.0.137", features = ["derive"] } +serde_json = "1.0.81" +wasm-bindgen-futures = "0.4.30" +wasm-logger = "0.2.0" +web-sys = { version = "0.3.57", features = ["FocusEvent"] } yew = "0.19.3" yew-hooks = "0.1.54" diff --git a/front-end/src/main.rs b/front-end/src/main.rs index aa06b32..720465f 100644 --- a/front-end/src/main.rs +++ b/front-end/src/main.rs @@ -1,12 +1,67 @@ -use yew::{function_component, html}; +mod server_api; -#[function_component(App)] -fn app() -> yew::Html { - html! { -

{ "Hi!" }

+use server_api::LoginResponse; +use yew::{function_component, html, use_state, Html, Callback, Component}; + +use log::*; +use serde_json::json; +use web_sys::FocusEvent; +use yew_hooks::use_async; + +enum Status { + NotLoggedIn, + LoggedIn { jwt: String }, +} + +struct App; + +impl Component for App { + type Message = (); + + type Properties = (); + + fn create(ctx: &yew::Context) -> Self { + App + } + + fn view(&self, ctx: &yew::Context) -> Html { + let onsubmit = Callback::from(|focus_event: FocusEvent| { + focus_event.prevent_default(); + + wasm_bindgen_futures::spawn_local(login("daniil", "hello")); + + }); + html! { +
+
+
+
+
+ +
+ } } } + +async fn login(username: &str, password: &str) { + let response: LoginResponse = reqwest::Client::new() + .post("http://localhost:8080/login") + .json(&json!({ + "name": "daniil", + "password": "world" + })) + .send() + .await + .unwrap() + .json() + .await + .unwrap(); + + info!("{response:?}"); +} fn main() { + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); + wasm_logger::init(wasm_logger::Config::default()); yew::start_app::(); } diff --git a/front-end/src/server_api.rs b/front-end/src/server_api.rs new file mode 100644 index 0000000..cabddbd --- /dev/null +++ b/front-end/src/server_api.rs @@ -0,0 +1,25 @@ +#![allow(non_snake_case, non_camel_case_types)] + +use serde::Deserialize; + +#[derive(Deserialize)] +#[allow(non_camel_case_types)] +pub enum GameSessionStatus { + Created, + Player_1_Turn, + Player_2_Turn, + Player_1_Won, + Player_2_Won, +} + +#[derive(Deserialize)] +#[serde(tag = "_type")] +pub enum Message { + #[serde(rename = "status")] + GameStatusUpdate { newStatus: GameSessionStatus }, +} + +#[derive(Deserialize, Clone, Debug)] +pub struct LoginResponse { + jwt: String, +} From b875dc9b35e3d828c39685e4518e3b44026635ad Mon Sep 17 00:00:00 2001 From: Filipp Samoilov Date: Thu, 5 May 2022 19:33:04 +0300 Subject: [PATCH 07/14] Create websocket connection --- front-end/src/main.rs | 81 ++++++++++++++++++++++++++----------- front-end/src/server_api.rs | 2 +- 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/front-end/src/main.rs b/front-end/src/main.rs index 720465f..7ed2c8d 100644 --- a/front-end/src/main.rs +++ b/front-end/src/main.rs @@ -1,50 +1,85 @@ mod server_api; use server_api::LoginResponse; -use yew::{function_component, html, use_state, Html, Callback, Component}; +use yew::{ + function_component, html, html::Scope, use_state, Callback, Component, Html, Properties, +}; use log::*; use serde_json::json; use web_sys::FocusEvent; -use yew_hooks::use_async; +use yew_hooks::{use_async, use_web_socket}; -enum Status { - NotLoggedIn, - LoggedIn { jwt: String }, +enum AppMsg { + SuccessfulLogin { jwt: String }, } -struct App; +struct App { + jwt: Option, +} impl Component for App { - type Message = (); + type Message = AppMsg; type Properties = (); - fn create(ctx: &yew::Context) -> Self { - App + fn create(_ctx: &yew::Context) -> Self { + App { jwt: None } + } + + fn update(&mut self, _ctx: &yew::Context, msg: Self::Message) -> bool { + match msg { + AppMsg::SuccessfulLogin { jwt } => self.jwt = Some(jwt), + } + true } fn view(&self, ctx: &yew::Context) -> Html { - let onsubmit = Callback::from(|focus_event: FocusEvent| { + let link = ctx.link().clone(); + let onsubmit = Callback::once(|focus_event: FocusEvent| { focus_event.prevent_default(); - - wasm_bindgen_futures::spawn_local(login("daniil", "hello")); - + + wasm_bindgen_futures::spawn_local(login("daniil", "hello", link)); }); - html! { -
-
-
-
-
- -
+ if let Some(jwt) = &self.jwt { + html! { + + } + } else { + html! { +
+
+
+
+
+ +
+ } } } } +#[derive(Properties, PartialEq)] +struct ConnectionProps { + jwt: String, +} + +#[function_component(Connection)] +fn connection(props: &ConnectionProps) -> Html { + let ws = use_web_socket("ws://localhost:8080/web-socket".to_string()); + ws.send( + json!({ + "_type": "jwt", + "jwt": &format!("Bearer {}", props.jwt) + }) + .to_string(), + ); + html!( +

{"connection"}

+ ) +} -async fn login(username: &str, password: &str) { +async fn login(username: &str, password: &str, link: Scope) { let response: LoginResponse = reqwest::Client::new() .post("http://localhost:8080/login") .json(&json!({ @@ -58,7 +93,7 @@ async fn login(username: &str, password: &str) { .await .unwrap(); - info!("{response:?}"); + link.send_message(AppMsg::SuccessfulLogin { jwt: response.jwt }); } fn main() { std::panic::set_hook(Box::new(console_error_panic_hook::hook)); diff --git a/front-end/src/server_api.rs b/front-end/src/server_api.rs index cabddbd..2d983d6 100644 --- a/front-end/src/server_api.rs +++ b/front-end/src/server_api.rs @@ -21,5 +21,5 @@ pub enum Message { #[derive(Deserialize, Clone, Debug)] pub struct LoginResponse { - jwt: String, + pub jwt: String, } From d086d03c551c12d40b702a721bb38b4c4b560738 Mon Sep 17 00:00:00 2001 From: Filipp Samoilov Date: Thu, 5 May 2022 21:41:15 +0300 Subject: [PATCH 08/14] Add instructions for starting server and client --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 2ce41e8..691057b 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,18 @@ STournament is a turn based multiplayer card game. This project is a backend server for the game. Work in progress! +## Dev + +start server +```bash +SPRING_PROFILES_ACTIVE=test-data ./gradlew bootRun +``` + +start client +```bash +trunk serve --port 8081 --open front-end/index.html +``` + [Link to the web client](https://github.com/denolia/startournament-client) ![image](docs/img/Screenshot1.png) From 5f487d6d6968efcea9878ef115c045e4da3970f0 Mon Sep 17 00:00:00 2001 From: Filipp Samoilov Date: Fri, 6 May 2022 11:10:21 +0300 Subject: [PATCH 09/14] --wip-- [skip ci] --- front-end/Cargo.lock | 754 ++++++++++-------------------------- front-end/Cargo.toml | 8 +- front-end/src/main.rs | 110 +++--- front-end/src/server_api.rs | 78 +++- front-end/src/utils.rs | 9 + 5 files changed, 344 insertions(+), 615 deletions(-) create mode 100644 front-end/src/utils.rs diff --git a/front-end/Cargo.lock b/front-end/Cargo.lock index 23d0a72..43aefa7 100644 --- a/front-end/Cargo.lock +++ b/front-end/Cargo.lock @@ -2,11 +2,35 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "anyhow" version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" +dependencies = [ + "backtrace", +] + +[[package]] +name = "anymap2" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d301b3b94cb4b2f23d7917810addbbaff90738e0ca2be692bd027e70d7e0330c" [[package]] name = "autocfg" @@ -15,16 +39,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] -name = "base64" -version = "0.13.0" +name = "backtrace" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] [[package]] -name = "bitflags" -version = "1.3.2" +name = "bincode" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] [[package]] name = "boolinator" @@ -38,12 +74,6 @@ version = "3.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" -[[package]] -name = "bytes" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" - [[package]] name = "cc" version = "1.0.73" @@ -66,61 +96,12 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" - -[[package]] -name = "encoding_rs" -version = "0.8.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "fastrand" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" -dependencies = [ - "instant", -] - [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.0.1" @@ -137,10 +118,12 @@ version = "0.1.0" dependencies = [ "anyhow", "console_error_panic_hook", + "futures", + "gloo 0.7.0", "log", - "reqwest", "serde", "serde_json", + "wasm-bindgen", "wasm-bindgen-futures", "wasm-logger", "web-sys", @@ -148,6 +131,21 @@ dependencies = [ "yew-hooks", ] +[[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" @@ -155,6 +153,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -163,6 +162,34 @@ 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" @@ -181,12 +208,24 @@ 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]] +name = "gimli" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" + [[package]] name = "gloo" version = "0.4.2" @@ -203,6 +242,25 @@ dependencies = [ "gloo-utils", ] +[[package]] +name = "gloo" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03e691526c3972d1fda35453f6df29925edea014dc75a2dede7661527e9439f0" +dependencies = [ + "gloo-console", + "gloo-dialogs", + "gloo-events", + "gloo-file", + "gloo-history", + "gloo-net", + "gloo-render", + "gloo-storage", + "gloo-timers", + "gloo-utils", + "gloo-worker", +] + [[package]] name = "gloo-console" version = "0.2.1" @@ -247,6 +305,42 @@ dependencies = [ "web-sys", ] +[[package]] +name = "gloo-history" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81af52c0d31e86242eecefe1ed4d066deb79cfb80f9f7da0847fac417396bfe" +dependencies = [ + "gloo-events", + "gloo-utils", + "serde", + "serde-wasm-bindgen", + "serde_urlencoded", + "thiserror", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gloo-net" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6d37f728c2b2b8c568bd2efb34ce9087e347c182db68f101a969b4fe23054d5" +dependencies = [ + "futures-channel", + "futures-core", + "futures-sink", + "gloo-utils", + "js-sys", + "pin-project", + "serde", + "serde_json", + "thiserror", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "gloo-render" version = "0.1.1" @@ -294,22 +388,20 @@ dependencies = [ ] [[package]] -name = "h2" -version = "0.3.13" +name = "gloo-worker" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +checksum = "7c843b9a46d07485026f030be7bd008580a12a2920fea837745a440a3b0c97cb" dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", + "anymap2", + "bincode", + "gloo-console", + "gloo-utils", + "js-sys", + "serde", "slab", - "tokio", - "tokio-util", - "tracing", + "wasm-bindgen", + "web-sys", ] [[package]] @@ -318,88 +410,6 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -[[package]] -name = "http" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" - -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - -[[package]] -name = "hyper" -version = "0.14.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - -[[package]] -name = "idna" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "indexmap" version = "1.8.1" @@ -410,21 +420,6 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "ipnet" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" - [[package]] name = "itoa" version = "1.0.1" @@ -474,118 +469,49 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] -name = "mime" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - -[[package]] -name = "mio" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9" -dependencies = [ - "libc", - "log", - "miow", - "ntapi", - "wasi", - "winapi", -] - -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", -] - -[[package]] -name = "native-tls" -version = "0.2.10" +name = "miniz_oxide" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082" dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", + "adler", ] [[package]] -name = "ntapi" -version = "0.3.7" +name = "object" +version = "0.28.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" +checksum = "40bec70ba014595f99f7aa110b84331ffe1ee9aece7fe6f387cc7e3ecda4d456" dependencies = [ - "winapi", + "memchr", ] [[package]] -name = "once_cell" -version = "1.10.0" +name = "percent-encoding" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] -name = "openssl" -version = "0.10.40" +name = "pin-project" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e" +checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e" dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", + "pin-project-internal", ] [[package]] -name = "openssl-macros" -version = "0.1.0" +name = "pin-project-internal" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5fd19fb3e0a8191c1e34935718976a3e70c112ab9a24af6d7cadccd9d90bc0" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "percent-encoding" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" - [[package]] name = "pin-project-lite" version = "0.2.9" @@ -598,12 +524,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -647,58 +567,10 @@ dependencies = [ ] [[package]] -name = "redox_syscall" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" -dependencies = [ - "bitflags", -] - -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - -[[package]] -name = "reqwest" -version = "0.11.10" +name = "rustc-demangle" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb" -dependencies = [ - "base64", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-tls", - "ipnet", - "js-sys", - "lazy_static", - "log", - "mime", - "native-tls", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-native-tls", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" [[package]] name = "ryu" @@ -706,16 +578,6 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" -[[package]] -name = "schannel" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" -dependencies = [ - "lazy_static", - "winapi", -] - [[package]] name = "scoped-tls-hkt" version = "0.1.2" @@ -723,35 +585,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2e9d7eaddb227e8fbaaa71136ae0e1e913ca159b86c7da82f3e8f0044ad3a63" [[package]] -name = "security-framework" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.6.1" +name = "serde" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" dependencies = [ - "core-foundation-sys", - "libc", + "serde_derive", ] [[package]] -name = "serde" -version = "1.0.137" +name = "serde-wasm-bindgen" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +checksum = "618365e8e586c22123d692b72a7d791d5ee697817b65a218cdf12a98870af0f7" dependencies = [ - "serde_derive", + "fnv", + "js-sys", + "serde", + "wasm-bindgen", ] [[package]] @@ -794,16 +645,6 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" -[[package]] -name = "socket2" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "syn" version = "1.0.92" @@ -815,20 +656,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "tempfile" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" -dependencies = [ - "cfg-if", - "fastrand", - "libc", - "redox_syscall", - "remove_dir_all", - "winapi", -] - [[package]] name = "thiserror" version = "1.0.31" @@ -849,166 +676,18 @@ dependencies = [ "syn", ] -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" - -[[package]] -name = "tokio" -version = "1.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dce653fb475565de9f6fb0614b28bca8df2c430c0cf84bcd9c843f15de5414cc" -dependencies = [ - "bytes", - "libc", - "memchr", - "mio", - "once_cell", - "pin-project-lite", - "socket2", - "winapi", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", -] - -[[package]] -name = "tower-service" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" - -[[package]] -name = "tracing" -version = "0.1.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" -dependencies = [ - "cfg-if", - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - -[[package]] -name = "unicode-bidi" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" - -[[package]] -name = "unicode-normalization" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-xid" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" -[[package]] -name = "url" -version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" -dependencies = [ - "form_urlencoded", - "idna", - "matches", - "percent-encoding", -] - -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "wasm-bindgen" version = "0.2.80" @@ -1098,37 +777,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] - [[package]] name = "yew" version = "0.19.3" @@ -1136,7 +784,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a1ccb53e57d3f7d847338cf5758befa811cabe207df07f543c06f502f9998cd" dependencies = [ "console_error_panic_hook", - "gloo", + "gloo 0.4.2", "gloo-utils", "indexmap", "js-sys", @@ -1154,7 +802,7 @@ version = "0.1.54" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fa359dd6d6435dcfd13ea191701ac1df4d55eb8660b71ca24db81f005947cec" dependencies = [ - "gloo", + "gloo 0.4.2", "js-sys", "log", "serde", diff --git a/front-end/Cargo.toml b/front-end/Cargo.toml index 9386729..74e3fc3 100644 --- a/front-end/Cargo.toml +++ b/front-end/Cargo.toml @@ -4,15 +4,17 @@ version = "0.1.0" edition = "2021" [dependencies] -anyhow = "1.0.57" +anyhow = { version = "1.0.57", features = ["backtrace"] } console_error_panic_hook = "0.1.7" +futures = "0.3.21" +gloo = "0.7.0" log = "0.4.17" -reqwest = {version="0.11.10", features=["json"]} serde = { version = "1.0.137", features = ["derive"] } serde_json = "1.0.81" +wasm-bindgen = "0.2.80" wasm-bindgen-futures = "0.4.30" wasm-logger = "0.2.0" -web-sys = { version = "0.3.57", features = ["FocusEvent"] } +web-sys = { version = "0.3.57", features = ["HtmlInputElement"] } yew = "0.19.3" yew-hooks = "0.1.54" diff --git a/front-end/src/main.rs b/front-end/src/main.rs index 7ed2c8d..3d4faa4 100644 --- a/front-end/src/main.rs +++ b/front-end/src/main.rs @@ -1,21 +1,23 @@ mod server_api; +mod utils; -use server_api::LoginResponse; -use yew::{ - function_component, html, html::Scope, use_state, Callback, Component, Html, Properties, -}; +use gloo::net::websocket::Message; +use server_api::ServerApi; +use utils::value_by_id; +use yew::{html, Callback, Component, FocusEvent, Html, MouseEvent, Properties}; use log::*; -use serde_json::json; -use web_sys::FocusEvent; -use yew_hooks::{use_async, use_web_socket}; enum AppMsg { - SuccessfulLogin { jwt: String }, + LogInStarted, + LoggedIn(ServerApi), + Msg(String), + WsMessage(Message), } struct App { - jwt: Option, + api: Option, + logging_in: bool, } impl Component for App { @@ -24,36 +26,61 @@ impl Component for App { type Properties = (); fn create(_ctx: &yew::Context) -> Self { - App { jwt: None } + App { + api: None, + logging_in: false, + } } - fn update(&mut self, _ctx: &yew::Context, msg: Self::Message) -> bool { + fn update(&mut self, ctx: &yew::Context, msg: Self::Message) -> bool { match msg { - AppMsg::SuccessfulLogin { jwt } => self.jwt = Some(jwt), + AppMsg::LoggedIn(mut api) => { + api.list_games(); + self.api = Some(api); + true + } + + AppMsg::Msg(m) => { + info!("{m}"); + false + } + AppMsg::WsMessage(m) => { + info!("Server says {m:?}"); + true + } + AppMsg::LogInStarted => { + self.logging_in = true; + true + } } - true } fn view(&self, ctx: &yew::Context) -> Html { - let link = ctx.link().clone(); - let onsubmit = Callback::once(|focus_event: FocusEvent| { - focus_event.prevent_default(); - - wasm_bindgen_futures::spawn_local(login("daniil", "hello", link)); - }); - if let Some(jwt) = &self.jwt { - html! { - - } + if let Some(api) = &self.api { + html!( +

{"Playing!"}

+ ) } else { + if self.logging_in { + return html!( +

{"Logging in..."}

+ ); + } + let onmessage = ctx.link().callback(AppMsg::WsMessage); + let onclick = ctx.link().callback_future_once(|_e| async { + let login = value_by_id("username").unwrap(); + let password = value_by_id("pwd").unwrap(); + let api = ServerApi::login(&login, &password, onmessage).await; + AppMsg::LoggedIn(api.unwrap()) + }); html! { -
+ <>



- -
+ + } } } @@ -64,37 +91,6 @@ struct ConnectionProps { jwt: String, } -#[function_component(Connection)] -fn connection(props: &ConnectionProps) -> Html { - let ws = use_web_socket("ws://localhost:8080/web-socket".to_string()); - ws.send( - json!({ - "_type": "jwt", - "jwt": &format!("Bearer {}", props.jwt) - }) - .to_string(), - ); - html!( -

{"connection"}

- ) -} - -async fn login(username: &str, password: &str, link: Scope) { - let response: LoginResponse = reqwest::Client::new() - .post("http://localhost:8080/login") - .json(&json!({ - "name": "daniil", - "password": "world" - })) - .send() - .await - .unwrap() - .json() - .await - .unwrap(); - - link.send_message(AppMsg::SuccessfulLogin { jwt: response.jwt }); -} fn main() { std::panic::set_hook(Box::new(console_error_panic_hook::hook)); wasm_logger::init(wasm_logger::Config::default()); diff --git a/front-end/src/server_api.rs b/front-end/src/server_api.rs index 2d983d6..903a012 100644 --- a/front-end/src/server_api.rs +++ b/front-end/src/server_api.rs @@ -1,9 +1,19 @@ #![allow(non_snake_case, non_camel_case_types)] +use anyhow::format_err; +use futures::{ + channel::mpsc::{channel, Sender}, + stream::{SplitSink, SplitStream}, + SinkExt, StreamExt, +}; +use gloo::net::websocket::{futures::WebSocket, Message, WebSocketError}; +use log::*; use serde::Deserialize; +use serde_json::json; +use wasm_bindgen_futures::spawn_local; +use yew::Callback; #[derive(Deserialize)] -#[allow(non_camel_case_types)] pub enum GameSessionStatus { Created, Player_1_Turn, @@ -14,7 +24,7 @@ pub enum GameSessionStatus { #[derive(Deserialize)] #[serde(tag = "_type")] -pub enum Message { +pub enum RigelMessage { #[serde(rename = "status")] GameStatusUpdate { newStatus: GameSessionStatus }, } @@ -23,3 +33,67 @@ pub enum Message { pub struct LoginResponse { pub jwt: String, } + +pub struct ServerApi { + sink: Sender, +} + +impl ServerApi { + pub async fn login( + username: &str, + password: &str, + onmessage: Callback, + ) -> anyhow::Result { + let response = gloo::net::http::Request::post("http://localhost:8080/login") + .json(&json!({ + "name": username, + "password": password + }))? + .send() + .await?; + + let response = response.json::().await?; + let websocket = WebSocket::open("ws://localhost:8080/web-socket") + .map_err(|e| format_err!("Error connecting to WS: {e}"))?; + let (mut sink, mut source) = websocket.split(); + sink.send(Message::Text( + json!({ + "_type": "jwt", + "jwt": &format!("Bearer {}", response.jwt) + }) + .to_string(), + )) + .await + .map_err(|e| format_err!("Error sending to ws: {e}"))?; + spawn_local(async move { + while let Some(m) = source.next().await { + match m { + Ok(m) => onmessage.emit(m), + Err(WebSocketError::ConnectionClose(e)) => info!("Closing ws {e:?}"), + Err(e) => panic!("{e:?}"), + } + } + }); + + let (tx, mut rx) = channel(50); + spawn_local(async move { + while let Some(m) = rx.next().await { + sink.send(m).await.unwrap(); + } + }); + + Ok(ServerApi { sink: tx }) + } + pub fn list_games(&mut self) { + self.sink + .try_send(Message::Text( + json!( + { + "_type": "game_list" + } + ) + .to_string(), + )) + .unwrap() + } +} diff --git a/front-end/src/utils.rs b/front-end/src/utils.rs new file mode 100644 index 0000000..8d1de2f --- /dev/null +++ b/front-end/src/utils.rs @@ -0,0 +1,9 @@ +use wasm_bindgen::JsCast; +use web_sys::HtmlInputElement; + +pub fn value_by_id(element_id: &str) -> Option { + let element = gloo::utils::document() + .get_element_by_id(element_id)?; + let element = element.dyn_ref::()?; + Some(element.value()) +} From abb43406835b823b60ee9c287f7a3550be1c1010 Mon Sep 17 00:00:00 2001 From: Filipp Samoilov Date: Tue, 10 May 2022 20:59:00 +0300 Subject: [PATCH 10/14] Hide the login form when logging in --- front-end/src/main.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/front-end/src/main.rs b/front-end/src/main.rs index 3d4faa4..7730919 100644 --- a/front-end/src/main.rs +++ b/front-end/src/main.rs @@ -67,11 +67,15 @@ impl Component for App { ); } let onmessage = ctx.link().callback(AppMsg::WsMessage); - let onclick = ctx.link().callback_future_once(|_e| async { + let onstartlogin = ctx.link().callback(|()| AppMsg::LogInStarted); + let onclick = ctx.link().callback_future_once(move |_e| { let login = value_by_id("username").unwrap(); let password = value_by_id("pwd").unwrap(); - let api = ServerApi::login(&login, &password, onmessage).await; - AppMsg::LoggedIn(api.unwrap()) + onstartlogin.emit(()); + async move { + let api = ServerApi::login(&login, &password, onmessage).await; + AppMsg::LoggedIn(api.unwrap()) + } }); html! { <> From 9f251337d81cddfc487ba01a1220b8e7391054e3 Mon Sep 17 00:00:00 2001 From: Filipp Samoilov Date: Tue, 10 May 2022 21:47:09 +0300 Subject: [PATCH 11/14] Remove "loggingin"state and add a new game button --- front-end/src/main.rs | 83 ++++++++++++++++++++++--------------- front-end/src/server_api.rs | 13 ++++++ 2 files changed, 63 insertions(+), 33 deletions(-) diff --git a/front-end/src/main.rs b/front-end/src/main.rs index 7730919..523dbdb 100644 --- a/front-end/src/main.rs +++ b/front-end/src/main.rs @@ -9,15 +9,22 @@ use yew::{html, Callback, Component, FocusEvent, Html, MouseEvent, Properties}; use log::*; enum AppMsg { - LogInStarted, LoggedIn(ServerApi), Msg(String), WsMessage(Message), + CreateNewGame, } struct App { api: Option, - logging_in: bool, + current_screen: Screen, +} + +// FIXME: disable login button after the first press +// FIXME: add yew router +enum Screen { + Login, + ListGames, } impl Component for App { @@ -28,7 +35,7 @@ impl Component for App { fn create(_ctx: &yew::Context) -> Self { App { api: None, - logging_in: false, + current_screen: Screen::Login, } } @@ -37,6 +44,7 @@ impl Component for App { AppMsg::LoggedIn(mut api) => { api.list_games(); self.api = Some(api); + self.current_screen = Screen::ListGames; true } @@ -48,45 +56,54 @@ impl Component for App { info!("Server says {m:?}"); true } - AppMsg::LogInStarted => { - self.logging_in = true; - true + AppMsg::CreateNewGame => { + self.api.as_mut().unwrap().new_game(); + false } } } fn view(&self, ctx: &yew::Context) -> Html { - if let Some(api) = &self.api { - html!( -

{"Playing!"}

- ) - } else { - if self.logging_in { - return html!( -

{"Logging in..."}

- ); + match self.current_screen { + Screen::Login => { + let onmessage = ctx.link().callback(AppMsg::WsMessage); + let onclick = ctx.link().callback_future_once(move |_e| { + let login = value_by_id("username").unwrap(); + let password = value_by_id("pwd").unwrap(); + async move { + let api = ServerApi::login(&login, &password, onmessage).await; + AppMsg::LoggedIn(api.unwrap()) + } + }); + html! { + <> +
+
+
+
+ + + } } - let onmessage = ctx.link().callback(AppMsg::WsMessage); - let onstartlogin = ctx.link().callback(|()| AppMsg::LogInStarted); - let onclick = ctx.link().callback_future_once(move |_e| { - let login = value_by_id("username").unwrap(); - let password = value_by_id("pwd").unwrap(); - onstartlogin.emit(()); - async move { - let api = ServerApi::login(&login, &password, onmessage).await; - AppMsg::LoggedIn(api.unwrap()) + Screen::ListGames => { + // let games = self.api.unwrap().list_games() + // FIXME: new component will have non-optional api + let newgame = ctx.link().callback(|_e| AppMsg::CreateNewGame); + html! { + <> +

{ "Here be your games" }

+ + } - }); - html! { - <> -
-
-
-
- - } } + // if let Some(api) = &self.api { + // html!( + //

{"Playing!"}

+ // ) + // } else { + + // } } } diff --git a/front-end/src/server_api.rs b/front-end/src/server_api.rs index 903a012..a557201 100644 --- a/front-end/src/server_api.rs +++ b/front-end/src/server_api.rs @@ -96,4 +96,17 @@ impl ServerApi { )) .unwrap() } + pub fn new_game(&mut self) { + self.sink + .try_send(Message::Text( + json!( + { + "_type": "new_game" + } + ) + .to_string(), + )) + .unwrap() + } + } From 7c2a5e2945b02beb353a21d2575aa981e1f2f68e Mon Sep 17 00:00:00 2001 From: Filipp Date: Sun, 15 May 2022 12:02:51 +0300 Subject: [PATCH 12/14] Parse server messages --- front-end/src/main.rs | 15 ++++++++++++--- front-end/src/server_api.rs | 32 +++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/front-end/src/main.rs b/front-end/src/main.rs index 523dbdb..9648d5f 100644 --- a/front-end/src/main.rs +++ b/front-end/src/main.rs @@ -2,7 +2,7 @@ mod server_api; mod utils; use gloo::net::websocket::Message; -use server_api::ServerApi; +use server_api::{RigelServerMessage, ServerApi}; use utils::value_by_id; use yew::{html, Callback, Component, FocusEvent, Html, MouseEvent, Properties}; @@ -11,13 +11,14 @@ use log::*; enum AppMsg { LoggedIn(ServerApi), Msg(String), - WsMessage(Message), + WsMessage(RigelServerMessage), CreateNewGame, } struct App { api: Option, current_screen: Screen, + games: Vec, } // FIXME: disable login button after the first press @@ -36,6 +37,7 @@ impl Component for App { App { api: None, current_screen: Screen::Login, + games: vec![], } } @@ -68,6 +70,7 @@ impl Component for App { Screen::Login => { let onmessage = ctx.link().callback(AppMsg::WsMessage); let onclick = ctx.link().callback_future_once(move |_e| { + // FIXME: use node refs let login = value_by_id("username").unwrap(); let password = value_by_id("pwd").unwrap(); async move { @@ -91,7 +94,13 @@ impl Component for App { let newgame = ctx.link().callback(|_e| AppMsg::CreateNewGame); html! { <> -

{ "Here be your games" }

+
    + if self.games.is_empty() { +

    { "No games"}

    + } else { + { for self.games.iter() } + } +
} diff --git a/front-end/src/server_api.rs b/front-end/src/server_api.rs index a557201..ae61baf 100644 --- a/front-end/src/server_api.rs +++ b/front-end/src/server_api.rs @@ -13,7 +13,7 @@ use serde_json::json; use wasm_bindgen_futures::spawn_local; use yew::Callback; -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] pub enum GameSessionStatus { Created, Player_1_Turn, @@ -22,18 +22,28 @@ pub enum GameSessionStatus { Player_2_Won, } -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] #[serde(tag = "_type")] -pub enum RigelMessage { +pub enum RigelServerMessage { #[serde(rename = "status")] GameStatusUpdate { newStatus: GameSessionStatus }, } -#[derive(Deserialize, Clone, Debug)] +#[derive(Deserialize, Debug)] pub struct LoginResponse { pub jwt: String, } +#[derive(Deserialize, Debug)] +pub struct GamesListResponse { + pub games: Vec, +} + +#[derive(Deserialize, Debug)] +pub struct NewGameResponse { + pub gameId: String, +} + pub struct ServerApi { sink: Sender, } @@ -42,7 +52,7 @@ impl ServerApi { pub async fn login( username: &str, password: &str, - onmessage: Callback, + onmessage: Callback, ) -> anyhow::Result { let response = gloo::net::http::Request::post("http://localhost:8080/login") .json(&json!({ @@ -68,7 +78,16 @@ impl ServerApi { spawn_local(async move { while let Some(m) = source.next().await { match m { - Ok(m) => onmessage.emit(m), + Ok(m) => { + if let Message::Text(text_message) = m { + let rigel_message: Result = + serde_json::from_str(&text_message); + match rigel_message { + Ok(m) => onmessage.emit(m), + Err(e) => error!("Cannot parse server message {e:?}"), + } + } + } Err(WebSocketError::ConnectionClose(e)) => info!("Closing ws {e:?}"), Err(e) => panic!("{e:?}"), } @@ -108,5 +127,4 @@ impl ServerApi { )) .unwrap() } - } From 37d07003aaab819743eb4f3079b2e5d6c149e7af Mon Sep 17 00:00:00 2001 From: Filipp Date: Sun, 15 May 2022 14:37:54 +0300 Subject: [PATCH 13/14] List games --- front-end/src/main.rs | 10 ++++++++-- front-end/src/server_api.rs | 14 ++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/front-end/src/main.rs b/front-end/src/main.rs index 9648d5f..f673208 100644 --- a/front-end/src/main.rs +++ b/front-end/src/main.rs @@ -55,7 +55,11 @@ impl Component for App { false } AppMsg::WsMessage(m) => { - info!("Server says {m:?}"); + match m { + RigelServerMessage::GamesListResponse { games } => self.games = games, + RigelServerMessage::NewGameCreated { gameId } => self.games.push(gameId), + _ => info!("Server says {m:?}"), + } true } AppMsg::CreateNewGame => { @@ -98,7 +102,9 @@ impl Component for App { if self.games.is_empty() {

{ "No games"}

} else { - { for self.games.iter() } +
    + { for self.games.iter().map(|g| html!{
  • {g}
  • }) } +
} diff --git a/front-end/src/server_api.rs b/front-end/src/server_api.rs index ae61baf..666d512 100644 --- a/front-end/src/server_api.rs +++ b/front-end/src/server_api.rs @@ -27,6 +27,10 @@ pub enum GameSessionStatus { pub enum RigelServerMessage { #[serde(rename = "status")] GameStatusUpdate { newStatus: GameSessionStatus }, + #[serde(rename = "game_list")] + GamesListResponse { games: Vec }, + #[serde(rename = "new_game_created")] + NewGameCreated { gameId: String }, } #[derive(Deserialize, Debug)] @@ -34,16 +38,6 @@ pub struct LoginResponse { pub jwt: String, } -#[derive(Deserialize, Debug)] -pub struct GamesListResponse { - pub games: Vec, -} - -#[derive(Deserialize, Debug)] -pub struct NewGameResponse { - pub gameId: String, -} - pub struct ServerApi { sink: Sender, } From 6f92aa4f0bfc3bdd3668ab3420f23e91f3494d78 Mon Sep 17 00:00:00 2001 From: Filipp Date: Sun, 15 May 2022 18:16:58 +0300 Subject: [PATCH 14/14] Add router [broken] --- front-end/Cargo.lock | 41 ++++++++++ front-end/Cargo.toml | 1 + front-end/src/game_list.rs | 15 ++++ front-end/src/login.rs | 23 ++++++ front-end/src/main.rs | 148 ++++++++++++++++++++++-------------- front-end/src/server_api.rs | 9 +++ 6 files changed, 178 insertions(+), 59 deletions(-) create mode 100644 front-end/src/game_list.rs create mode 100644 front-end/src/login.rs diff --git a/front-end/Cargo.lock b/front-end/Cargo.lock index 43aefa7..9f9ee3c 100644 --- a/front-end/Cargo.lock +++ b/front-end/Cargo.lock @@ -129,6 +129,7 @@ dependencies = [ "web-sys", "yew", "yew-hooks", + "yew-router", ] [[package]] @@ -299,6 +300,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa5d6084efa4a2b182ef3a8649cb6506cb4843f22cf907c6e0a799944248ae90" dependencies = [ + "futures-channel", "gloo-events", "js-sys", "wasm-bindgen", @@ -372,6 +374,8 @@ 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", ] @@ -566,6 +570,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "route-recognizer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afab94fb28594581f62d981211a9a4d53cc8130bbcbbb89a0440d9b8e81a7746" + [[package]] name = "rustc-demangle" version = "0.1.21" @@ -825,3 +835,34 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "yew-router" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "155804f6f3aa309f596d5c3fa14486a94e7756f1edd7634569949e401d5099f2" +dependencies = [ + "gloo 0.4.2", + "gloo-utils", + "js-sys", + "route-recognizer", + "serde", + "serde-wasm-bindgen", + "serde_urlencoded", + "thiserror", + "wasm-bindgen", + "web-sys", + "yew", + "yew-router-macro", +] + +[[package]] +name = "yew-router-macro" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39049d193b52eaad4ffc80916bf08806d142c90b5edcebd527644de438a7e19a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/front-end/Cargo.toml b/front-end/Cargo.toml index 74e3fc3..e2b00c6 100644 --- a/front-end/Cargo.toml +++ b/front-end/Cargo.toml @@ -17,6 +17,7 @@ wasm-logger = "0.2.0" web-sys = { version = "0.3.57", features = ["HtmlInputElement"] } yew = "0.19.3" yew-hooks = "0.1.54" +yew-router = "0.16.0" [profile.release] lto = true diff --git a/front-end/src/game_list.rs b/front-end/src/game_list.rs new file mode 100644 index 0000000..a0061d7 --- /dev/null +++ b/front-end/src/game_list.rs @@ -0,0 +1,15 @@ +use std::{cell::RefCell, rc::Rc}; + +use yew::prelude::*; + +use crate::server_api::ServerApi; + +#[derive(Properties, PartialEq)] +pub struct Props { + pub api: Rc> +} + +#[function_component(GameList)] +pub fn game_list(props: &Props) -> Html { + html! { {"Games"} } +} diff --git a/front-end/src/login.rs b/front-end/src/login.rs new file mode 100644 index 0000000..3465000 --- /dev/null +++ b/front-end/src/login.rs @@ -0,0 +1,23 @@ +use yew::{prelude::*}; + +use crate::App; + + +#[derive(Properties, PartialEq)] +pub struct Props { + pub onlogin: Callback +} + +#[function_component(Login)] +pub fn login(props: &Props) -> Html { + let onlogin = props.onlogin.clone(); + html! { + <> +
+
+
+
+ + + } +} \ No newline at end of file diff --git a/front-end/src/main.rs b/front-end/src/main.rs index f673208..7feb725 100644 --- a/front-end/src/main.rs +++ b/front-end/src/main.rs @@ -1,22 +1,25 @@ +mod game_list; +mod login; mod server_api; mod utils; -use gloo::net::websocket::Message; -use server_api::{RigelServerMessage, ServerApi}; -use utils::value_by_id; -use yew::{html, Callback, Component, FocusEvent, Html, MouseEvent, Properties}; +use std::{cell::RefCell, rc::Rc}; +use crate::game_list::GameList; +use crate::login::Login; use log::*; +use server_api::{RigelServerMessage, ServerApi}; +use utils::value_by_id; +use yew::prelude::*; +use yew_router::prelude::*; enum AppMsg { LoggedIn(ServerApi), - Msg(String), WsMessage(RigelServerMessage), - CreateNewGame, } struct App { - api: Option, + api: Option>>, current_screen: Screen, games: Vec, } @@ -28,6 +31,19 @@ enum Screen { ListGames, } +#[derive(Clone, Routable, PartialEq)] +enum Route { + #[at("/")] + Home, + #[at("/login")] + Login, + #[at("/games")] + GamesList, + #[not_found] + #[at("/404")] + NotFound, +} + impl Component for App { type Message = AppMsg; @@ -45,15 +61,11 @@ impl Component for App { match msg { AppMsg::LoggedIn(mut api) => { api.list_games(); - self.api = Some(api); + self.api = Some(Rc::new(RefCell::new(api))); self.current_screen = Screen::ListGames; true } - AppMsg::Msg(m) => { - info!("{m}"); - false - } AppMsg::WsMessage(m) => { match m { RigelServerMessage::GamesListResponse { games } => self.games = games, @@ -61,57 +73,38 @@ impl Component for App { _ => info!("Server says {m:?}"), } true - } - AppMsg::CreateNewGame => { - self.api.as_mut().unwrap().new_game(); - false - } + } // AppMsg::CreateNewGame => { + // self.api.as_mut().unwrap().new_game(); + // false + // } } } fn view(&self, ctx: &yew::Context) -> Html { - match self.current_screen { - Screen::Login => { - let onmessage = ctx.link().callback(AppMsg::WsMessage); - let onclick = ctx.link().callback_future_once(move |_e| { - // FIXME: use node refs - let login = value_by_id("username").unwrap(); - let password = value_by_id("pwd").unwrap(); - async move { - let api = ServerApi::login(&login, &password, onmessage).await; - AppMsg::LoggedIn(api.unwrap()) - } - }); - html! { - <> -
-
-
-
- - - } - } - Screen::ListGames => { - // let games = self.api.unwrap().list_games() - // FIXME: new component will have non-optional api - let newgame = ctx.link().callback(|_e| AppMsg::CreateNewGame); - html! { - <> -
    - if self.games.is_empty() { -

    { "No games"}

    - } else { -
      - { for self.games.iter().map(|g| html!{
    • {g}
    • }) } -
    - } -
- - - } - } - } + // match self.current_screen { + // Screen::Login => { + + // } + // Screen::ListGames => { + // // let games = self.api.unwrap().list_games() + // // FIXME: new component will have non-optional api + // let newgame = ctx.link().callback(|_e| AppMsg::CreateNewGame); + // html! { + // <> + //
    + // if self.games.is_empty() { + //

    { "No games"}

    + // } else { + //
      + // { for self.games.iter().map(|g| html!{
    • {g}
    • }) } + //
    + // } + //
+ // + // + // } + // } + // }; // if let Some(api) = &self.api { // html!( //

{"Playing!"}

@@ -119,6 +112,43 @@ impl Component for App { // } else { // } + + let link = ctx.link().clone(); + let link2 = link.clone(); + let api = self.api.as_ref().map(Rc::clone); + let gotologin = Callback::from(move |_| link2.history().unwrap().push(Route::Login)); + + let switch = move |route: &Route| -> Html { + let onmessage = link.callback(AppMsg::WsMessage); + let onlogin = link.callback_future(move |_e| { + let onmessage = onmessage.clone(); + // FIXME: use node refs + let login = value_by_id("username").unwrap(); + let password = value_by_id("pwd").unwrap(); + async move { + let api = ServerApi::login(&login, &password, onmessage).await; + AppMsg::LoggedIn(api.unwrap()) + } + }); + match route { + Route::Home => html! { <>

{"Home"}