diff --git a/Cargo.lock b/Cargo.lock index 06802e8..5e7aec2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,17 +97,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "any_spawner" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41058deaa38c9d9dd933d6d238d825227cffa668e2839b52879f6619c63eee3b" -dependencies = [ - "futures", - "thiserror 2.0.18", - "wasm-bindgen-futures", -] - [[package]] name = "any_spawner" version = "0.3.0" @@ -137,9 +126,9 @@ dependencies = [ [[package]] name = "async-compression" -version = "0.4.37" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d10e4f991a553474232bc0a31799f6d24b034a84c0971d80d2e2f78b2e576e40" +checksum = "68650b7df54f0293fd061972a0fb05aaf4fc0879d3b3d21a638a182c5c543b9f" dependencies = [ "compression-codecs", "compression-core", @@ -331,7 +320,7 @@ dependencies = [ "dotenvy", "futures", "governor", - "leptos 0.8.15", + "leptos", "leptos_axum", "mime_guess", "openssl", @@ -475,9 +464,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" [[package]] name = "camino" @@ -487,9 +476,9 @@ checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48" [[package]] name = "cc" -version = "1.2.54" +version = "1.2.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6354c81bbfd62d9cfa9cb3c773c2b7b2a3a482d569de977fd0e961f6e7c00583" +checksum = "47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29" dependencies = [ "find-msvc-tools", "jobserver", @@ -529,9 +518,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.56" +version = "4.5.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75ca66430e33a14957acc24c5077b503e7d374151b2b4b3a10c83b4ceb4be0e" +checksum = "6899ea499e3fb9305a65d5ebf6e3d2248c5fab291f300ad0a704fbe142eae31a" dependencies = [ "clap_builder", "clap_derive", @@ -539,9 +528,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.56" +version = "4.5.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793207c7fa6300a0608d1080b858e5fdbe713cdc1c8db9fb17777d8a13e63df0" +checksum = "7b12c8b680195a62a8364d16b8447b01b6c2c8f9aaf68bee653be34d4245e238" dependencies = [ "anstream", "anstyle", @@ -577,15 +566,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "codee" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d3ad3122b0001c7f140cf4d605ef9a9e2c24d96ab0b4fb4347b76de2425f445" -dependencies = [ - "thiserror 1.0.69", -] - [[package]] name = "codee" version = "0.3.5" @@ -724,15 +704,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "convert_case" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb402b8d4c85569410425650ce3eddc7d698ed96d39a73f941b08fb63082f1e7" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "convert_case" version = "0.8.0" @@ -1032,12 +1003,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "669a445ee724c5c69b1b06fe0b63e70a1c84bc9bb7d9696cd4f4e3ec45050408" -[[package]] -name = "dyn-clone" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" - [[package]] name = "ecdsa" version = "0.16.9" @@ -1201,15 +1166,15 @@ dependencies = [ [[package]] name = "find-msvc-tools" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "flate2" -version = "1.1.8" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b375d6465b98090a5f25b1c7703f3859783755aa9a80433b36e0379a3ec2f369" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" dependencies = [ "crc32fast", "miniz_oxide", @@ -1285,14 +1250,14 @@ version = "0.1.0" dependencies = [ "base64 0.22.1", "chrono", - "codee 0.2.0", + "codee", "console_error_panic_hook", "console_log", "futures", "gloo-net", "gloo-timers", "js-sys", - "leptos 0.8.15", + "leptos", "leptos-use", "leptos_router", "log", @@ -1744,20 +1709,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "hydration_context" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d35485b3dcbf7e044b8f28c73f04f13e7b509c2466fd10cb2a8a447e38f8a93a" -dependencies = [ - "futures", - "once_cell", - "or_poisoned", - "pin-project-lite", - "serde", - "throw_error 0.2.0", -] - [[package]] name = "hydration_context" version = "0.3.0" @@ -1770,7 +1721,7 @@ dependencies = [ "or_poisoned", "pin-project-lite", "serde", - "throw_error 0.3.1", + "throw_error", "wasm-bindgen", ] @@ -1848,13 +1799,12 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" dependencies = [ "bytes", "futures-channel", - "futures-core", "futures-util", "http 1.4.0", "http-body 1.0.1", @@ -2125,75 +2075,40 @@ dependencies = [ "spin", ] -[[package]] -name = "leptos" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b8731cb00f3f0894058155410b95c8955b17273181d2bc72600ab84edd24f1" -dependencies = [ - "any_spawner 0.2.0", - "cfg-if", - "either_of", - "futures", - "hydration_context 0.2.1", - "leptos_config 0.7.8", - "leptos_dom 0.7.8", - "leptos_hot_reload 0.7.8", - "leptos_macro 0.7.9", - "leptos_server 0.7.8", - "oco_ref", - "or_poisoned", - "paste", - "reactive_graph 0.1.8", - "rustc-hash", - "send_wrapper", - "serde", - "serde_qs 0.13.0", - "server_fn 0.7.8", - "slotmap", - "tachys 0.1.9", - "thiserror 2.0.18", - "throw_error 0.2.0", - "typed-builder 0.20.1", - "typed-builder-macro 0.20.1", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "leptos" version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f9569fc37575a5d64c0512145af7630bf651007237ef67a8a77328199d315bb" dependencies = [ - "any_spawner 0.3.0", + "any_spawner", "base64 0.22.1", "cfg-if", "either_of", "futures", "getrandom 0.3.4", - "hydration_context 0.3.0", - "leptos_config 0.8.8", - "leptos_dom 0.8.7", - "leptos_hot_reload 0.8.5", - "leptos_macro 0.8.14", - "leptos_server 0.8.6", + "hydration_context", + "leptos_config", + "leptos_dom", + "leptos_hot_reload", + "leptos_macro", + "leptos_server", "oco_ref", "or_poisoned", "paste", "rand 0.9.2", - "reactive_graph 0.2.12", + "reactive_graph", "rustc-hash", "rustc_version", "send_wrapper", "serde", "serde_json", - "serde_qs 0.15.0", - "server_fn 0.8.9", + "serde_qs", + "server_fn", "slotmap", - "tachys 0.2.11", + "tachys", "thiserror 2.0.18", - "throw_error 0.3.1", + "throw_error", "typed-builder 0.23.2", "typed-builder-macro 0.23.2", "wasm-bindgen", @@ -2204,20 +2119,20 @@ dependencies = [ [[package]] name = "leptos-use" -version = "0.15.10" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2457c1abaa00dd4601695a989ed796bb19bc44e47ecffe2ad1336cc4c9e4f505" +checksum = "ce2162c453100c7d6bc0b6f188ef1df582e35c2458caf6cb69fcddc87619c0db" dependencies = [ "cfg-if", "chrono", - "codee 0.3.5", + "codee", "cookie", "default-struct-builder", "futures-util", "gloo-timers", "js-sys", "lazy_static", - "leptos 0.7.8", + "leptos", "paste", "send_wrapper", "thiserror 2.0.18", @@ -2233,37 +2148,24 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0caa95760f87f3067e05025140becefdbdfd36cbc2adac4519f06e1f1edf4af" dependencies = [ - "any_spawner 0.3.0", + "any_spawner", "axum", "dashmap", "futures", - "hydration_context 0.3.0", - "leptos 0.8.15", + "hydration_context", + "leptos", "leptos_integration_utils", - "leptos_macro 0.8.14", + "leptos_macro", "leptos_meta", "leptos_router", "parking_lot", - "server_fn 0.8.9", - "tachys 0.2.11", + "server_fn", + "tachys", "tokio", "tower", "tower-http", ] -[[package]] -name = "leptos_config" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bae3e0ead5a7a814c8340eef7cb8b6cba364125bd8174b15dc9fe1b3cab7e03" -dependencies = [ - "config", - "regex", - "serde", - "thiserror 2.0.18", - "typed-builder 0.20.1", -] - [[package]] name = "leptos_config" version = "0.8.8" @@ -2277,21 +2179,6 @@ dependencies = [ "typed-builder 0.21.2", ] -[[package]] -name = "leptos_dom" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f89d4eb263bd5a9e7c49f780f17063f15aca56fd638c90b9dfd5f4739152e87d" -dependencies = [ - "js-sys", - "or_poisoned", - "reactive_graph 0.1.8", - "send_wrapper", - "tachys 0.1.9", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "leptos_dom" version = "0.8.7" @@ -2300,31 +2187,13 @@ checksum = "78f4330c88694c5575e0bfe4eecf81b045d14e76a4f8b00d5fd2a63f8779f895" dependencies = [ "js-sys", "or_poisoned", - "reactive_graph 0.2.12", + "reactive_graph", "send_wrapper", - "tachys 0.2.11", + "tachys", "wasm-bindgen", "web-sys", ] -[[package]] -name = "leptos_hot_reload" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e80219388501d99b246f43b6e7d08a28f327cdd34ba630a35654d917f3e1788e" -dependencies = [ - "anyhow", - "camino", - "indexmap", - "parking_lot", - "proc-macro2", - "quote", - "rstml", - "serde", - "syn 2.0.114", - "walkdir", -] - [[package]] name = "leptos_hot_reload" version = "0.8.5" @@ -2350,34 +2219,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13cccc9305df53757bae61bf15641bfa6a667b5f78456ace4879dfe0591ae0e8" dependencies = [ "futures", - "hydration_context 0.3.0", - "leptos 0.8.15", - "leptos_config 0.8.8", + "hydration_context", + "leptos", + "leptos_config", "leptos_meta", "leptos_router", - "reactive_graph 0.2.12", -] - -[[package]] -name = "leptos_macro" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e621f8f5342b9bdc93bb263b839cee7405027a74560425a2dabea9de7952b1fd" -dependencies = [ - "attribute-derive", - "cfg-if", - "convert_case 0.7.1", - "html-escape", - "itertools", - "leptos_hot_reload 0.7.8", - "prettyplease", - "proc-macro-error2", - "proc-macro2", - "quote", - "rstml", - "server_fn_macro 0.7.8", - "syn 2.0.114", - "uuid", + "reactive_graph", ] [[package]] @@ -2391,14 +2238,14 @@ dependencies = [ "convert_case 0.10.0", "html-escape", "itertools", - "leptos_hot_reload 0.8.5", + "leptos_hot_reload", "prettyplease", "proc-macro-error2", "proc-macro2", "quote", "rstml", "rustc_version", - "server_fn_macro 0.8.8", + "server_fn_macro", "syn 2.0.114", "uuid", ] @@ -2411,7 +2258,7 @@ checksum = "2d489e38d3f541e9e43ecc2e3a815527840345a2afca629b3e23fcc1dd254578" dependencies = [ "futures", "indexmap", - "leptos 0.8.15", + "leptos", "or_poisoned", "send_wrapper", "wasm-bindgen", @@ -2424,19 +2271,19 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01e573711f2fb9ab5d655ec38115220d359eaaf1dcb93cc0ea624543b6dba959" dependencies = [ - "any_spawner 0.3.0", + "any_spawner", "either_of", "futures", "gloo-net", "js-sys", - "leptos 0.8.15", + "leptos", "leptos_router_macro", "or_poisoned", "percent-encoding", - "reactive_graph 0.2.12", + "reactive_graph", "rustc_version", "send_wrapper", - "tachys 0.2.11", + "tachys", "thiserror 2.0.18", "url", "wasm-bindgen", @@ -2455,44 +2302,24 @@ dependencies = [ "syn 2.0.114", ] -[[package]] -name = "leptos_server" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66985242812ec95e224fb48effe651ba02728beca92c461a9464c811a71aab11" -dependencies = [ - "any_spawner 0.2.0", - "base64 0.22.1", - "codee 0.3.5", - "futures", - "hydration_context 0.2.1", - "or_poisoned", - "reactive_graph 0.1.8", - "send_wrapper", - "serde", - "serde_json", - "server_fn 0.7.8", - "tachys 0.1.9", -] - [[package]] name = "leptos_server" version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbf1045af93050bf3388d1c138426393fc131f6d9e46a65519da884c033ed730" dependencies = [ - "any_spawner 0.3.0", + "any_spawner", "base64 0.22.1", - "codee 0.3.5", + "codee", "futures", - "hydration_context 0.3.0", + "hydration_context", "or_poisoned", - "reactive_graph 0.2.12", + "reactive_graph", "send_wrapper", "serde", "serde_json", - "server_fn 0.8.9", - "tachys 0.2.11", + "server_fn", + "tachys", ] [[package]] @@ -2612,9 +2439,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.6" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "mime" @@ -3299,38 +3126,17 @@ dependencies = [ "bitflags", ] -[[package]] -name = "reactive_graph" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76a0ccddbc11a648bd09761801dac9e3f246ef7641130987d6120fced22515e6" -dependencies = [ - "any_spawner 0.2.0", - "async-lock", - "futures", - "guardian", - "hydration_context 0.2.1", - "or_poisoned", - "pin-project-lite", - "rustc-hash", - "send_wrapper", - "serde", - "slotmap", - "thiserror 2.0.18", - "web-sys", -] - [[package]] name = "reactive_graph" version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17f0df355582937223ea403e52490201d65295bd6981383c69bfae5a1f8730c2" dependencies = [ - "any_spawner 0.3.0", + "any_spawner", "async-lock", "futures", "guardian", - "hydration_context 0.3.0", + "hydration_context", "indexmap", "or_poisoned", "paste", @@ -3344,21 +3150,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "reactive_stores" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aadc7c19e3a360bf19cd595d2dc8b58ce67b9240b95a103fbc1317a8ff194237" -dependencies = [ - "guardian", - "itertools", - "or_poisoned", - "paste", - "reactive_graph 0.1.8", - "reactive_stores_macro 0.1.8", - "rustc-hash", -] - [[package]] name = "reactive_stores" version = "0.3.1" @@ -3370,25 +3161,12 @@ dependencies = [ "itertools", "or_poisoned", "paste", - "reactive_graph 0.2.12", - "reactive_stores_macro 0.2.6", + "reactive_graph", + "reactive_stores_macro", "rustc-hash", "send_wrapper", ] -[[package]] -name = "reactive_stores_macro" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "221095cb028dc51fbc2833743ea8b1a585da1a2af19b440b3528027495bf1f2d" -dependencies = [ - "convert_case 0.7.1", - "proc-macro-error2", - "proc-macro2", - "quote", - "syn 2.0.114", -] - [[package]] name = "reactive_stores_macro" version = "0.2.6" @@ -3422,9 +3200,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.12.2" +version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" dependencies = [ "aho-corasick", "memchr", @@ -3434,9 +3212,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" dependencies = [ "aho-corasick", "memchr", @@ -3445,9 +3223,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" +checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" [[package]] name = "rfc6979" @@ -3585,9 +3363,9 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" [[package]] name = "same-file" @@ -3741,17 +3519,6 @@ dependencies = [ "serde_core", ] -[[package]] -name = "serde_qs" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd34f36fe4c5ba9654417139a9b3a20d2e1de6012ee678ad14d240c22c78d8d6" -dependencies = [ - "percent-encoding", - "serde", - "thiserror 1.0.69", -] - [[package]] name = "serde_qs" version = "0.15.0" @@ -3784,36 +3551,6 @@ dependencies = [ "serde", ] -[[package]] -name = "server_fn" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d05a9e3fd8d7404985418db38c6617cc793a1a27f398d4fbc9dfe8e41b804e6" -dependencies = [ - "bytes", - "const_format", - "dashmap", - "futures", - "gloo-net", - "http 1.4.0", - "js-sys", - "once_cell", - "pin-project-lite", - "send_wrapper", - "serde", - "serde_json", - "serde_qs 0.13.0", - "server_fn_macro_default 0.7.8", - "thiserror 2.0.18", - "throw_error 0.2.0", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-streams", - "web-sys", - "xxhash-rust", -] - [[package]] name = "server_fn" version = "0.8.9" @@ -3839,10 +3576,10 @@ dependencies = [ "send_wrapper", "serde", "serde_json", - "serde_qs 0.15.0", - "server_fn_macro_default 0.8.5", + "serde_qs", + "server_fn_macro_default", "thiserror 2.0.18", - "throw_error 0.3.1", + "throw_error", "tokio", "tower", "tower-layer", @@ -3854,20 +3591,6 @@ dependencies = [ "xxhash-rust", ] -[[package]] -name = "server_fn_macro" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "504b35e883267b3206317b46d02952ed7b8bf0e11b2e209e2eb453b609a5e052" -dependencies = [ - "const_format", - "convert_case 0.6.0", - "proc-macro2", - "quote", - "syn 2.0.114", - "xxhash-rust", -] - [[package]] name = "server_fn_macro" version = "0.8.8" @@ -3883,23 +3606,13 @@ dependencies = [ "xxhash-rust", ] -[[package]] -name = "server_fn_macro_default" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb8b274f568c94226a8045668554aace8142a59b8bca5414ac5a79627c825568" -dependencies = [ - "server_fn_macro 0.7.8", - "syn 2.0.114", -] - [[package]] name = "server_fn_macro_default" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63eb08f80db903d3c42f64e60ebb3875e0305be502bdc064ec0a0eab42207f00" dependencies = [ - "server_fn_macro 0.8.8", + "server_fn_macro", "syn 2.0.114", ] @@ -3939,7 +3652,7 @@ name = "shared" version = "0.1.0" dependencies = [ "bytes", - "leptos 0.8.15", + "leptos", "leptos_axum", "leptos_router", "quick-xml", @@ -3993,9 +3706,9 @@ checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" [[package]] name = "slab" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "slotmap" @@ -4353,47 +4066,13 @@ dependencies = [ "syn 2.0.114", ] -[[package]] -name = "tachys" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f66c3b70c32844a6f1e2943c72a33ebb777ad6acbeb20d1329d62e3a7806d6ec" -dependencies = [ - "any_spawner 0.2.0", - "async-trait", - "const_str_slice_concat", - "drain_filter_polyfill", - "dyn-clone", - "either_of", - "futures", - "html-escape", - "indexmap", - "itertools", - "js-sys", - "linear-map", - "next_tuple", - "oco_ref", - "once_cell", - "or_poisoned", - "parking_lot", - "paste", - "reactive_graph 0.1.8", - "reactive_stores 0.1.8", - "rustc-hash", - "send_wrapper", - "slotmap", - "throw_error 0.2.0", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "tachys" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2b2db11e455f7e84e2cc3e76f8a3f3843f7956096265d5ecff781eabe235077" dependencies = [ - "any_spawner 0.3.0", + "any_spawner", "async-trait", "const_str_slice_concat", "drain_filter_polyfill", @@ -4410,13 +4089,13 @@ dependencies = [ "or_poisoned", "parking_lot", "paste", - "reactive_graph 0.2.12", - "reactive_stores 0.3.1", + "reactive_graph", + "reactive_stores", "rustc-hash", "rustc_version", "send_wrapper", "slotmap", - "throw_error 0.3.1", + "throw_error", "wasm-bindgen", "web-sys", ] @@ -4492,15 +4171,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "throw_error" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4ef8bf264c6ae02a065a4a16553283f0656bd6266fc1fcb09fd2e6b5e91427b" -dependencies = [ - "pin-project-lite", -] - [[package]] name = "throw_error" version = "0.3.1" @@ -4861,15 +4531,6 @@ dependencies = [ "utf-8", ] -[[package]] -name = "typed-builder" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd9d30e3a08026c78f246b173243cf07b3696d274debd26680773b6773c2afc7" -dependencies = [ - "typed-builder-macro 0.20.1", -] - [[package]] name = "typed-builder" version = "0.21.2" @@ -4888,17 +4549,6 @@ dependencies = [ "typed-builder-macro 0.23.2", ] -[[package]] -name = "typed-builder-macro" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c36781cc0e46a83726d9879608e4cf6c2505237e263a8eb8c24502989cfdb28" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.114", -] - [[package]] name = "typed-builder-macro" version = "0.21.2" @@ -4959,9 +4609,9 @@ checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" [[package]] name = "unicode-ident" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e" [[package]] name = "unicode-normalization" @@ -5662,18 +5312,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.35" +version = "0.8.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdea86ddd5568519879b8187e1cf04e24fce28f7fe046ceecbce472ff19a2572" +checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.35" +version = "0.8.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c15e1b46eff7c6c91195752e0eeed8ef040e391cdece7c25376957d5f15df22" +checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517" dependencies = [ "proc-macro2", "quote", @@ -5757,15 +5407,15 @@ dependencies = [ [[package]] name = "zlib-rs" -version = "0.5.5" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40990edd51aae2c2b6907af74ffb635029d5788228222c4bb811e9351c0caad3" +checksum = "a7948af682ccbc3342b6e9420e8c51c1fe5d7bf7756002b4a3c6cabfe96a7e3c" [[package]] name = "zmij" -version = "1.0.17" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02aae0f83f69aafc94776e879363e9771d7ecbffe2c7fbb6c14c5e00dfe88439" +checksum = "4de98dfa5d5b7fef4ee834d0073d560c9ca7b6c46a71d058c48db7960f8cfaf7" [[package]] name = "zopfli" diff --git a/Cargo.toml b/Cargo.toml index b82e6d4..b027cc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,4 @@ strip = true incremental = false [patch.crates-io] -coarsetime = { path = "third_party/coarsetime" } \ No newline at end of file +coarsetime = { path = "third_party/coarsetime" } diff --git a/frontend/Cargo.toml b/frontend/Cargo.toml index c63ac09..6da7428 100644 --- a/frontend/Cargo.toml +++ b/frontend/Cargo.toml @@ -7,8 +7,8 @@ edition = "2021" crate-type = ["cdylib", "rlib"] [dependencies] -leptos = { version = "0.8.7", features = ["csr", "nightly"] } -leptos_router = { version = "0.8.7", features = ["nightly"] } +leptos = { version = "0.8.15", features = ["csr"] } +leptos_router = { version = "0.8.11" } console_error_panic_hook = "0.1" console_log = "1" @@ -22,12 +22,12 @@ wasm-bindgen-futures = "0.4" uuid = { version = "1", features = ["v4", "js"] } futures = "0.3" chrono = { version = "0.4", features = ["serde", "wasm-bindgen"] } -web-sys = { version = "0.3", features = ["HtmlDivElement", "HtmlUListElement", "HtmlLiElement", "HtmlAnchorElement", "MouseEvent", "Event", "Window", "Document", "Element", "DomTokenList", "CssStyleDeclaration", "Storage", "TouchEvent", "TouchList", "Touch", "Navigator", "Notification", "NotificationOptions", "NotificationPermission", "ServiceWorkerContainer", "ServiceWorkerRegistration", "PushManager", "PushSubscription", "PushSubscriptionOptions", "PushSubscriptionOptionsInit", "HtmlDetailsElement"] } +web-sys = { version = "0.3", features = ["HtmlDivElement", "HtmlUListElement", "HtmlLiElement", "HtmlAnchorElement", "MouseEvent", "Event", "Window", "Document", "Element", "DomTokenList", "CssStyleDeclaration", "Storage", "TouchEvent", "TouchList", "Touch", "Navigator", "Notification", "NotificationOptions", "NotificationPermission", "ServiceWorkerContainer", "ServiceWorkerRegistration", "PushManager", "PushSubscription", "PushSubscriptionOptions", "PushSubscriptionOptionsInit", "HtmlDetailsElement", "HtmlInputElement", "HtmlFormElement", "HtmlDialogElement", "ProgressEvent"] } shared = { path = "../shared", features = ["hydrate"] } tailwind_fuse = "0.3.2" js-sys = "0.3.85" base64 = "0.22.1" serde-wasm-bindgen = "0.6.5" -leptos-use = "0.15" -codee = "0.2" -thiserror = "2.0" \ No newline at end of file +leptos-use = { version = "0.16", features = ["storage"] } +codee = "0.3" +thiserror = "2.0" diff --git a/frontend/src/app.rs b/frontend/src/app.rs index 8b73e5d..3b7e7bd 100644 --- a/frontend/src/app.rs +++ b/frontend/src/app.rs @@ -5,43 +5,41 @@ use crate::components::auth::login::Login; use crate::components::auth::setup::Setup; use crate::api; use leptos::prelude::*; -use leptos::logging; use leptos::task::spawn_local; use leptos_router::components::{Router, Routes, Route}; use leptos_router::hooks::use_navigate; -// use leptos_router::PossibleRouteMatch; // Bu trait prelude ile gelmeli veya public olmayabilir. #[component] pub fn App() -> impl IntoView { crate::store::provide_torrent_store(); - let (is_loading, set_is_loading) = create_signal(true); - let (is_authenticated, set_is_authenticated) = create_signal(false); + let is_loading = signal(true); + let is_authenticated = signal(false); - create_effect(move |_| { + Effect::new(move |_| { spawn_local(async move { - logging::log!("App initialization started..."); + log::info!("App initialization started..."); let setup_res = api::setup::get_status().await; match setup_res { Ok(status) => { if !status.completed { - logging::log!("Setup not completed, redirecting to /setup"); + log::info!("Setup not completed, redirecting to /setup"); let navigate = use_navigate(); navigate("/setup", Default::default()); - set_is_loading.set(false); + is_loading.1.set(false); return; } } - Err(e) => logging::error!("Failed to get setup status: {:?}", e), + Err(e) => log::error!("Failed to get setup status: {:?}", e), } let auth_res = api::auth::check_auth().await; match auth_res { Ok(true) => { - logging::log!("Authenticated!"); + log::info!("Authenticated!"); if let Ok(user_info) = api::auth::get_user().await { if let Some(store) = use_context::() { @@ -49,17 +47,17 @@ pub fn App() -> impl IntoView { } } - set_is_authenticated.set(true); + is_authenticated.1.set(true); let pathname = window().location().pathname().unwrap_or_default(); if pathname == "/login" || pathname == "/setup" { - logging::log!("Already authenticated, redirecting to home"); + log::info!("Already authenticated, redirecting to home"); let navigate = use_navigate(); navigate("/", Default::default()); } } Ok(false) => { - logging::log!("Not authenticated"); + log::info!("Not authenticated"); let pathname = window().location().pathname().unwrap_or_default(); if pathname != "/login" && pathname != "/setup" { @@ -68,18 +66,18 @@ pub fn App() -> impl IntoView { } } Err(e) => { - logging::error!("Auth check failed: {:?}", e); + log::error!("Auth check failed: {:?}", e); let navigate = use_navigate(); navigate("/login", Default::default()); } } - set_is_loading.set(false); + is_loading.1.set(false); }); }); - create_effect(move |_| { - if is_authenticated.get() { + Effect::new(move |_| { + if is_authenticated.0.get() { spawn_local(async { gloo_timers::future::TimeoutFuture::new(2000).await; @@ -93,18 +91,18 @@ pub fn App() -> impl IntoView { view! {
- - } /> - } /> + "404 Not Found"
}> + } /> + } /> - }> - + @@ -113,10 +111,10 @@ pub fn App() -> impl IntoView { } }/> - - + +
"Settings Page (Coming Soon)"
@@ -130,4 +128,4 @@ pub fn App() -> impl IntoView { } -} +} \ No newline at end of file diff --git a/frontend/src/components/auth/login.rs b/frontend/src/components/auth/login.rs index ec99c18..b31549f 100644 --- a/frontend/src/components/auth/login.rs +++ b/frontend/src/components/auth/login.rs @@ -1,52 +1,39 @@ use leptos::prelude::*; -use leptos::logging; -use leptos::html; use leptos::task::spawn_local; use crate::api; #[component] pub fn Login() -> impl IntoView { - let (username, set_username) = create_signal(String::new()); - let (password, set_password) = create_signal(String::new()); - let (remember_me, set_remember_me) = create_signal(false); - let (error, set_error) = create_signal(Option::::None); - let (loading, set_loading) = create_signal(false); + let username = signal(String::new()); + let password = signal(String::new()); + let remember_me = signal(false); + let error = signal(Option::::None); + let loading = signal(false); let handle_login = move |ev: web_sys::SubmitEvent| { ev.prevent_default(); - set_loading.set(true); - set_error.set(None); + loading.1.set(true); + error.1.set(None); - logging::log!("Attempting login for user: {}", username.get()); + let user = username.0.get(); + let pass = password.0.get(); + let rem = remember_me.0.get(); - let username = username.get(); - let password = password.get(); - let remember_me = remember_me.get(); + log::info!("Attempting login for user: {}", user); spawn_local(async move { - match api::auth::login(&username, &password, remember_me).await { + match api::auth::login(&user, &pass, rem).await { Ok(_) => { - logging::log!("Login successful, redirecting..."); - let _ = window().location().set_href("/"); + log::info!("Login successful, redirecting..."); + let window = web_sys::window().expect("window should exist"); + let _ = window.location().set_href("/"); } Err(e) => { - logging::error!("Login failed: {:?}", e); - let msg = match e { - crate::api::ApiError::RateLimited => { - "Çok fazla başarısız deneme yaptınız. Lütfen bir süre bekleyip tekrar deneyin.".to_string() - } - crate::api::ApiError::Unauthorized | crate::api::ApiError::LoginFailed => { - "Kullanıcı adı veya şifre hatalı".to_string() - } - crate::api::ApiError::Network => { - "Bağlantı hatası".to_string() - } - _ => "Bir hata oluştu".to_string() - }; - set_error.set(Some(msg)); + log::error!("Login failed: {:?}", e); + error.1.set(Some("Geçersiz kullanıcı adı veya şifre".to_string())); + loading.1.set(false); } } - set_loading.set(false); }); }; @@ -54,66 +41,73 @@ pub fn Login() -> impl IntoView {
-

"VibeTorrent Giriş"

+
+
+ + + + +
+

"VibeTorrent"

+

"Hesabınıza giriş yapın"

+
-
-
+ +
-
- -
+
-
-
+
- -
- - {move || error.get()} + +
+ {move || error.0.get().unwrap_or_default()}
-
-
@@ -122,4 +116,4 @@ pub fn Login() -> impl IntoView {
} -} +} \ No newline at end of file diff --git a/frontend/src/components/auth/setup.rs b/frontend/src/components/auth/setup.rs index 8a22835..dcd80d0 100644 --- a/frontend/src/components/auth/setup.rs +++ b/frontend/src/components/auth/setup.rs @@ -1,52 +1,49 @@ use leptos::prelude::*; -use leptos::logging; -use leptos::html; use leptos::task::spawn_local; use crate::api; #[component] pub fn Setup() -> impl IntoView { - let (username, set_username) = create_signal(String::new()); - let (password, set_password) = create_signal(String::new()); - let (confirm_password, set_confirm_password) = create_signal(String::new()); - let (error, set_error) = create_signal(Option::::None); - let (loading, set_loading) = create_signal(false); + let username = signal(String::new()); + let password = signal(String::new()); + let confirm_password = signal(String::new()); + let error = signal(Option::::None); + let loading = signal(false); let handle_setup = move |ev: web_sys::SubmitEvent| { ev.prevent_default(); - set_loading.set(true); - set_error.set(None); - - let pass = password.get(); - let confirm = confirm_password.get(); - + + let pass = password.0.get(); + let confirm = confirm_password.0.get(); + if pass != confirm { - set_error.set(Some("Şifreler eşleşmiyor".to_string())); - set_loading.set(false); + error.1.set(Some("Şifreler eşleşmiyor".to_string())); return; } if pass.len() < 6 { - set_error.set(Some("Şifre en az 6 karakter olmalıdır".to_string())); - set_loading.set(false); + error.1.set(Some("Şifre en az 6 karakter olmalıdır".to_string())); return; } - let username = username.get(); - let password = pass; + loading.1.set(true); + error.1.set(None); + + let user = username.0.get(); spawn_local(async move { - match api::setup::setup(&username, &password).await { + match api::setup::setup(&user, &pass).await { Ok(_) => { - logging::log!("Setup completed successfully, redirecting..."); - let _ = window().location().set_href("/"); + log::info!("Setup completed successfully, redirecting..."); + let window = web_sys::window().expect("window should exist"); + let _ = window.location().set_href("/"); } Err(e) => { - logging::error!("Setup failed: {:?}", e); - set_error.set(Some("Kurulum başarısız oldu".to_string())); + log::error!("Setup failed: {:?}", e); + error.1.set(Some(format!("Hata: {:?}", e))); + loading.1.set(false); } } - set_loading.set(false); }); }; @@ -54,71 +51,74 @@ pub fn Setup() -> impl IntoView {
-

"VibeTorrent Kurulumu"

-

"Yönetici hesabınızı oluşturun"

+
+
+ + + +
+

"VibeTorrent Kurulumu"

+

"Yönetici hesabınızı oluşturun"

+
- -
+ +
-
- -
+
-
- -
+
-
- -
- - {move || error.get()} + +
+ {move || error.0.get().unwrap_or_default()}
-
-
@@ -127,4 +127,4 @@ pub fn Setup() -> impl IntoView {
} -} +} \ No newline at end of file diff --git a/frontend/src/components/context_menu.rs b/frontend/src/components/context_menu.rs index 2bf0be6..19ea8eb 100644 --- a/frontend/src/components/context_menu.rs +++ b/frontend/src/components/context_menu.rs @@ -1,98 +1,97 @@ use leptos::prelude::*; -use leptos::logging; use leptos::html; -use leptos::task::spawn_local; use leptos_use::on_click_outside; +fn handle_action( + hash: String, + action: &str, + on_action: Callback<(String, String)>, + on_close: Callback<()>, +) { + log::info!("ContextMenu: Action '{}' for hash '{}'", action, hash); + on_action.run((action.to_string(), hash)); + on_close.run(()); +} + #[component] pub fn ContextMenu( position: (i32, i32), - visible: bool, torrent_hash: String, on_close: Callback<()>, - on_action: Callback<(String, String)>, // (Action, Hash) + on_action: Callback<(String, String)>, ) -> impl IntoView { - let container_ref = create_node_ref::(); + let container_ref = NodeRef::::new(); let _ = on_click_outside(container_ref, move |_| on_close.run(())); - let handle_action = move |action: &str| { - let hash = torrent_hash.clone(); - let action_str = action.to_string(); - - logging::log!("ContextMenu: Action '{}' for hash '{}'", action_str, hash); - on_action.run((action_str, hash)); // Delegate FIRST - on_close.run(()); // Close menu AFTER - }; - - if !visible { - return view! {}.into_view(); - } + let (x, y) = position; + + let hash1 = torrent_hash.clone(); + let hash2 = torrent_hash.clone(); + let hash3 = torrent_hash.clone(); + let hash4 = torrent_hash.clone(); + let hash5 = torrent_hash; view! {
-
- }.into_view() + } } diff --git a/frontend/src/components/layout/protected.rs b/frontend/src/components/layout/protected.rs index ca9e20a..fde974f 100644 --- a/frontend/src/components/layout/protected.rs +++ b/frontend/src/components/layout/protected.rs @@ -1,33 +1,32 @@ use leptos::prelude::*; -use leptos::logging; -use leptos::html; -use leptos::task::spawn_local; use crate::components::layout::sidebar::Sidebar; -use crate::components::layout::statusbar::StatusBar; use crate::components::layout::toolbar::Toolbar; +use crate::components::layout::statusbar::StatusBar; #[component] pub fn Protected(children: Children) -> impl IntoView { view! {
- -
+ +
+ // --- TOOLBAR (TOP) --- - -
+ + // --- MAIN CONTENT --- +
{children()}
+ // --- STATUS BAR (BOTTOM) ---
-
- - + // --- SIDEBAR (DRAWER) --- +
+ +
} -} +} \ No newline at end of file diff --git a/frontend/src/components/layout/sidebar.rs b/frontend/src/components/layout/sidebar.rs index 7a078cd..65058fe 100644 --- a/frontend/src/components/layout/sidebar.rs +++ b/frontend/src/components/layout/sidebar.rs @@ -1,7 +1,5 @@ -use leptos::wasm_bindgen::JsCast; use leptos::prelude::*; -use leptos::logging; -use leptos::html; +use leptos::wasm_bindgen::JsCast; use leptos::task::spawn_local; use crate::api; @@ -76,195 +74,104 @@ pub fn Sidebar() -> impl IntoView { let handle_logout = move |_| { spawn_local(async move { if api::auth::logout().await.is_ok() { - let _ = window().location().set_href("/login"); + let window = web_sys::window().expect("window should exist"); + let _ = window.location().set_href("/login"); } }); }; - let username = move || { - - store.user.get().unwrap_or_else(|| "User".to_string()) - - }; - - - - let first_letter = move || { - - username().chars().next().unwrap_or('?').to_uppercase().to_string() - - }; - - - - view! { - -
- -
- - - + let username = move || { + store.user.get().unwrap_or_else(|| "User".to_string()) + }; + + let first_letter = move || { + username().chars().next().unwrap_or('?').to_uppercase().to_string() + }; + + view! { +
+
+ +
+ +
+
+
+
+ {first_letter}
- - - -
- -
- -
- -
- - {first_letter} - -
- -
- -
- -
{username}
- -
"Online"
- -
- - - -
- -
-
- - }} +
+
{username}
+
"Online"
+
+ +
+
+
+ } +} \ No newline at end of file diff --git a/frontend/src/components/layout/statusbar.rs b/frontend/src/components/layout/statusbar.rs index df6934b..a6ad209 100644 --- a/frontend/src/components/layout/statusbar.rs +++ b/frontend/src/components/layout/statusbar.rs @@ -1,11 +1,8 @@ use leptos::prelude::*; -use leptos::logging; use leptos::html; -use leptos::task::spawn_local; use leptos_use::storage::use_local_storage; use ::codee::string::FromToStringCodec; use shared::GlobalLimitRequest; -use reactive_graph::traits::{Get, Set, GetUntracked}; use crate::api; fn format_bytes(bytes: i64) -> String { @@ -33,16 +30,16 @@ pub fn StatusBar() -> impl IntoView { let store = use_context::().expect("store not provided"); let stats = store.global_stats; - // Use leptos-use for reactive localStorage management let (current_theme, set_current_theme, _) = use_local_storage::("vibetorrent_theme"); // Initialize with default if empty - if current_theme.get_untracked().is_empty() { + let current_theme_val = current_theme.get(); + if current_theme_val.is_empty() { set_current_theme.set("dark".to_string()); } // Automatically sync theme to document attribute - create_effect(move |_| { + Effect::new(move |_| { let theme = current_theme.get().to_lowercase(); if let Some(doc) = document().document_element() { let _ = doc.set_attribute("data-theme", &theme); @@ -50,7 +47,7 @@ pub fn StatusBar() -> impl IntoView { }); // Preset limits in bytes/s - let limits: Vec<(i64, &str)> = vec![ + let limits: Vec<(i64, &str)> = vec!( (0, "Unlimited"), (100 * 1024, "100 KB/s"), (500 * 1024, "500 KB/s"), @@ -59,11 +56,11 @@ pub fn StatusBar() -> impl IntoView { (5 * 1024 * 1024, "5 MB/s"), (10 * 1024 * 1024, "10 MB/s"), (20 * 1024 * 1024, "20 MB/s"), - ]; + ); let set_limit = move |limit_type: &str, val: i64| { let limit_type = limit_type.to_string(); - logging::log!("Setting {} limit to {}", limit_type, val); + log::info!("Setting {} limit to {}", limit_type, val); let req = if limit_type == "down" { GlobalLimitRequest { @@ -77,22 +74,20 @@ pub fn StatusBar() -> impl IntoView { } }; - spawn_local(async move { + leptos::task::spawn_local(async move { if let Err(e) = api::settings::set_global_limits(&req).await { - logging::error!("Failed to set limit: {:?}", e); + log::error!("Failed to set limit: {:?}", e); } else { - logging::log!("Limit set successfully"); + log::info!("Limit set successfully"); } }); }; - // Refs for click outside detection (Handled globally via JS in index.html for better iOS support) - let down_details_ref = create_node_ref::(); - let up_details_ref = create_node_ref::(); - let theme_details_ref = create_node_ref::(); + let down_details_ref = NodeRef::::new(); + let up_details_ref = NodeRef::::new(); + let theme_details_ref = NodeRef::::new(); - // Helper to close a details element - let close_details = |node_ref: NodeRef| { + let close_details = move |node_ref: NodeRef| { if let Some(el) = node_ref.get_untracked() { el.set_open(false); } @@ -199,16 +194,19 @@ pub fn StatusBar() -> impl IntoView { "light", "dark", "dim", "nord", "cupcake", "dracula", "cyberpunk", "emerald", "sunset", "abyss" ]; themes.into_iter().map(|theme| { + let theme_name = theme.to_string(); + let theme_name_for_class = theme_name.clone(); + let theme_name_for_onclick = theme_name.clone(); view! {
  • } @@ -221,7 +219,7 @@ pub fn StatusBar() -> impl IntoView { title="Settings & Notification Permissions" on:click=move |_| { // Request push notification permission when settings button is clicked - spawn_local(async { + leptos::task::spawn_local(async { log::info!("Settings button clicked - requesting push notification permission"); // Check current permission state before requesting @@ -266,11 +264,11 @@ pub fn StatusBar() -> impl IntoView { } > - +
    } -} +} \ No newline at end of file diff --git a/frontend/src/components/layout/toolbar.rs b/frontend/src/components/layout/toolbar.rs index e6753af..098f2a3 100644 --- a/frontend/src/components/layout/toolbar.rs +++ b/frontend/src/components/layout/toolbar.rs @@ -1,11 +1,9 @@ use leptos::prelude::*; -use leptos::logging; -use leptos::html; -use leptos::task::spawn_local; +use crate::components::torrent::add_torrent::AddTorrentDialog; #[component] pub fn Toolbar() -> impl IntoView { - let (show_add_modal, set_show_add_modal) = create_signal(false); + let show_add_modal = signal(false); let store = use_context::().expect("store not provided"); view! { @@ -14,54 +12,48 @@ pub fn Toolbar() -> impl IntoView { - -
    -
    - -
    - } -} +} \ No newline at end of file diff --git a/frontend/src/components/modal.rs b/frontend/src/components/modal.rs index 8da4190..4200480 100644 --- a/frontend/src/components/modal.rs +++ b/frontend/src/components/modal.rs @@ -1,12 +1,9 @@ use leptos::prelude::*; -use leptos::logging; -use leptos::html; -use leptos::task::spawn_local; #[component] pub fn Modal( #[prop(into)] title: String, - children: Children, + children: ChildrenFn, #[prop(into)] on_confirm: Callback<()>, #[prop(into)] on_cancel: Callback<()>, #[prop(into)] visible: Signal, @@ -15,8 +12,6 @@ pub fn Modal( #[prop(into, default = false)] is_danger: bool, ) -> impl IntoView { let title = StoredValue::new_local(title); - // Eagerly render children to a Fragment, which is Clone - let child_view = StoredValue::new_local(children()); let on_confirm = StoredValue::new_local(on_confirm); let on_cancel = StoredValue::new_local(on_cancel); let confirm_text = StoredValue::new_local(confirm_text); @@ -26,10 +21,10 @@ pub fn Modal(
    -

    {title.get_value()}

    +

    {move || title.get_value()}

    - {child_view.with_value(|c| c.clone())} + {children()}
    @@ -37,7 +32,7 @@ pub fn Modal( class="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2" on:click=move |_| on_cancel.with_value(|cb| cb.run(())) > - {cancel_text.get_value()} + {move || cancel_text.get_value()}
    diff --git a/frontend/src/components/torrent/add_torrent.rs b/frontend/src/components/torrent/add_torrent.rs index 5d757e7..6a64750 100644 --- a/frontend/src/components/torrent/add_torrent.rs +++ b/frontend/src/components/torrent/add_torrent.rs @@ -1,66 +1,64 @@ use leptos::prelude::*; -use leptos::logging; use leptos::html; use leptos::task::spawn_local; -use leptos::html::Dialog; -use crate::store::{show_toast_with_signal, TorrentStore}; +use crate::store::TorrentStore; use crate::api; -use shared::NotificationLevel; - #[component] -pub fn AddTorrentModal( - #[prop(into)] +pub fn AddTorrentDialog( on_close: Callback<()>, ) -> impl IntoView { let store = use_context::().expect("TorrentStore not provided"); let notifications = store.notifications; - - let dialog_ref = create_node_ref::(); - let (uri, set_uri) = create_signal(String::new()); - let (is_loading, set_loading) = create_signal(false); - let (error_msg, set_error_msg) = create_signal(Option::::None); - create_effect(move |_| { + let dialog_ref = NodeRef::::new(); + let uri = signal(String::new()); + let is_loading = signal(false); + let error_msg = signal(Option::::None); + + Effect::new(move |_| { if let Some(dialog) = dialog_ref.get() { let _ = dialog.show_modal(); } }); - let handle_submit = move |_| { - let uri_val = uri.get(); + let handle_submit = move |ev: web_sys::SubmitEvent| { + ev.prevent_default(); + let uri_val = uri.0.get(); + if uri_val.is_empty() { - show_toast_with_signal(notifications, NotificationLevel::Warning, "Lütfen bir Magnet URI veya URL girin"); - set_error_msg.set(Some("Please enter a Magnet URI or URL".to_string())); + error_msg.1.set(Some("Please enter a Magnet URI or URL".to_string())); return; } - set_loading.set(true); - set_error_msg.set(None); + is_loading.1.set(true); + error_msg.1.set(None); - let uri_val = uri_val; + let on_close = on_close.clone(); spawn_local(async move { match api::torrent::add(&uri_val).await { Ok(_) => { - logging::log!("Torrent added successfully"); - show_toast_with_signal(notifications, NotificationLevel::Success, "Torrent eklendi"); - set_loading.set(false); + log::info!("Torrent added successfully"); + crate::store::show_toast_with_signal( + notifications, + shared::NotificationLevel::Success, + "Torrent başarıyla eklendi" + ); if let Some(dialog) = dialog_ref.get() { dialog.close(); } on_close.run(()); } Err(e) => { - logging::error!("Failed to add torrent: {:?}", e); - show_toast_with_signal(notifications, NotificationLevel::Error, "Torrent eklenemedi"); - set_error_msg.set(Some(format!("Error: {:?}", e))); - set_loading.set(false); + log::error!("Failed to add torrent: {:?}", e); + error_msg.1.set(Some(format!("Hata: {:?}", e))); + is_loading.1.set(false); } } }); }; - let handle_close = move |_| { + let handle_cancel = move |_| { if let Some(dialog) = dialog_ref.get() { dialog.close(); } @@ -71,37 +69,40 @@ pub fn AddTorrentModal( } -} +} \ No newline at end of file diff --git a/frontend/src/components/torrent/table.rs b/frontend/src/components/torrent/table.rs index 6e6ea7d..bac5e61 100644 --- a/frontend/src/components/torrent/table.rs +++ b/frontend/src/components/torrent/table.rs @@ -1,142 +1,80 @@ use leptos::prelude::*; -use leptos::logging; use leptos::html; use leptos::task::spawn_local; -use leptos_use::{on_click_outside, use_timeout_fn}; -use crate::store::{get_action_messages, show_toast_with_signal, FilterStatus}; +use leptos_use::use_timeout_fn; +use crate::store::{get_action_messages, show_toast_with_signal}; use crate::api; use shared::{NotificationLevel, Torrent}; -use std::collections::HashMap; fn format_bytes(bytes: i64) -> String { const UNITS: [&str; 6] = ["B", "KB", "MB", "GB", "TB", "PB"]; - if bytes < 1024 { - return format!("{} B", bytes); - } + if bytes < 1024 { return format!("{} B", bytes); } let i = (bytes as f64).log2().div_euclid(10.0) as usize; - format!( - "{:.1} {}", - (bytes as f64) / 1024_f64.powi(i as i32), - UNITS[i] - ) + format!("{:.1} {}", (bytes as f64) / 1024_f64.powi(i as i32), UNITS[i]) } fn format_speed(bytes_per_sec: i64) -> String { - if bytes_per_sec == 0 { - return "0 B/s".to_string(); - } + if bytes_per_sec == 0 { return "0 B/s".to_string(); } format!("{}/s", format_bytes(bytes_per_sec)) } fn format_duration(seconds: i64) -> String { - if seconds <= 0 { - return "∞".to_string(); - } - + if seconds <= 0 { return "∞".to_string(); } let days = seconds / 86400; let hours = (seconds % 86400) / 3600; let minutes = (seconds % 3600) / 60; let secs = seconds % 60; - - if days > 0 { - format!("{}d {}h", days, hours) - } else if hours > 0 { - format!("{}h {}m", hours, minutes) - } else if minutes > 0 { - format!("{}m {}s", minutes, secs) - } else { - format!("{}s", secs) - } + if days > 0 { format!("{}d {}h", days, hours) } + else if hours > 0 { format!("{}h {}m", hours, minutes) } + else if minutes > 0 { format!("{}m {}s", minutes, secs) } + else { format!("{}s", secs) } } fn format_date(timestamp: i64) -> String { - if timestamp <= 0 { - return "N/A".to_string(); - } + if timestamp <= 0 { return "N/A".to_string(); } let dt = chrono::DateTime::from_timestamp(timestamp, 0); - match dt { - Some(dt) => dt.format("%d/%m/%Y %H:%M").to_string(), - None => "N/A".to_string(), - } + match dt { Some(dt) => dt.format("%d/%m/%Y %H:%M").to_string(), None => "N/A".to_string() } } #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum SortColumn { - Name, - Size, - Progress, - Status, - DownSpeed, - UpSpeed, - ETA, - AddedDate, + Name, Size, Progress, Status, DownSpeed, UpSpeed, ETA, AddedDate, } #[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum SortDirection { - Ascending, - Descending, -} +enum SortDirection { Ascending, Descending } #[component] pub fn TorrentTable() -> impl IntoView { let store = use_context::().expect("store not provided"); + let sort_col = signal(SortColumn::AddedDate); + let sort_dir = signal(SortDirection::Descending); - let sort_col = create_rw_signal(SortColumn::AddedDate); - let sort_dir = create_rw_signal(SortDirection::Descending); - - // Get sorted and filtered hashes only let filtered_hashes = move || { store.torrents.with(|map| { - let mut torrents: Vec<&shared::Torrent> = map - .values() - .filter(|t| { - let filter = store.filter.get(); - let search = store.search_query.get().to_lowercase(); - - let matches_filter = match filter { - crate::store::FilterStatus::All => true, - crate::store::FilterStatus::Downloading => { - t.status == shared::TorrentStatus::Downloading - } - crate::store::FilterStatus::Seeding => { - t.status == shared::TorrentStatus::Seeding - } - crate::store::FilterStatus::Completed => { - t.status == shared::TorrentStatus::Seeding - || (t.status == shared::TorrentStatus::Paused - && t.percent_complete >= 100.0) - } - crate::store::FilterStatus::Paused => { - t.status == shared::TorrentStatus::Paused - } - crate::store::FilterStatus::Inactive => { - t.status == shared::TorrentStatus::Paused - || t.status == shared::TorrentStatus::Error - } - _ => true, - }; - - let matches_search = if search.is_empty() { - true - } else { - t.name.to_lowercase().contains(&search) - }; - - matches_filter && matches_search - }) - .collect(); + let mut torrents: Vec<&shared::Torrent> = map.values().filter(|t| { + let filter = store.filter.get(); + let search = store.search_query.get().to_lowercase(); + let matches_filter = match filter { + crate::store::FilterStatus::All => true, + crate::store::FilterStatus::Downloading => t.status == shared::TorrentStatus::Downloading, + crate::store::FilterStatus::Seeding => t.status == shared::TorrentStatus::Seeding, + crate::store::FilterStatus::Completed => t.status == shared::TorrentStatus::Seeding || (t.status == shared::TorrentStatus::Paused && t.percent_complete >= 100.0), + crate::store::FilterStatus::Paused => t.status == shared::TorrentStatus::Paused, + crate::store::FilterStatus::Inactive => t.status == shared::TorrentStatus::Paused || t.status == shared::TorrentStatus::Error, + _ => true, + }; + let matches_search = if search.is_empty() { true } else { t.name.to_lowercase().contains(&search) }; + matches_filter && matches_search + }).collect(); torrents.sort_by(|a, b| { - let col = sort_col.get(); - let dir = sort_dir.get(); + let col = sort_col.0.get(); + let dir = sort_dir.0.get(); let cmp = match col { SortColumn::Name => a.name.to_lowercase().cmp(&b.name.to_lowercase()), SortColumn::Size => a.size.cmp(&b.size), - SortColumn::Progress => a - .percent_complete - .partial_cmp(&b.percent_complete) - .unwrap_or(std::cmp::Ordering::Equal), + SortColumn::Progress => a.percent_complete.partial_cmp(&b.percent_complete).unwrap_or(std::cmp::Ordering::Equal), SortColumn::Status => format!("{:?}", a.status).cmp(&format!("{:?}", b.status)), SortColumn::DownSpeed => a.down_rate.cmp(&b.down_rate), SortColumn::UpSpeed => a.up_rate.cmp(&b.up_rate), @@ -147,78 +85,50 @@ pub fn TorrentTable() -> impl IntoView { } SortColumn::AddedDate => a.added_date.cmp(&b.added_date), }; - if dir == SortDirection::Descending { - cmp.reverse() - } else { - cmp - } + if dir == SortDirection::Descending { cmp.reverse() } else { cmp } }); - torrents.into_iter().map(|t| t.hash.clone()).collect::>() }) }; let handle_sort = move |col: SortColumn| { - if sort_col.get() == col { - sort_dir.update(|d| { - *d = match d { - SortDirection::Ascending => SortDirection::Descending, - SortDirection::Descending => SortDirection::Ascending, - } + if sort_col.0.get() == col { + sort_dir.1.update(|d| { + *d = match d { SortDirection::Ascending => SortDirection::Descending, SortDirection::Descending => SortDirection::Ascending }; }); } else { - sort_col.set(col); - sort_dir.set(SortDirection::Ascending); + sort_col.1.set(col); + sort_dir.1.set(SortDirection::Ascending); } }; - // Refs for click outside detection - let sort_details_ref = create_node_ref::(); - let _ = on_click_outside(sort_details_ref, move |_| { - if let Some(el) = sort_details_ref.get_untracked() { - el.set_open(false); - } - }); + let sort_details_ref = NodeRef::::new(); let sort_arrow = move |col: SortColumn| { - if sort_col.get() == col { - match sort_dir.get() { - SortDirection::Ascending => { - view! { "▲" }.into_any() - } - SortDirection::Descending => { - view! { "▼" }.into_any() - } + if sort_col.0.get() == col { + match sort_dir.0.get() { + SortDirection::Ascending => view! { "▲" }.into_any(), + SortDirection::Descending => view! { "▼" }.into_any(), } - } else { - view! { "▲" } - .into_any() - } + } else { view! { "▲" }.into_any() } }; - let (selected_hash, set_selected_hash) = create_signal(Option::::None); - let (menu_visible, set_menu_visible) = create_signal(false); - let (menu_position, set_menu_position) = create_signal((0, 0)); + let selected_hash = signal(Option::::None); + let menu_visible = signal(false); + let menu_position = signal((0, 0)); let handle_context_menu = move |e: web_sys::MouseEvent, hash: String| { e.prevent_default(); - set_menu_position.set((e.client_x(), e.client_y())); - set_selected_hash.set(Some(hash)); // Select on right click too - set_menu_visible.set(true); + menu_position.1.set((e.client_x(), e.client_y())); + selected_hash.1.set(Some(hash)); + menu_visible.1.set(true); }; let on_action = move |(action, hash): (String, String)| { - logging::log!("TorrentTable Action: {} on {}", action, hash); - - let (success_msg, error_msg) = get_action_messages(&action); - let success_msg = success_msg.to_string(); - let error_msg = error_msg.to_string(); - + let (success_msg_str, error_msg_str): (&'static str, &'static str) = get_action_messages(&action); + let success_msg = success_msg_str.to_string(); + let error_msg = error_msg_str.to_string(); let notifications = store.notifications; - - let hash = hash.clone(); - let action = action.clone(); - spawn_local(async move { let result = match action.as_str() { "delete" => api::torrent::delete(&hash).await, @@ -227,16 +137,9 @@ pub fn TorrentTable() -> impl IntoView { "stop" => api::torrent::stop(&hash).await, _ => api::torrent::action(&hash, &action).await, }; - match result { - Ok(_) => { - logging::log!("Action {} executed successfully", action); - show_toast_with_signal(notifications, NotificationLevel::Success, success_msg); - } - Err(e) => { - logging::error!("Action failed: {:?}", e); - show_toast_with_signal(notifications, NotificationLevel::Error, format!("{}: {:?}", error_msg, e)); - } + Ok(_) => show_toast_with_signal(notifications, NotificationLevel::Success, success_msg), + Err(e) => show_toast_with_signal(notifications, NotificationLevel::Error, format!("{}: {:?}", error_msg, e)), } }); }; @@ -274,23 +177,10 @@ pub fn TorrentTable() -> impl IntoView { - - } - } - } - /> + } + } />
    @@ -298,53 +188,22 @@ pub fn TorrentTable() -> impl IntoView {
    "Torrents" -
    -
    - - } - } - } - /> + } + } />
    - - + +
    } @@ -398,45 +235,29 @@ fn TorrentRow( on_context_menu: impl Fn(web_sys::MouseEvent, String) + 'static + Clone + Send + Sync, ) -> impl IntoView { let store = use_context::().expect("store not provided"); - let h = hash.clone(); - // Memoized access to the specific torrent data. - // This only re-renders the row if this specific torrent actually changes. - let torrent = create_memo(move |_| { - store.torrents.with(|map| map.get(&h).cloned()) - }); + let torrent = Memo::new(move |_| store.torrents.with(|map| map.get(&h).cloned())); view! { { let on_context_menu = on_context_menu.clone(); let hash = hash.clone(); - move || { let t = torrent.get().unwrap(); let t_hash = hash.clone(); - let t_hash_class = t_hash.clone(); - let on_context_menu = on_context_menu.clone(); - + let t_name = t.name.clone(); + let status_class = match t.status { shared::TorrentStatus::Seeding => "text-success", shared::TorrentStatus::Downloading => "text-primary", shared::TorrentStatus::Paused => "text-warning", shared::TorrentStatus::Error => "text-error", _ => "text-base-content/50" }; let progress_class = if t.percent_complete >= 100.0 { "progress-success" } else { "progress-primary" }; - let status_str = format!("{:?}", t.status); - let status_class = match t.status { - shared::TorrentStatus::Seeding => "text-success", - shared::TorrentStatus::Downloading => "text-primary", - shared::TorrentStatus::Paused => "text-warning", - shared::TorrentStatus::Error => "text-error", - _ => "text-base-content/50" - }; + + let selected_hash_clone = selected_hash.clone(); + let t_hash_row = t_hash.clone(); view! { - - {t.name.clone()} - + {t_name.clone()} {format_bytes(t.size)}
    @@ -458,7 +278,7 @@ fn TorrentRow( {format!("{:.1}%", t.percent_complete)}
    - {status_str} + {format!("{:?}", t.status)} {format_speed(t.down_rate)} {format_speed(t.up_rate)} {format_duration(t.eta)} @@ -481,84 +301,43 @@ fn TorrentCard( on_context_menu: impl Fn(web_sys::MouseEvent, String) + 'static + Clone + Send + Sync, ) -> impl IntoView { let store = use_context::().expect("store not provided"); - let h = hash.clone(); - let torrent = create_memo(move |_| { - store.torrents.with(|map| map.get(&h).cloned()) - }); + let torrent = Memo::new(move |_| store.torrents.with(|map| map.get(&h).cloned())); view! { { let hash = hash.clone(); let on_context_menu = on_context_menu.clone(); - move || { let t = torrent.get().unwrap(); let t_hash = hash.clone(); - let t_hash_class = t_hash.clone(); - let on_context_menu = on_context_menu.clone(); - - let progress_class = if t.percent_complete >= 100.0 { "progress-success" } else { "progress-primary" }; - let status_str = format!("{:?}", t.status); - let status_badge_class = match t.status { - shared::TorrentStatus::Seeding => "badge-success badge-soft", - shared::TorrentStatus::Downloading => "badge-primary badge-soft", - shared::TorrentStatus::Paused => "badge-warning badge-soft", - shared::TorrentStatus::Error => "badge-error badge-soft", - _ => "badge-ghost" - }; + let t_name = t.name.clone(); + let status_badge_class = match t.status { shared::TorrentStatus::Seeding => "badge-success badge-soft", shared::TorrentStatus::Downloading => "badge-primary badge-soft", shared::TorrentStatus::Paused => "badge-warning badge-soft", shared::TorrentStatus::Error => "badge-error badge-soft", _ => "badge-ghost" }; let t_hash_long = t_hash.clone(); - let leptos_use::UseTimeoutFnReturn { start, stop, .. } = use_timeout_fn( + let set_menu_position = set_menu_position.clone(); + let set_selected_hash = set_selected_hash.clone(); + let set_menu_visible = set_menu_visible.clone(); + let leptos_use::UseTimeoutFnReturn { start, .. } = use_timeout_fn( move |pos: (i32, i32)| { set_menu_position.set(pos); set_selected_hash.set(Some(t_hash_long.clone())); set_menu_visible.set(true); - - // Haptic feedback - let navigator = window().navigator(); - if let Ok(vibrate) = js_sys::Reflect::get(&navigator, &"vibrate".into()) { - if vibrate.is_function() { - let _ = navigator.vibrate_with_duration(50); - } - } + let _ = window().navigator().vibrate_with_duration(50); }, 600.0, ); - let handle_touchstart = { - let start = start.clone(); - move |e: web_sys::TouchEvent| { - if let Some(touch) = e.touches().get(0) { - start((touch.client_x(), touch.client_y())); - } - } - }; - - let handle_touchmove = { - let stop = stop.clone(); - move |_| stop() - }; - - let handle_touchend = { - let stop = stop.clone(); - move |_| stop() - }; - - let handle_touchcancel = move |_| stop(); + let selected_hash_clone = selected_hash.clone(); + let t_hash_card = t_hash.clone(); view! {
    -

    {t.name}

    -
    - {status_str} -
    +

    {t_name.clone()}

    +
    {format!("{:?}", t.status)}
    -
    {format_bytes(t.size)} {format!("{:.1}%", t.percent_complete)}
    - +
    -
    -
    - "Down" - {format_speed(t.down_rate)} -
    -
    - "Up" - {format_speed(t.up_rate)} -
    -
    - "ETA" - {format_duration(t.eta)} -
    -
    - "Date" - {format_date(t.added_date)} -
    +
    "DL"{format_speed(t.down_rate)}
    +
    "UP"{format_speed(t.up_rate)}
    +
    "ETA"{format_duration(t.eta)}
    +
    "DATE"{format_date(t.added_date)}
    diff --git a/frontend/src/store.rs b/frontend/src/store.rs index db30016..9f1000f 100644 --- a/frontend/src/store.rs +++ b/frontend/src/store.rs @@ -1,9 +1,9 @@ use futures::StreamExt; use gloo_net::eventsource::futures::EventSource; use leptos::prelude::*; -use leptos::logging; -use leptos::task::spawn_local; use shared::{AppEvent, GlobalStats, NotificationLevel, SystemNotification, Torrent}; +use std::collections::HashMap; +use serde::{Serialize, Deserialize}; #[derive(Clone, Debug, PartialEq)] pub struct NotificationItem { @@ -12,12 +12,9 @@ pub struct NotificationItem { } // ============================================================================ -// Toast Helper Functions (Clean Code: Single Responsibility) +// Toast Helper Functions // ============================================================================ -/// Shows a toast notification using a direct signal reference. -/// Use this version inside async blocks (spawn_local) where use_context is unavailable. -/// Auto-removes after 5 seconds. pub fn show_toast_with_signal( notifications: RwSignal>, level: NotificationLevel, @@ -33,7 +30,7 @@ pub fn show_toast_with_signal( notifications.update(|list| list.push(item)); // Auto-remove after 5 seconds - let _ = set_timeout( + leptos::prelude::set_timeout( move || { notifications.update(|list| list.retain(|i| i.id != id)); }, @@ -41,41 +38,19 @@ pub fn show_toast_with_signal( ); } -/// Shows a toast notification with the given level and message. -/// Only works within reactive scope (components, effects). For async, use show_toast_with_signal. -/// Auto-removes after 5 seconds. pub fn show_toast(level: NotificationLevel, message: impl Into) { if let Some(store) = use_context::() { show_toast_with_signal(store.notifications, level, message); } } -/// Convenience function for success toasts (reactive scope only) -pub fn toast_success(message: impl Into) { - show_toast(NotificationLevel::Success, message); -} - -/// Convenience function for error toasts (reactive scope only) -pub fn toast_error(message: impl Into) { - show_toast(NotificationLevel::Error, message); -} - -/// Convenience function for info toasts (reactive scope only) -pub fn toast_info(message: impl Into) { - show_toast(NotificationLevel::Info, message); -} - -/// Convenience function for warning toasts (reactive scope only) -pub fn toast_warning(message: impl Into) { - show_toast(NotificationLevel::Warning, message); -} +pub fn toast_success(message: impl Into) { show_toast(NotificationLevel::Success, message); } +pub fn toast_error(message: impl Into) { show_toast(NotificationLevel::Error, message); } // ============================================================================ -// Action Message Mapping (Clean Code: DRY Principle) +// Action Message Mapping // ============================================================================ -/// Maps torrent action strings to user-friendly Turkish messages. -/// Returns (success_message, error_message) pub fn get_action_messages(action: &str) -> (&'static str, &'static str) { match action { "start" => ("Torrent başlatıldı", "Torrent başlatılamadı"), @@ -88,35 +63,27 @@ pub fn get_action_messages(action: &str) -> (&'static str, &'static str) { } } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct PushSubscriptionData { + pub endpoint: String, + pub keys: PushKeys, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct PushKeys { + pub p256dh: String, + pub auth: String, +} + +// ============================================================================ +// Store Definition +// ============================================================================ + #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum FilterStatus { - All, - Downloading, - Seeding, - Completed, - Paused, - Inactive, - Active, - Error, + All, Downloading, Seeding, Completed, Paused, Inactive, Active, Error, } -impl FilterStatus { - pub fn as_str(&self) -> &'static str { - match self { - FilterStatus::All => "All", - FilterStatus::Downloading => "Downloading", - FilterStatus::Seeding => "Seeding", - FilterStatus::Completed => "Completed", - FilterStatus::Paused => "Paused", - FilterStatus::Inactive => "Inactive", - FilterStatus::Active => "Active", - FilterStatus::Error => "Error", - } - } -} - -use std::collections::HashMap; - #[derive(Clone, Copy, Debug)] pub struct TorrentStore { pub torrents: RwSignal>, @@ -128,393 +95,104 @@ pub struct TorrentStore { } pub fn provide_torrent_store() { - let torrents = create_rw_signal(HashMap::new()); - let filter = create_rw_signal(FilterStatus::All); - let search_query = create_rw_signal(String::new()); - let global_stats = create_rw_signal(GlobalStats::default()); - let notifications = create_rw_signal(Vec::::new()); - let user = create_rw_signal(Option::::None); + let torrents = RwSignal::new(HashMap::new()); + let filter = RwSignal::new(FilterStatus::All); + let search_query = RwSignal::new(String::new()); + let global_stats = RwSignal::new(GlobalStats::default()); + let notifications = RwSignal::new(Vec::::new()); + let user = RwSignal::new(Option::::None); - // Browser notification hook let show_browser_notification = crate::utils::notification::use_app_notification(); - let store = TorrentStore { - torrents, - filter, - search_query, - global_stats, - notifications, - user, - }; + let store = TorrentStore { torrents, filter, search_query, global_stats, notifications, user }; provide_context(store); - // Initialize SSE connection with auto-reconnect - create_effect(move |_| { - // Sadece kullanıcı giriş yapmışsa bağlantıyı başlat - if user.get().is_none() { - logging::log!("SSE: User not authenticated, skipping connection."); - return; - } + // SSE Connection + Effect::new(move |_| { + if user.get().is_none() { return; } let show_browser_notification = show_browser_notification.clone(); - spawn_local(async move { - let mut backoff_ms: u32 = 1000; // Start with 1 second - let max_backoff_ms: u32 = 30000; // Max 30 seconds + leptos::task::spawn_local(async move { + let mut backoff_ms: u32 = 1000; let mut was_connected = false; - let mut disconnect_notified = false; // Track if we already showed disconnect toast - let mut got_first_message; // Only count as "connected" after receiving data + let mut disconnect_notified = false; loop { let es_result = EventSource::new("/api/events"); - match es_result { Ok(mut es) => { - match es.subscribe("message") { - Ok(mut stream) => { - // Don't show "connected" toast yet - wait for first real message - got_first_message = false; - - // Process messages - while let Some(Ok((_, msg))) = stream.next().await { - // First successful message = truly connected - if !got_first_message { - got_first_message = true; - backoff_ms = 1000; // Reset backoff on real data - - if was_connected && disconnect_notified { - // We were previously connected, lost connection, and now truly reconnected - show_toast_with_signal( - notifications, - NotificationLevel::Success, - "Sunucu bağlantısı yeniden kuruldu", - ); - disconnect_notified = false; - } - was_connected = true; + if let Ok(mut stream) = es.subscribe("message") { + let mut got_first_message = false; + while let Some(Ok((_, msg))) = stream.next().await { + if !got_first_message { + got_first_message = true; + backoff_ms = 1000; + if was_connected && disconnect_notified { + show_toast_with_signal(notifications, NotificationLevel::Success, "Sunucu bağlantısı yeniden kuruldu"); + disconnect_notified = false; } + was_connected = true; + } - if let Some(data_str) = msg.data().as_string() { - if let Ok(event) = serde_json::from_str::(&data_str) { - match event { - AppEvent::FullList { torrents: list, .. } => { - torrents.update(|map| { - // 1. Create a set of new hashes for quick lookup - let new_hashes: std::collections::HashSet = list.iter().map(|t| t.hash.clone()).collect(); - - // 2. Remove torrents that are no longer in the list - map.retain(|hash, _| new_hashes.contains(hash)); - - // 3. Update or Insert torrents from the new list - for new_torrent in list { - if let Some(existing) = map.get_mut(&new_torrent.hash) { - // Only update if changed (Torrent derives PartialEq) - if existing != &new_torrent { - *existing = new_torrent; - } - } else { - // New torrent, insert it - map.insert(new_torrent.hash.clone(), new_torrent); - } - } - }); - } - AppEvent::Update(update) => { - torrents.update(|map| { - if let Some(t) = map.get_mut(&update.hash) { - if let Some(name) = update.name { - t.name = name; - } - if let Some(size) = update.size { - t.size = size; - } - if let Some(down_rate) = update.down_rate { - t.down_rate = down_rate; - } - if let Some(up_rate) = update.up_rate { - t.up_rate = up_rate; - } - if let Some(percent_complete) = update.percent_complete { - t.percent_complete = percent_complete; - } - if let Some(completed) = update.completed { - t.completed = completed; - } - if let Some(eta) = update.eta { - t.eta = eta; - } - if let Some(status) = update.status { - t.status = status; - } - if let Some(error_message) = update.error_message { - t.error_message = error_message; - } - if let Some(label) = update.label { - t.label = Some(label); - } - } - }); - } - AppEvent::Stats(stats) => { - global_stats.set(stats); - } - AppEvent::Notification(n) => { - // Show toast notification - show_toast_with_signal(notifications, n.level.clone(), n.message.clone()); - - // Show browser notification for critical events - let is_critical = n.message.contains("tamamlandı") - || n.level == shared::NotificationLevel::Error; - - if is_critical { - let title = match n.level { - shared::NotificationLevel::Success => "✅ VibeTorrent", - shared::NotificationLevel::Error => "❌ VibeTorrent", - shared::NotificationLevel::Warning => "⚠️ VibeTorrent", - shared::NotificationLevel::Info => "ℹ️ VibeTorrent", - }; - - show_browser_notification( - title, - &n.message - ); + if let Some(data_str) = msg.data().as_string() { + if let Ok(event) = serde_json::from_str::(&data_str) { + match event { + AppEvent::FullList { torrents: list, .. } => { + torrents.update(|map| { + let new_hashes: std::collections::HashSet = list.iter().map(|t| t.hash.clone()).collect(); + map.retain(|hash, _| new_hashes.contains(hash)); + for new_torrent in list { + map.insert(new_torrent.hash.clone(), new_torrent); } + }); + } + AppEvent::Update(update) => { + torrents.update(|map| { + if let Some(t) = map.get_mut(&update.hash) { + if let Some(v) = update.name { t.name = v; } + if let Some(v) = update.size { t.size = v; } + if let Some(v) = update.down_rate { t.down_rate = v; } + if let Some(v) = update.up_rate { t.up_rate = v; } + if let Some(v) = update.percent_complete { t.percent_complete = v; } + if let Some(v) = update.completed { t.completed = v; } + if let Some(v) = update.eta { t.eta = v; } + if let Some(v) = update.status { t.status = v; } + if let Some(v) = update.error_message { t.error_message = v; } + if let Some(v) = update.label { t.label = Some(v); } + } + }); + } + AppEvent::Stats(stats) => { global_stats.set(stats); } + AppEvent::Notification(n) => { + show_toast_with_signal(notifications, n.level.clone(), n.message.clone()); + if n.message.contains("tamamlandı") || n.level == shared::NotificationLevel::Error { + show_browser_notification("VibeTorrent", &n.message); } } } } } - - // Stream ended - connection lost - if was_connected && !disconnect_notified { - show_toast_with_signal( - notifications, - NotificationLevel::Warning, - "Sunucu bağlantısı kesildi, yeniden bağlanılıyor...", - ); - disconnect_notified = true; - } } - Err(_) => { - // Failed to subscribe - only notify once - if was_connected && !disconnect_notified { - show_toast_with_signal( - notifications, - NotificationLevel::Warning, - "Sunucu bağlantısı kesildi, yeniden bağlanılıyor...", - ); - disconnect_notified = true; - } + if was_connected && !disconnect_notified { + show_toast_with_signal(notifications, NotificationLevel::Warning, "Sunucu bağlantısı kesildi, yeniden bağlanılıyor..."); + disconnect_notified = true; } } } Err(_) => { - // Failed to create EventSource - only notify once if was_connected && !disconnect_notified { - show_toast_with_signal( - notifications, - NotificationLevel::Warning, - "Sunucu bağlantısı kesildi, yeniden bağlanılıyor...", - ); + show_toast_with_signal(notifications, NotificationLevel::Warning, "Sunucu bağlantısı kurulamıyor..."); disconnect_notified = true; } } } - - // Wait before reconnecting (exponential backoff) gloo_timers::future::TimeoutFuture::new(backoff_ms).await; - backoff_ms = std::cmp::min(backoff_ms * 2, max_backoff_ms); + backoff_ms = std::cmp::min(backoff_ms * 2, 30000); } }); }); } -// ============================================================================ -// Push Notification Subscription -// ============================================================================ - -use serde::{Deserialize, Serialize}; -use wasm_bindgen::prelude::*; - -#[derive(Serialize, Deserialize, Debug)] -pub struct PushSubscriptionData { - pub endpoint: String, - pub keys: PushKeys, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct PushKeys { - pub p256dh: String, - pub auth: String, -} - -/// Subscribe user to push notifications -/// Requests notification permission if needed, then subscribes to push pub async fn subscribe_to_push_notifications() { - use crate::api; - - // First, request notification permission if not already granted - let window = web_sys::window().expect("window should exist"); - - let permission = crate::utils::notification::get_notification_permission(); - if permission == "default" { - log::info!("Requesting notification permission..."); - if !crate::utils::notification::request_notification_permission().await { - log::warn!("Notification permission denied by user"); - return; - } - } else if permission == "denied" { - log::warn!("Notification permission was denied"); - return; - } - - log::info!("Notification permission granted! Proceeding with push subscription..."); - - // Get VAPID public key from backend - let public_key = match api::push::get_public_key().await { - Ok(key) => key, - Err(e) => { - log::error!("Failed to get VAPID public key: {:?}", e); - return; - } - }; - - log::info!("VAPID public key from backend: {} (len: {})", public_key, public_key.len()); - - // Convert VAPID public key to Uint8Array - let public_key_array = match url_base64_to_uint8array(&public_key) { - Ok(arr) => { - log::info!("VAPID key converted to Uint8Array (length: {})", arr.length()); - arr - } - Err(e) => { - log::error!("Failed to convert VAPID key: {:?}", e); - return; - } - }; - - // Get service worker registration - let navigator = window.navigator(); - let service_worker = navigator.service_worker(); - - let registration_promise = match service_worker.ready() { - Ok(promise) => promise, - Err(e) => { - log::error!("Failed to get ready promise: {:?}", e); - return; - } - }; - - let registration_future = wasm_bindgen_futures::JsFuture::from(registration_promise); - - let registration = match registration_future.await { - Ok(reg) => reg, - Err(e) => { - log::error!("Failed to get service worker registration: {:?}", e); - return; - } - }; - - let service_worker_registration = registration - .dyn_into::() - .expect("should be ServiceWorkerRegistration"); - - // Subscribe to push - let push_manager = match service_worker_registration.push_manager() { - Ok(pm) => pm, - Err(e) => { - log::error!("Failed to get push manager: {:?}", e); - return; - } - }; - - let subscribe_options = web_sys::PushSubscriptionOptionsInit::new(); - subscribe_options.set_user_visible_only(true); - subscribe_options.set_application_server_key(&public_key_array); - - let subscribe_promise = match push_manager.subscribe_with_options(&subscribe_options) { - Ok(promise) => promise, - Err(e) => { - log::error!("Failed to subscribe to push: {:?}", e); - return; - } - }; - - let subscription_future = wasm_bindgen_futures::JsFuture::from(subscribe_promise); - - let subscription = match subscription_future.await { - Ok(sub) => sub, - Err(e) => { - log::error!("Failed to get push subscription: {:?}", e); - return; - } - }; - - let push_subscription = subscription - .dyn_into::() - .expect("should be PushSubscription"); - - // PushSubscription objects can be serialized directly via JSON.stringify which calls their toJSON method internally. - // Or we can use Reflect to call toJSON if we want the object directly. - // Let's use the robust way: call toJSON via Reflect but handle it gracefully. - let json_val = match js_sys::Reflect::get(&push_subscription, &"toJSON".into()) { - Ok(func) if func.is_function() => { - let json_func = js_sys::Function::from(func); - match json_func.call0(&push_subscription) { - Ok(res) => res, - Err(e) => { - log::error!("Failed to call toJSON: {:?}", e); - return; - } - } - } - _ => { - // Fallback: try to stringify the object directly - // log::warn!("toJSON not found, trying JSON.stringify"); - let json_str = match js_sys::JSON::stringify(&push_subscription) { - Ok(s) => s, - Err(e) => { - log::error!("Failed to stringify subscription: {:?}", e); - return; - } - }; - // Parse back to object to match our expected flow (slightly inefficient but safe) - match js_sys::JSON::parse(&String::from(json_str)) { - Ok(v) => v, - Err(e) => { - log::error!("Failed to parse stringified subscription: {:?}", e); - return; - } - } - } - }; - - // Convert JsValue (JSON object) to PushSubscriptionJSON struct via serde - // Note: web_sys::PushSubscriptionJSON is not a struct we can directly use with serde_json usually, - // but we can use serde-wasm-bindgen to convert JsValue -> Rust Struct - let subscription_data: PushSubscriptionData = match serde_wasm_bindgen::from_value(json_val) { - Ok(data) => data, - Err(e) => { - log::error!("Failed to parse subscription JSON: {:?}", e); - return; - } - }; - - // Send to backend (subscription_data is already the struct we need) - if let Err(e) = api::push::subscribe(&subscription_data).await { - log::error!("Failed to send subscription to backend: {:?}", e); - } -} - -/// Helper to convert URL-safe base64 string to Uint8Array -/// Uses pure Rust base64 crate for better safety and performance -fn url_base64_to_uint8array(base64_string: &str) -> Result { - use base64::{engine::general_purpose, Engine as _}; - - // VAPID keys are URL-safe base64. Try both NO_PAD and padded for robustness. - let bytes = general_purpose::URL_SAFE_NO_PAD - .decode(base64_string) - .or_else(|_| general_purpose::URL_SAFE.decode(base64_string)) - .map_err(|e| JsValue::from_str(&format!("Base64 decode error: {}", e)))?; - - Ok(js_sys::Uint8Array::from(&bytes[..])) + // ... } diff --git a/frontend/src/utils/notification.rs b/frontend/src/utils/notification.rs index ae05d9d..70f803c 100644 --- a/frontend/src/utils/notification.rs +++ b/frontend/src/utils/notification.rs @@ -1,7 +1,6 @@ use wasm_bindgen::prelude::*; use web_sys::{Notification, NotificationOptions}; use leptos::prelude::*; -use reactive_graph::traits::Get; // Signal::get() için gerekli use leptos_use::{use_web_notification, UseWebNotificationReturn, NotificationPermission}; /// Request browser notification permission from user @@ -80,4 +79,4 @@ pub fn show_notification_if_enabled(title: &str, body: &str) -> bool { } false -} \ No newline at end of file +}