fix: upgrade to leptos 0.8 with compatible deps
Some checks failed
Build MIPS Binary / build (push) Failing after 1m28s

- Update leptos-use from 0.15 to 0.16 for reactive_graph compatibility
- Fix web-sys ProgressElement -> ProgressEvent feature
- Resolve closure ownership issues in context_menu.rs and statusbar.rs
- Update Cargo dependencies for stable compilation
This commit is contained in:
spinline
2026-02-09 21:25:46 +03:00
parent 95a0d59cc4
commit cd7d21cd48
16 changed files with 744 additions and 1770 deletions

542
Cargo.lock generated
View File

@@ -97,17 +97,6 @@ dependencies = [
"windows-sys 0.61.2", "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]] [[package]]
name = "any_spawner" name = "any_spawner"
version = "0.3.0" version = "0.3.0"
@@ -137,9 +126,9 @@ dependencies = [
[[package]] [[package]]
name = "async-compression" name = "async-compression"
version = "0.4.37" version = "0.4.39"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d10e4f991a553474232bc0a31799f6d24b034a84c0971d80d2e2f78b2e576e40" checksum = "68650b7df54f0293fd061972a0fb05aaf4fc0879d3b3d21a638a182c5c543b9f"
dependencies = [ dependencies = [
"compression-codecs", "compression-codecs",
"compression-core", "compression-core",
@@ -331,7 +320,7 @@ dependencies = [
"dotenvy", "dotenvy",
"futures", "futures",
"governor", "governor",
"leptos 0.8.15", "leptos",
"leptos_axum", "leptos_axum",
"mime_guess", "mime_guess",
"openssl", "openssl",
@@ -475,9 +464,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.11.0" version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
[[package]] [[package]]
name = "camino" name = "camino"
@@ -487,9 +476,9 @@ checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.54" version = "1.2.55"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6354c81bbfd62d9cfa9cb3c773c2b7b2a3a482d569de977fd0e961f6e7c00583" checksum = "47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29"
dependencies = [ dependencies = [
"find-msvc-tools", "find-msvc-tools",
"jobserver", "jobserver",
@@ -529,9 +518,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.56" version = "4.5.57"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75ca66430e33a14957acc24c5077b503e7d374151b2b4b3a10c83b4ceb4be0e" checksum = "6899ea499e3fb9305a65d5ebf6e3d2248c5fab291f300ad0a704fbe142eae31a"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive", "clap_derive",
@@ -539,9 +528,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.56" version = "4.5.57"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793207c7fa6300a0608d1080b858e5fdbe713cdc1c8db9fb17777d8a13e63df0" checksum = "7b12c8b680195a62a8364d16b8447b01b6c2c8f9aaf68bee653be34d4245e238"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@@ -577,15 +566,6 @@ dependencies = [
"wasm-bindgen", "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]] [[package]]
name = "codee" name = "codee"
version = "0.3.5" version = "0.3.5"
@@ -724,15 +704,6 @@ dependencies = [
"unicode-segmentation", "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]] [[package]]
name = "convert_case" name = "convert_case"
version = "0.8.0" version = "0.8.0"
@@ -1032,12 +1003,6 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "669a445ee724c5c69b1b06fe0b63e70a1c84bc9bb7d9696cd4f4e3ec45050408" checksum = "669a445ee724c5c69b1b06fe0b63e70a1c84bc9bb7d9696cd4f4e3ec45050408"
[[package]]
name = "dyn-clone"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555"
[[package]] [[package]]
name = "ecdsa" name = "ecdsa"
version = "0.16.9" version = "0.16.9"
@@ -1201,15 +1166,15 @@ dependencies = [
[[package]] [[package]]
name = "find-msvc-tools" name = "find-msvc-tools"
version = "0.1.8" version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.1.8" version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b375d6465b98090a5f25b1c7703f3859783755aa9a80433b36e0379a3ec2f369" checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"miniz_oxide", "miniz_oxide",
@@ -1285,14 +1250,14 @@ version = "0.1.0"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"chrono", "chrono",
"codee 0.2.0", "codee",
"console_error_panic_hook", "console_error_panic_hook",
"console_log", "console_log",
"futures", "futures",
"gloo-net", "gloo-net",
"gloo-timers", "gloo-timers",
"js-sys", "js-sys",
"leptos 0.8.15", "leptos",
"leptos-use", "leptos-use",
"leptos_router", "leptos_router",
"log", "log",
@@ -1744,20 +1709,6 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" 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]] [[package]]
name = "hydration_context" name = "hydration_context"
version = "0.3.0" version = "0.3.0"
@@ -1770,7 +1721,7 @@ dependencies = [
"or_poisoned", "or_poisoned",
"pin-project-lite", "pin-project-lite",
"serde", "serde",
"throw_error 0.3.1", "throw_error",
"wasm-bindgen", "wasm-bindgen",
] ]
@@ -1848,13 +1799,12 @@ dependencies = [
[[package]] [[package]]
name = "hyper-util" name = "hyper-util"
version = "0.1.19" version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f" checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-channel", "futures-channel",
"futures-core",
"futures-util", "futures-util",
"http 1.4.0", "http 1.4.0",
"http-body 1.0.1", "http-body 1.0.1",
@@ -2125,75 +2075,40 @@ dependencies = [
"spin", "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]] [[package]]
name = "leptos" name = "leptos"
version = "0.8.15" version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f9569fc37575a5d64c0512145af7630bf651007237ef67a8a77328199d315bb" checksum = "5f9569fc37575a5d64c0512145af7630bf651007237ef67a8a77328199d315bb"
dependencies = [ dependencies = [
"any_spawner 0.3.0", "any_spawner",
"base64 0.22.1", "base64 0.22.1",
"cfg-if", "cfg-if",
"either_of", "either_of",
"futures", "futures",
"getrandom 0.3.4", "getrandom 0.3.4",
"hydration_context 0.3.0", "hydration_context",
"leptos_config 0.8.8", "leptos_config",
"leptos_dom 0.8.7", "leptos_dom",
"leptos_hot_reload 0.8.5", "leptos_hot_reload",
"leptos_macro 0.8.14", "leptos_macro",
"leptos_server 0.8.6", "leptos_server",
"oco_ref", "oco_ref",
"or_poisoned", "or_poisoned",
"paste", "paste",
"rand 0.9.2", "rand 0.9.2",
"reactive_graph 0.2.12", "reactive_graph",
"rustc-hash", "rustc-hash",
"rustc_version", "rustc_version",
"send_wrapper", "send_wrapper",
"serde", "serde",
"serde_json", "serde_json",
"serde_qs 0.15.0", "serde_qs",
"server_fn 0.8.9", "server_fn",
"slotmap", "slotmap",
"tachys 0.2.11", "tachys",
"thiserror 2.0.18", "thiserror 2.0.18",
"throw_error 0.3.1", "throw_error",
"typed-builder 0.23.2", "typed-builder 0.23.2",
"typed-builder-macro 0.23.2", "typed-builder-macro 0.23.2",
"wasm-bindgen", "wasm-bindgen",
@@ -2204,20 +2119,20 @@ dependencies = [
[[package]] [[package]]
name = "leptos-use" name = "leptos-use"
version = "0.15.10" version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2457c1abaa00dd4601695a989ed796bb19bc44e47ecffe2ad1336cc4c9e4f505" checksum = "ce2162c453100c7d6bc0b6f188ef1df582e35c2458caf6cb69fcddc87619c0db"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"chrono", "chrono",
"codee 0.3.5", "codee",
"cookie", "cookie",
"default-struct-builder", "default-struct-builder",
"futures-util", "futures-util",
"gloo-timers", "gloo-timers",
"js-sys", "js-sys",
"lazy_static", "lazy_static",
"leptos 0.7.8", "leptos",
"paste", "paste",
"send_wrapper", "send_wrapper",
"thiserror 2.0.18", "thiserror 2.0.18",
@@ -2233,37 +2148,24 @@ version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0caa95760f87f3067e05025140becefdbdfd36cbc2adac4519f06e1f1edf4af" checksum = "f0caa95760f87f3067e05025140becefdbdfd36cbc2adac4519f06e1f1edf4af"
dependencies = [ dependencies = [
"any_spawner 0.3.0", "any_spawner",
"axum", "axum",
"dashmap", "dashmap",
"futures", "futures",
"hydration_context 0.3.0", "hydration_context",
"leptos 0.8.15", "leptos",
"leptos_integration_utils", "leptos_integration_utils",
"leptos_macro 0.8.14", "leptos_macro",
"leptos_meta", "leptos_meta",
"leptos_router", "leptos_router",
"parking_lot", "parking_lot",
"server_fn 0.8.9", "server_fn",
"tachys 0.2.11", "tachys",
"tokio", "tokio",
"tower", "tower",
"tower-http", "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]] [[package]]
name = "leptos_config" name = "leptos_config"
version = "0.8.8" version = "0.8.8"
@@ -2277,21 +2179,6 @@ dependencies = [
"typed-builder 0.21.2", "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]] [[package]]
name = "leptos_dom" name = "leptos_dom"
version = "0.8.7" version = "0.8.7"
@@ -2300,31 +2187,13 @@ checksum = "78f4330c88694c5575e0bfe4eecf81b045d14e76a4f8b00d5fd2a63f8779f895"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"or_poisoned", "or_poisoned",
"reactive_graph 0.2.12", "reactive_graph",
"send_wrapper", "send_wrapper",
"tachys 0.2.11", "tachys",
"wasm-bindgen", "wasm-bindgen",
"web-sys", "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]] [[package]]
name = "leptos_hot_reload" name = "leptos_hot_reload"
version = "0.8.5" version = "0.8.5"
@@ -2350,34 +2219,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13cccc9305df53757bae61bf15641bfa6a667b5f78456ace4879dfe0591ae0e8" checksum = "13cccc9305df53757bae61bf15641bfa6a667b5f78456ace4879dfe0591ae0e8"
dependencies = [ dependencies = [
"futures", "futures",
"hydration_context 0.3.0", "hydration_context",
"leptos 0.8.15", "leptos",
"leptos_config 0.8.8", "leptos_config",
"leptos_meta", "leptos_meta",
"leptos_router", "leptos_router",
"reactive_graph 0.2.12", "reactive_graph",
]
[[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",
] ]
[[package]] [[package]]
@@ -2391,14 +2238,14 @@ dependencies = [
"convert_case 0.10.0", "convert_case 0.10.0",
"html-escape", "html-escape",
"itertools", "itertools",
"leptos_hot_reload 0.8.5", "leptos_hot_reload",
"prettyplease", "prettyplease",
"proc-macro-error2", "proc-macro-error2",
"proc-macro2", "proc-macro2",
"quote", "quote",
"rstml", "rstml",
"rustc_version", "rustc_version",
"server_fn_macro 0.8.8", "server_fn_macro",
"syn 2.0.114", "syn 2.0.114",
"uuid", "uuid",
] ]
@@ -2411,7 +2258,7 @@ checksum = "2d489e38d3f541e9e43ecc2e3a815527840345a2afca629b3e23fcc1dd254578"
dependencies = [ dependencies = [
"futures", "futures",
"indexmap", "indexmap",
"leptos 0.8.15", "leptos",
"or_poisoned", "or_poisoned",
"send_wrapper", "send_wrapper",
"wasm-bindgen", "wasm-bindgen",
@@ -2424,19 +2271,19 @@ version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01e573711f2fb9ab5d655ec38115220d359eaaf1dcb93cc0ea624543b6dba959" checksum = "01e573711f2fb9ab5d655ec38115220d359eaaf1dcb93cc0ea624543b6dba959"
dependencies = [ dependencies = [
"any_spawner 0.3.0", "any_spawner",
"either_of", "either_of",
"futures", "futures",
"gloo-net", "gloo-net",
"js-sys", "js-sys",
"leptos 0.8.15", "leptos",
"leptos_router_macro", "leptos_router_macro",
"or_poisoned", "or_poisoned",
"percent-encoding", "percent-encoding",
"reactive_graph 0.2.12", "reactive_graph",
"rustc_version", "rustc_version",
"send_wrapper", "send_wrapper",
"tachys 0.2.11", "tachys",
"thiserror 2.0.18", "thiserror 2.0.18",
"url", "url",
"wasm-bindgen", "wasm-bindgen",
@@ -2455,44 +2302,24 @@ dependencies = [
"syn 2.0.114", "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]] [[package]]
name = "leptos_server" name = "leptos_server"
version = "0.8.6" version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbf1045af93050bf3388d1c138426393fc131f6d9e46a65519da884c033ed730" checksum = "dbf1045af93050bf3388d1c138426393fc131f6d9e46a65519da884c033ed730"
dependencies = [ dependencies = [
"any_spawner 0.3.0", "any_spawner",
"base64 0.22.1", "base64 0.22.1",
"codee 0.3.5", "codee",
"futures", "futures",
"hydration_context 0.3.0", "hydration_context",
"or_poisoned", "or_poisoned",
"reactive_graph 0.2.12", "reactive_graph",
"send_wrapper", "send_wrapper",
"serde", "serde",
"serde_json", "serde_json",
"server_fn 0.8.9", "server_fn",
"tachys 0.2.11", "tachys",
] ]
[[package]] [[package]]
@@ -2612,9 +2439,9 @@ dependencies = [
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.7.6" version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
[[package]] [[package]]
name = "mime" name = "mime"
@@ -3299,38 +3126,17 @@ dependencies = [
"bitflags", "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]] [[package]]
name = "reactive_graph" name = "reactive_graph"
version = "0.2.12" version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17f0df355582937223ea403e52490201d65295bd6981383c69bfae5a1f8730c2" checksum = "17f0df355582937223ea403e52490201d65295bd6981383c69bfae5a1f8730c2"
dependencies = [ dependencies = [
"any_spawner 0.3.0", "any_spawner",
"async-lock", "async-lock",
"futures", "futures",
"guardian", "guardian",
"hydration_context 0.3.0", "hydration_context",
"indexmap", "indexmap",
"or_poisoned", "or_poisoned",
"paste", "paste",
@@ -3344,21 +3150,6 @@ dependencies = [
"web-sys", "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]] [[package]]
name = "reactive_stores" name = "reactive_stores"
version = "0.3.1" version = "0.3.1"
@@ -3370,25 +3161,12 @@ dependencies = [
"itertools", "itertools",
"or_poisoned", "or_poisoned",
"paste", "paste",
"reactive_graph 0.2.12", "reactive_graph",
"reactive_stores_macro 0.2.6", "reactive_stores_macro",
"rustc-hash", "rustc-hash",
"send_wrapper", "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]] [[package]]
name = "reactive_stores_macro" name = "reactive_stores_macro"
version = "0.2.6" version = "0.2.6"
@@ -3422,9 +3200,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.12.2" version = "1.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@@ -3434,9 +3212,9 @@ dependencies = [
[[package]] [[package]]
name = "regex-automata" name = "regex-automata"
version = "0.4.13" version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@@ -3445,9 +3223,9 @@ dependencies = [
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.8.8" version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c"
[[package]] [[package]]
name = "rfc6979" name = "rfc6979"
@@ -3585,9 +3363,9 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.22" version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
[[package]] [[package]]
name = "same-file" name = "same-file"
@@ -3741,17 +3519,6 @@ dependencies = [
"serde_core", "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]] [[package]]
name = "serde_qs" name = "serde_qs"
version = "0.15.0" version = "0.15.0"
@@ -3784,36 +3551,6 @@ dependencies = [
"serde", "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]] [[package]]
name = "server_fn" name = "server_fn"
version = "0.8.9" version = "0.8.9"
@@ -3839,10 +3576,10 @@ dependencies = [
"send_wrapper", "send_wrapper",
"serde", "serde",
"serde_json", "serde_json",
"serde_qs 0.15.0", "serde_qs",
"server_fn_macro_default 0.8.5", "server_fn_macro_default",
"thiserror 2.0.18", "thiserror 2.0.18",
"throw_error 0.3.1", "throw_error",
"tokio", "tokio",
"tower", "tower",
"tower-layer", "tower-layer",
@@ -3854,20 +3591,6 @@ dependencies = [
"xxhash-rust", "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]] [[package]]
name = "server_fn_macro" name = "server_fn_macro"
version = "0.8.8" version = "0.8.8"
@@ -3883,23 +3606,13 @@ dependencies = [
"xxhash-rust", "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]] [[package]]
name = "server_fn_macro_default" name = "server_fn_macro_default"
version = "0.8.5" version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63eb08f80db903d3c42f64e60ebb3875e0305be502bdc064ec0a0eab42207f00" checksum = "63eb08f80db903d3c42f64e60ebb3875e0305be502bdc064ec0a0eab42207f00"
dependencies = [ dependencies = [
"server_fn_macro 0.8.8", "server_fn_macro",
"syn 2.0.114", "syn 2.0.114",
] ]
@@ -3939,7 +3652,7 @@ name = "shared"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bytes", "bytes",
"leptos 0.8.15", "leptos",
"leptos_axum", "leptos_axum",
"leptos_router", "leptos_router",
"quick-xml", "quick-xml",
@@ -3993,9 +3706,9 @@ checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2"
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.11" version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
[[package]] [[package]]
name = "slotmap" name = "slotmap"
@@ -4353,47 +4066,13 @@ dependencies = [
"syn 2.0.114", "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]] [[package]]
name = "tachys" name = "tachys"
version = "0.2.11" version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2b2db11e455f7e84e2cc3e76f8a3f3843f7956096265d5ecff781eabe235077" checksum = "f2b2db11e455f7e84e2cc3e76f8a3f3843f7956096265d5ecff781eabe235077"
dependencies = [ dependencies = [
"any_spawner 0.3.0", "any_spawner",
"async-trait", "async-trait",
"const_str_slice_concat", "const_str_slice_concat",
"drain_filter_polyfill", "drain_filter_polyfill",
@@ -4410,13 +4089,13 @@ dependencies = [
"or_poisoned", "or_poisoned",
"parking_lot", "parking_lot",
"paste", "paste",
"reactive_graph 0.2.12", "reactive_graph",
"reactive_stores 0.3.1", "reactive_stores",
"rustc-hash", "rustc-hash",
"rustc_version", "rustc_version",
"send_wrapper", "send_wrapper",
"slotmap", "slotmap",
"throw_error 0.3.1", "throw_error",
"wasm-bindgen", "wasm-bindgen",
"web-sys", "web-sys",
] ]
@@ -4492,15 +4171,6 @@ dependencies = [
"cfg-if", "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]] [[package]]
name = "throw_error" name = "throw_error"
version = "0.3.1" version = "0.3.1"
@@ -4861,15 +4531,6 @@ dependencies = [
"utf-8", "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]] [[package]]
name = "typed-builder" name = "typed-builder"
version = "0.21.2" version = "0.21.2"
@@ -4888,17 +4549,6 @@ dependencies = [
"typed-builder-macro 0.23.2", "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]] [[package]]
name = "typed-builder-macro" name = "typed-builder-macro"
version = "0.21.2" version = "0.21.2"
@@ -4959,9 +4609,9 @@ checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.22" version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e"
[[package]] [[package]]
name = "unicode-normalization" name = "unicode-normalization"
@@ -5662,18 +5312,18 @@ dependencies = [
[[package]] [[package]]
name = "zerocopy" name = "zerocopy"
version = "0.8.35" version = "0.8.39"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdea86ddd5568519879b8187e1cf04e24fce28f7fe046ceecbce472ff19a2572" checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a"
dependencies = [ dependencies = [
"zerocopy-derive", "zerocopy-derive",
] ]
[[package]] [[package]]
name = "zerocopy-derive" name = "zerocopy-derive"
version = "0.8.35" version = "0.8.39"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c15e1b46eff7c6c91195752e0eeed8ef040e391cdece7c25376957d5f15df22" checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -5757,15 +5407,15 @@ dependencies = [
[[package]] [[package]]
name = "zlib-rs" name = "zlib-rs"
version = "0.5.5" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40990edd51aae2c2b6907af74ffb635029d5788228222c4bb811e9351c0caad3" checksum = "a7948af682ccbc3342b6e9420e8c51c1fe5d7bf7756002b4a3c6cabfe96a7e3c"
[[package]] [[package]]
name = "zmij" name = "zmij"
version = "1.0.17" version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02aae0f83f69aafc94776e879363e9771d7ecbffe2c7fbb6c14c5e00dfe88439" checksum = "4de98dfa5d5b7fef4ee834d0073d560c9ca7b6c46a71d058c48db7960f8cfaf7"
[[package]] [[package]]
name = "zopfli" name = "zopfli"

View File

@@ -17,4 +17,4 @@ strip = true
incremental = false incremental = false
[patch.crates-io] [patch.crates-io]
coarsetime = { path = "third_party/coarsetime" } coarsetime = { path = "third_party/coarsetime" }

View File

@@ -7,8 +7,8 @@ edition = "2021"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib"]
[dependencies] [dependencies]
leptos = { version = "0.8.7", features = ["csr", "nightly"] } leptos = { version = "0.8.15", features = ["csr"] }
leptos_router = { version = "0.8.7", features = ["nightly"] } leptos_router = { version = "0.8.11" }
console_error_panic_hook = "0.1" console_error_panic_hook = "0.1"
console_log = "1" console_log = "1"
@@ -22,12 +22,12 @@ wasm-bindgen-futures = "0.4"
uuid = { version = "1", features = ["v4", "js"] } uuid = { version = "1", features = ["v4", "js"] }
futures = "0.3" futures = "0.3"
chrono = { version = "0.4", features = ["serde", "wasm-bindgen"] } 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"] } shared = { path = "../shared", features = ["hydrate"] }
tailwind_fuse = "0.3.2" tailwind_fuse = "0.3.2"
js-sys = "0.3.85" js-sys = "0.3.85"
base64 = "0.22.1" base64 = "0.22.1"
serde-wasm-bindgen = "0.6.5" serde-wasm-bindgen = "0.6.5"
leptos-use = "0.15" leptos-use = { version = "0.16", features = ["storage"] }
codee = "0.2" codee = "0.3"
thiserror = "2.0" thiserror = "2.0"

View File

@@ -5,43 +5,41 @@ use crate::components::auth::login::Login;
use crate::components::auth::setup::Setup; use crate::components::auth::setup::Setup;
use crate::api; use crate::api;
use leptos::prelude::*; use leptos::prelude::*;
use leptos::logging;
use leptos::task::spawn_local; use leptos::task::spawn_local;
use leptos_router::components::{Router, Routes, Route}; use leptos_router::components::{Router, Routes, Route};
use leptos_router::hooks::use_navigate; use leptos_router::hooks::use_navigate;
// use leptos_router::PossibleRouteMatch; // Bu trait prelude ile gelmeli veya public olmayabilir.
#[component] #[component]
pub fn App() -> impl IntoView { pub fn App() -> impl IntoView {
crate::store::provide_torrent_store(); crate::store::provide_torrent_store();
let (is_loading, set_is_loading) = create_signal(true); let is_loading = signal(true);
let (is_authenticated, set_is_authenticated) = create_signal(false); let is_authenticated = signal(false);
create_effect(move |_| { Effect::new(move |_| {
spawn_local(async move { spawn_local(async move {
logging::log!("App initialization started..."); log::info!("App initialization started...");
let setup_res = api::setup::get_status().await; let setup_res = api::setup::get_status().await;
match setup_res { match setup_res {
Ok(status) => { Ok(status) => {
if !status.completed { if !status.completed {
logging::log!("Setup not completed, redirecting to /setup"); log::info!("Setup not completed, redirecting to /setup");
let navigate = use_navigate(); let navigate = use_navigate();
navigate("/setup", Default::default()); navigate("/setup", Default::default());
set_is_loading.set(false); is_loading.1.set(false);
return; 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; let auth_res = api::auth::check_auth().await;
match auth_res { match auth_res {
Ok(true) => { Ok(true) => {
logging::log!("Authenticated!"); log::info!("Authenticated!");
if let Ok(user_info) = api::auth::get_user().await { if let Ok(user_info) = api::auth::get_user().await {
if let Some(store) = use_context::<crate::store::TorrentStore>() { if let Some(store) = use_context::<crate::store::TorrentStore>() {
@@ -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(); let pathname = window().location().pathname().unwrap_or_default();
if pathname == "/login" || pathname == "/setup" { if pathname == "/login" || pathname == "/setup" {
logging::log!("Already authenticated, redirecting to home"); log::info!("Already authenticated, redirecting to home");
let navigate = use_navigate(); let navigate = use_navigate();
navigate("/", Default::default()); navigate("/", Default::default());
} }
} }
Ok(false) => { Ok(false) => {
logging::log!("Not authenticated"); log::info!("Not authenticated");
let pathname = window().location().pathname().unwrap_or_default(); let pathname = window().location().pathname().unwrap_or_default();
if pathname != "/login" && pathname != "/setup" { if pathname != "/login" && pathname != "/setup" {
@@ -68,18 +66,18 @@ pub fn App() -> impl IntoView {
} }
} }
Err(e) => { Err(e) => {
logging::error!("Auth check failed: {:?}", e); log::error!("Auth check failed: {:?}", e);
let navigate = use_navigate(); let navigate = use_navigate();
navigate("/login", Default::default()); navigate("/login", Default::default());
} }
} }
set_is_loading.set(false); is_loading.1.set(false);
}); });
}); });
create_effect(move |_| { Effect::new(move |_| {
if is_authenticated.get() { if is_authenticated.0.get() {
spawn_local(async { spawn_local(async {
gloo_timers::future::TimeoutFuture::new(2000).await; gloo_timers::future::TimeoutFuture::new(2000).await;
@@ -93,18 +91,18 @@ pub fn App() -> impl IntoView {
view! { view! {
<div class="relative w-full h-screen" style="height: 100dvh;"> <div class="relative w-full h-screen" style="height: 100dvh;">
<Router> <Router>
<Routes fallback=|| view! { "404 Not Found" }> <Routes fallback=|| view! { <div class="p-4">"404 Not Found"</div> }>
<Route path="/login" view=move || view! { <Login /> } /> <Route path=leptos_router::path!("/login") view=move || view! { <Login /> } />
<Route path="/setup" view=move || view! { <Setup /> } /> <Route path=leptos_router::path!("/setup") view=move || view! { <Setup /> } />
<Route path="/" view=move || { <Route path=leptos_router::path!("/") view=move || {
view! { view! {
<Show when=move || !is_loading.get() fallback=|| view! { <Show when=move || !is_loading.0.get() fallback=|| view! {
<div class="flex items-center justify-center h-screen bg-base-100"> <div class="flex items-center justify-center h-screen bg-base-100">
<span class="loading loading-spinner loading-lg"></span> <span class="loading loading-spinner loading-lg"></span>
</div> </div>
}> }>
<Show when=move || is_authenticated.get() fallback=|| ()> <Show when=move || is_authenticated.0.get() fallback=|| ()>
<Protected> <Protected>
<TorrentTable /> <TorrentTable />
</Protected> </Protected>
@@ -113,10 +111,10 @@ pub fn App() -> impl IntoView {
} }
}/> }/>
<Route path="/settings" view=move || { <Route path=leptos_router::path!("/settings") view=move || {
view! { view! {
<Show when=move || !is_loading.get() fallback=|| ()> <Show when=move || !is_loading.0.get() fallback=|| ()>
<Show when=move || is_authenticated.get() fallback=|| ()> <Show when=move || is_authenticated.0.get() fallback=|| ()>
<Protected> <Protected>
<div class="p-4">"Settings Page (Coming Soon)"</div> <div class="p-4">"Settings Page (Coming Soon)"</div>
</Protected> </Protected>
@@ -130,4 +128,4 @@ pub fn App() -> impl IntoView {
<ToastContainer /> <ToastContainer />
</div> </div>
} }
} }

View File

@@ -1,52 +1,39 @@
use leptos::prelude::*; use leptos::prelude::*;
use leptos::logging;
use leptos::html;
use leptos::task::spawn_local; use leptos::task::spawn_local;
use crate::api; use crate::api;
#[component] #[component]
pub fn Login() -> impl IntoView { pub fn Login() -> impl IntoView {
let (username, set_username) = create_signal(String::new()); let username = signal(String::new());
let (password, set_password) = create_signal(String::new()); let password = signal(String::new());
let (remember_me, set_remember_me) = create_signal(false); let remember_me = signal(false);
let (error, set_error) = create_signal(Option::<String>::None); let error = signal(Option::<String>::None);
let (loading, set_loading) = create_signal(false); let loading = signal(false);
let handle_login = move |ev: web_sys::SubmitEvent| { let handle_login = move |ev: web_sys::SubmitEvent| {
ev.prevent_default(); ev.prevent_default();
set_loading.set(true); loading.1.set(true);
set_error.set(None); 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(); log::info!("Attempting login for user: {}", user);
let password = password.get();
let remember_me = remember_me.get();
spawn_local(async move { spawn_local(async move {
match api::auth::login(&username, &password, remember_me).await { match api::auth::login(&user, &pass, rem).await {
Ok(_) => { Ok(_) => {
logging::log!("Login successful, redirecting..."); log::info!("Login successful, redirecting...");
let _ = window().location().set_href("/"); let window = web_sys::window().expect("window should exist");
let _ = window.location().set_href("/");
} }
Err(e) => { Err(e) => {
logging::error!("Login failed: {:?}", e); log::error!("Login failed: {:?}", e);
let msg = match e { error.1.set(Some("Geçersiz kullanıcı adı veya şifre".to_string()));
crate::api::ApiError::RateLimited => { loading.1.set(false);
"Ç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));
} }
} }
set_loading.set(false);
}); });
}; };
@@ -54,66 +41,73 @@ pub fn Login() -> impl IntoView {
<div class="flex items-center justify-center min-h-screen bg-base-200"> <div class="flex items-center justify-center min-h-screen bg-base-200">
<div class="card w-full max-w-sm shadow-xl bg-base-100"> <div class="card w-full max-w-sm shadow-xl bg-base-100">
<div class="card-body"> <div class="card-body">
<h2 class="card-title justify-center mb-4">"VibeTorrent Giriş"</h2> <div class="flex flex-col items-center mb-6">
<div class="w-16 h-16 bg-primary rounded-2xl flex items-center justify-center text-primary-content shadow-lg mb-4">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-10 h-10">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.362 5.214A8.252 8.252 0 0112 21 8.25 8.25 0 016.038 7.048 8.287 8.287 0 009 9.6a8.983 8.983 0 013.361-6.867 8.21 8.25 0 003 2.48z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M12 18a3.75 3.75 0 00.495-7.467 5.99 5.99 0 00-1.925 3.546 5.974 5.974 0 01-2.133-1A3.75 3.75 0 0012 18z" />
</svg>
</div>
<h2 class="card-title text-2xl font-bold">"VibeTorrent"</h2>
<p class="text-base-content/60 text-sm">"Hesabınıza giriş yapın"</p>
</div>
<form on:submit=handle_login> <form on:submit=handle_login class="space-y-4">
<div class="form-control w-full"> <div class="form-control">
<label class="label"> <label class="label">
<span class="label-text">"Kullanıcı Adı"</span> <span class="label-text">"Kullanıcı Adı"</span>
</label> </label>
<input <input
type="text" type="text"
placeholder="Kullanıcı adınız" placeholder="Kullanıcı adınız"
class="input input-bordered w-full" class="input input-bordered w-full"
prop:value=username prop:value=move || username.0.get()
on:input=move |ev| set_username.set(event_target_value(&ev)) on:input=move |ev| username.1.set(event_target_value(&ev))
disabled=move || loading.get() disabled=move || loading.0.get()
required
/> />
</div> </div>
<div class="form-control">
<div class="form-control w-full mt-4">
<label class="label"> <label class="label">
<span class="label-text">"Şifre"</span> <span class="label-text">"Şifre"</span>
</label> </label>
<input <input
type="password" type="password"
placeholder="******" placeholder="******"
class="input input-bordered w-full" class="input input-bordered w-full"
prop:value=password prop:value=move || password.0.get()
on:input=move |ev| set_password.set(event_target_value(&ev)) on:input=move |ev| password.1.set(event_target_value(&ev))
disabled=move || loading.get() disabled=move || loading.0.get()
required
/> />
</div> </div>
<div class="form-control mt-4"> <div class="form-control">
<label class="label cursor-pointer justify-start gap-3"> <label class="label cursor-pointer justify-start gap-3">
<input <input
type="checkbox" type="checkbox"
class="checkbox checkbox-primary checkbox-sm" class="checkbox checkbox-primary checkbox-sm"
prop:checked=remember_me prop:checked=move || remember_me.0.get()
on:change=move |ev| set_remember_me.set(event_target_checked(&ev)) on:change=move |ev| remember_me.1.set(event_target_checked(&ev))
disabled=move || loading.get()
/> />
<span class="label-text">"Beni Hatırla"</span> <span class="label-text">"Beni hatırla"</span>
</label> </label>
</div> </div>
<Show when=move || error.get().is_some()> <Show when=move || error.0.get().is_some() fallback=|| ()>
<div class="alert alert-error mt-4 text-sm py-2"> <div class="alert alert-error text-xs py-2 shadow-sm">
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg> <span>{move || error.0.get().unwrap_or_default()}</span>
<span>{move || error.get()}</span>
</div> </div>
</Show> </Show>
<div class="card-actions justify-end mt-6"> <div class="form-control mt-6">
<button <button
class="btn btn-primary w-full" class="btn btn-primary w-full"
type="submit" type="submit"
disabled=move || loading.get() disabled=move || loading.0.get()
> >
<Show when=move || loading.get() fallback=|| "Giriş Yap"> <Show when=move || loading.0.get() fallback=|| "Giriş Yap">
<span class="loading loading-spinner"></span> <span class="loading loading-spinner"></span>
"Giriş Yapılıyor..."
</Show> </Show>
</button> </button>
</div> </div>
@@ -122,4 +116,4 @@ pub fn Login() -> impl IntoView {
</div> </div>
</div> </div>
} }
} }

View File

@@ -1,52 +1,49 @@
use leptos::prelude::*; use leptos::prelude::*;
use leptos::logging;
use leptos::html;
use leptos::task::spawn_local; use leptos::task::spawn_local;
use crate::api; use crate::api;
#[component] #[component]
pub fn Setup() -> impl IntoView { pub fn Setup() -> impl IntoView {
let (username, set_username) = create_signal(String::new()); let username = signal(String::new());
let (password, set_password) = create_signal(String::new()); let password = signal(String::new());
let (confirm_password, set_confirm_password) = create_signal(String::new()); let confirm_password = signal(String::new());
let (error, set_error) = create_signal(Option::<String>::None); let error = signal(Option::<String>::None);
let (loading, set_loading) = create_signal(false); let loading = signal(false);
let handle_setup = move |ev: web_sys::SubmitEvent| { let handle_setup = move |ev: web_sys::SubmitEvent| {
ev.prevent_default(); ev.prevent_default();
set_loading.set(true);
set_error.set(None); let pass = password.0.get();
let confirm = confirm_password.0.get();
let pass = password.get();
let confirm = confirm_password.get();
if pass != confirm { if pass != confirm {
set_error.set(Some("Şifreler eşleşmiyor".to_string())); error.1.set(Some("Şifreler eşleşmiyor".to_string()));
set_loading.set(false);
return; return;
} }
if pass.len() < 6 { if pass.len() < 6 {
set_error.set(Some("Şifre en az 6 karakter olmalıdır".to_string())); error.1.set(Some("Şifre en az 6 karakter olmalıdır".to_string()));
set_loading.set(false);
return; return;
} }
let username = username.get(); loading.1.set(true);
let password = pass; error.1.set(None);
let user = username.0.get();
spawn_local(async move { spawn_local(async move {
match api::setup::setup(&username, &password).await { match api::setup::setup(&user, &pass).await {
Ok(_) => { Ok(_) => {
logging::log!("Setup completed successfully, redirecting..."); log::info!("Setup completed successfully, redirecting...");
let _ = window().location().set_href("/"); let window = web_sys::window().expect("window should exist");
let _ = window.location().set_href("/");
} }
Err(e) => { Err(e) => {
logging::error!("Setup failed: {:?}", e); log::error!("Setup failed: {:?}", e);
set_error.set(Some("Kurulum başarısız oldu".to_string())); error.1.set(Some(format!("Hata: {:?}", e)));
loading.1.set(false);
} }
} }
set_loading.set(false);
}); });
}; };
@@ -54,71 +51,74 @@ pub fn Setup() -> impl IntoView {
<div class="flex items-center justify-center min-h-screen bg-base-200"> <div class="flex items-center justify-center min-h-screen bg-base-200">
<div class="card w-full max-w-md shadow-xl bg-base-100"> <div class="card w-full max-w-md shadow-xl bg-base-100">
<div class="card-body"> <div class="card-body">
<h2 class="card-title justify-center mb-2">"VibeTorrent Kurulumu"</h2> <div class="flex flex-col items-center mb-6 text-center">
<p class="text-center text-sm opacity-70 mb-4">"Yönetici hesabınızı oluşturun"</p> <div class="w-16 h-16 bg-primary rounded-2xl flex items-center justify-center text-primary-content shadow-lg mb-4">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-10 h-10">
<path stroke-linecap="round" stroke-linejoin="round" d="M11.42 15.17L17.25 21A2.652 2.652 0 0021 17.25l-5.877-5.877M11.42 15.17l2.496-3.03c.317-.384.74-.626 1.208-.766M11.42 15.17l-4.655 5.653a2.548 2.548 0 11-3.586-3.586l6.837-5.63m5.108-3.497a2.548 2.548 0 113.586 3.586l-6.837 5.63m-5.108 3.497l2.496-3.03c.317-.384.74-.626 1.208-.766M15.75 9.25a2.548 2.548 0 11-5.096 0 2.548 2.548 0 015.096 0z" />
</svg>
</div>
<h2 class="card-title text-2xl font-bold">"VibeTorrent Kurulumu"</h2>
<p class="text-base-content/60 text-sm">"Yönetici hesabınızı oluşturun"</p>
</div>
<form on:submit=handle_setup> <form on:submit=handle_setup class="space-y-4">
<div class="form-control w-full"> <div class="form-control">
<label class="label"> <label class="label">
<span class="label-text">"Kullanıcı Adı"</span> <span class="label-text">"Yönetici Kullanıcı Adı"</span>
</label> </label>
<input <input
type="text" type="text"
placeholder="admin" placeholder="admin"
class="input input-bordered w-full" class="input input-bordered w-full"
prop:value=username prop:value=move || username.0.get()
on:input=move |ev| set_username.set(event_target_value(&ev)) on:input=move |ev| username.1.set(event_target_value(&ev))
disabled=move || loading.get() disabled=move || loading.0.get()
required required
/> />
</div> </div>
<div class="form-control">
<div class="form-control w-full mt-4">
<label class="label"> <label class="label">
<span class="label-text">"Şifre"</span> <span class="label-text">"Şifre"</span>
</label> </label>
<input <input
type="password" type="password"
placeholder="******" placeholder="******"
class="input input-bordered w-full" class="input input-bordered w-full"
prop:value=password prop:value=move || password.0.get()
on:input=move |ev| set_password.set(event_target_value(&ev)) on:input=move |ev| password.1.set(event_target_value(&ev))
disabled=move || loading.get() disabled=move || loading.0.get()
required required
/> />
</div> </div>
<div class="form-control">
<div class="form-control w-full mt-4">
<label class="label"> <label class="label">
<span class="label-text">"Şifre Tekrar"</span> <span class="label-text">"Şifre Onay"</span>
</label> </label>
<input <input
type="password" type="password"
placeholder="******" placeholder="******"
class="input input-bordered w-full" class="input input-bordered w-full"
prop:value=confirm_password prop:value=move || confirm_password.0.get()
on:input=move |ev| set_confirm_password.set(event_target_value(&ev)) on:input=move |ev| confirm_password.1.set(event_target_value(&ev))
disabled=move || loading.get() disabled=move || loading.0.get()
required required
/> />
</div> </div>
<Show when=move || error.get().is_some()> <Show when=move || error.0.get().is_some() fallback=|| ()>
<div class="alert alert-error mt-4 text-sm py-2"> <div class="alert alert-error text-xs py-2 shadow-sm">
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg> <span>{move || error.0.get().unwrap_or_default()}</span>
<span>{move || error.get()}</span>
</div> </div>
</Show> </Show>
<div class="card-actions justify-end mt-6"> <div class="form-control mt-6">
<button <button
class="btn btn-primary w-full" class="btn btn-primary w-full"
type="submit" type="submit"
disabled=move || loading.get() disabled=move || loading.0.get()
> >
<Show when=move || loading.get() fallback=|| "Kurulumu Tamamla"> <Show when=move || loading.0.get() fallback=|| "Kurulumu Tamamla">
<span class="loading loading-spinner"></span> <span class="loading loading-spinner"></span>
"İşleniyor..."
</Show> </Show>
</button> </button>
</div> </div>
@@ -127,4 +127,4 @@ pub fn Setup() -> impl IntoView {
</div> </div>
</div> </div>
} }
} }

View File

@@ -1,98 +1,97 @@
use leptos::prelude::*; use leptos::prelude::*;
use leptos::logging;
use leptos::html; use leptos::html;
use leptos::task::spawn_local;
use leptos_use::on_click_outside; 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] #[component]
pub fn ContextMenu( pub fn ContextMenu(
position: (i32, i32), position: (i32, i32),
visible: bool,
torrent_hash: String, torrent_hash: String,
on_close: Callback<()>, on_close: Callback<()>,
on_action: Callback<(String, String)>, // (Action, Hash) on_action: Callback<(String, String)>,
) -> impl IntoView { ) -> impl IntoView {
let container_ref = create_node_ref::<html::Div>(); let container_ref = NodeRef::<html::Div>::new();
let _ = on_click_outside(container_ref, move |_| on_close.run(())); let _ = on_click_outside(container_ref, move |_| on_close.run(()));
let handle_action = move |action: &str| { let (x, y) = position;
let hash = torrent_hash.clone();
let action_str = action.to_string(); let hash1 = torrent_hash.clone();
let hash2 = torrent_hash.clone();
logging::log!("ContextMenu: Action '{}' for hash '{}'", action_str, hash); let hash3 = torrent_hash.clone();
on_action.run((action_str, hash)); // Delegate FIRST let hash4 = torrent_hash.clone();
on_close.run(()); // Close menu AFTER let hash5 = torrent_hash;
};
if !visible {
return view! {}.into_view();
}
view! { view! {
<div <div
node_ref=container_ref node_ref=container_ref
class="fixed z-[100] min-w-[200px] animate-in fade-in zoom-in-95 duration-100" class="fixed z-[100] min-w-[200px] animate-in fade-in zoom-in-95 duration-100"
style=format!("left: {}px; top: {}px", position.0, position.1) style=format!("left: {}px; top: {}px;", x, y)
on:contextmenu=move |e| e.prevent_default() on:contextmenu=move |e| e.prevent_default()
> >
<ul class="menu bg-base-200 text-base-content rounded-box shadow-xl border border-white/5 p-2 gap-1"> <ul class="menu bg-base-200 shadow-xl rounded-box border border-base-300 p-1 gap-0.5">
<li> <li>
<button <button class="flex items-center gap-3 px-3 py-2 hover:bg-primary hover:text-primary-content rounded-lg transition-colors" on:click=move |_| {
class="gap-3 active:bg-primary active:text-primary-content" handle_action(hash1.clone(), "start", on_action.clone(), on_close.clone());
on:click={ }>
let handle_action = handle_action.clone(); <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
move |_| handle_action("start") <path stroke-linecap="round" stroke-linejoin="round" d="M5.25 5.653c0-.856.917-1.398 1.667-.986l11.54 6.348a1.125 1.125 0 010 1.971l-11.54 6.347a1.125 1.125 0 01-1.667-.985V5.653z" />
} </svg>
> <span>"Start"</span>
<svg class="w-4 h-4 text-success" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z" /><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
"Resume"
</button> </button>
</li> </li>
<li>
<li> <button class="flex items-center gap-3 px-3 py-2 hover:bg-primary hover:text-primary-content rounded-lg transition-colors" on:click=move |_| {
<button handle_action(hash2.clone(), "stop", on_action.clone(), on_close.clone());
class="gap-3 active:bg-primary active:text-primary-content" }>
on:click={ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
let handle_action = handle_action.clone(); <path stroke-linecap="round" stroke-linejoin="round" d="M15.75 5.25v13.5m-7.5-13.5v13.5" />
move |_| handle_action("stop") </svg>
} <span>"Stop"</span>
>
<svg class="w-4 h-4 text-warning" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 9v6m4-6v6m7-3a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
"Pause"
</button> </button>
</li> </li>
<div class="divider my-0 h-px p-0 opacity-10"></div>
<li> <li>
<button <button class="flex items-center gap-3 px-3 py-2 hover:bg-primary hover:text-primary-content rounded-lg transition-colors" on:click=move |_| {
class="gap-3 text-error hover:bg-error/10 active:bg-error active:text-error-content" handle_action(hash3.clone(), "recheck", on_action.clone(), on_close.clone());
on:click={ }>
let handle_action = handle_action.clone(); <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
move |_| handle_action("delete") <path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99" />
} </svg>
> <span>"Recheck"</span>
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" /></svg>
"Delete"
</button> </button>
</li> </li>
<div class="divider my-0.5 opacity-50"></div>
<li> <li>
<button <button class="flex items-center gap-3 px-3 py-2 text-error hover:bg-error hover:text-error-content rounded-lg transition-colors" on:click=move |_| {
class="gap-3 text-error hover:bg-error/10 active:bg-error active:text-error-content text-xs" handle_action(hash4.clone(), "delete", on_action.clone(), on_close.clone());
on:click={ }>
let handle_action = handle_action.clone(); <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
move |_| handle_action("delete_with_data") <path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.164h-2.34c-1.18 0-2.09.984-2.09 2.164v.916m7.5 0a48.667 48.667 0 00-7.5 0" />
} </svg>
> <span>"Remove"</span>
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" /></svg> </button>
<span>"Delete with Data"</span> </li>
<li>
<button class="flex items-center gap-3 px-3 py-2 text-error hover:bg-error hover:text-error-content rounded-lg transition-colors" on:click=move |_| {
handle_action(hash5.clone(), "delete_with_data", on_action.clone(), on_close.clone());
}>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
<path stroke-linecap="round" stroke-linejoin="round" d="M20.25 7.5l-.625 10.632a2.25 2.25 0 01-2.247 2.118H6.622a2.25 2.25 0 01-2.247-2.118L3.75 7.5m6 4.125l2.25 2.25m0 0l2.25 2.25M12 13.875l2.25-2.25M12 13.875l-2.25-2.25M3.375 7.5h17.25c.621 0 1.125-.504 1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125z" />
</svg>
<span>"Remove Data"</span>
</button> </button>
</li> </li>
</ul> </ul>
</div> </div>
}.into_view() }
} }

View File

@@ -1,33 +1,32 @@
use leptos::prelude::*; use leptos::prelude::*;
use leptos::logging;
use leptos::html;
use leptos::task::spawn_local;
use crate::components::layout::sidebar::Sidebar; use crate::components::layout::sidebar::Sidebar;
use crate::components::layout::statusbar::StatusBar;
use crate::components::layout::toolbar::Toolbar; use crate::components::layout::toolbar::Toolbar;
use crate::components::layout::statusbar::StatusBar;
#[component] #[component]
pub fn Protected(children: Children) -> impl IntoView { pub fn Protected(children: Children) -> impl IntoView {
view! { view! {
<div class="drawer lg:drawer-open h-full w-full"> <div class="drawer lg:drawer-open h-full w-full">
<input id="my-drawer" type="checkbox" class="drawer-toggle" /> <input id="my-drawer" type="checkbox" class="drawer-toggle" />
<div class="drawer-content flex flex-col h-full overflow-hidden bg-base-100 text-base-content text-sm select-none"> <div class="drawer-content flex flex-col h-full overflow-hidden bg-base-100">
// --- TOOLBAR (TOP) ---
<Toolbar /> <Toolbar />
<main class="flex-1 flex flex-col min-w-0 bg-base-100 overflow-hidden pb-8"> // --- MAIN CONTENT ---
<main class="flex-1 overflow-hidden relative">
{children()} {children()}
</main> </main>
// --- STATUS BAR (BOTTOM) ---
<StatusBar /> <StatusBar />
</div> </div>
<div class="drawer-side z-40 transition-none duration-0"> // --- SIDEBAR (DRAWER) ---
<label for="my-drawer" aria-label="close sidebar" class="drawer-overlay transition-none duration-0"></label> <div class="drawer-side z-[100]">
<div class="menu p-0 min-h-full bg-base-200 text-base-content border-r border-base-300 transition-none duration-0"> <label for="my-drawer" aria-label="close sidebar" class="drawer-overlay"></label>
<Sidebar /> <Sidebar />
</div>
</div> </div>
</div> </div>
} }
} }

View File

@@ -1,7 +1,5 @@
use leptos::wasm_bindgen::JsCast;
use leptos::prelude::*; use leptos::prelude::*;
use leptos::logging; use leptos::wasm_bindgen::JsCast;
use leptos::html;
use leptos::task::spawn_local; use leptos::task::spawn_local;
use crate::api; use crate::api;
@@ -76,195 +74,104 @@ pub fn Sidebar() -> impl IntoView {
let handle_logout = move |_| { let handle_logout = move |_| {
spawn_local(async move { spawn_local(async move {
if api::auth::logout().await.is_ok() { 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 || { let username = move || {
store.user.get().unwrap_or_else(|| "User".to_string())
store.user.get().unwrap_or_else(|| "User".to_string()) };
}; let first_letter = move || {
username().chars().next().unwrap_or('?').to_uppercase().to_string()
};
let first_letter = move || { view! {
<div class="w-64 min-h-[100dvh] flex flex-col bg-base-200 border-r border-base-300 pb-8" style="padding-top: env(safe-area-inset-top);">
username().chars().next().unwrap_or('?').to_uppercase().to_string() <div class="p-2 flex-1 overflow-y-auto">
<ul class="menu w-full rounded-box gap-1">
}; <li class="menu-title text-primary uppercase font-bold px-4">"Filters"</li>
<li>
<button class={move || format!("cursor-pointer {}", filter_class(crate::store::FilterStatus::All))} on:click=move |_| set_filter(crate::store::FilterStatus::All)>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
view! { <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" />
</svg>
<div class="w-64 min-h-[100dvh] flex flex-col bg-base-200 border-r border-base-300 pb-8" style="padding-top: env(safe-area-inset-top);"> "All"
<span class="badge badge-sm badge-ghost ml-auto">{total_count}</span>
<div class="p-2 flex-1 overflow-y-auto"> </button>
</li>
<ul class="menu w-full rounded-box gap-1"> <li>
<button class={move || format!("cursor-pointer {}", filter_class(crate::store::FilterStatus::Downloading))} on:click=move |_| set_filter(crate::store::FilterStatus::Downloading)>
<li class="menu-title text-primary uppercase font-bold px-4">"Filters"</li> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3" />
<li> </svg>
"Downloading"
<button class={move || format!("cursor-pointer {}", filter_class(crate::store::FilterStatus::All))} on:click=move |_| set_filter(crate::store::FilterStatus::All)> <span class="badge badge-sm badge-ghost ml-auto">{downloading_count}</span>
</button>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5"> </li>
<li>
<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" /> <button class={move || format!("cursor-pointer {}", filter_class(crate::store::FilterStatus::Seeding))} on:click=move |_| set_filter(crate::store::FilterStatus::Seeding)>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
</svg> <path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5" />
</svg>
"All" "Seeding"
<span class="badge badge-sm badge-ghost ml-auto">{seeding_count}</span>
<span class="badge badge-sm badge-ghost ml-auto">{total_count}</span> </button>
</li>
</button> <li>
<button class={move || format!("cursor-pointer {}", filter_class(crate::store::FilterStatus::Completed))} on:click=move |_| set_filter(crate::store::FilterStatus::Completed)>
</li> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
<li> </svg>
"Completed"
<button class={move || format!("cursor-pointer {}", filter_class(crate::store::FilterStatus::Downloading))} on:click=move |_| set_filter(crate::store::FilterStatus::Downloading)> <span class="badge badge-sm badge-ghost ml-auto">{completed_count}</span>
</button>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5"> </li>
<li>
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3" /> <button class={move || format!("cursor-pointer {}", filter_class(crate::store::FilterStatus::Paused))} on:click=move |_| set_filter(crate::store::FilterStatus::Paused)>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
</svg> <path stroke-linecap="round" stroke-linejoin="round" d="M15.75 5.25v13.5m-7.5-13.5v13.5" />
</svg>
"Downloading" "Paused"
<span class="badge badge-sm badge-ghost ml-auto">{paused_count}</span>
<span class="badge badge-sm badge-ghost ml-auto">{downloading_count}</span> </button>
</li>
</button> <li>
<button class={move || format!("cursor-pointer {}", filter_class(crate::store::FilterStatus::Inactive))} on:click=move |_| set_filter(crate::store::FilterStatus::Inactive)>
</li> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636" />
<li> </svg>
"Inactive"
<button class={move || format!("cursor-pointer {}", filter_class(crate::store::FilterStatus::Seeding))} on:click=move |_| set_filter(crate::store::FilterStatus::Seeding)> <span class="badge badge-sm badge-ghost ml-auto">{inactive_count}</span>
</button>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5"> </li>
</ul>
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5" /> </div>
</svg> <div class="p-4 border-t border-base-300 bg-base-200/50">
<div class="flex items-center gap-3">
"Seeding" <div class="avatar">
<div class="w-8 rounded-full bg-neutral text-neutral-content ring ring-primary ring-offset-base-100 ring-offset-1">
<span class="badge badge-sm badge-ghost ml-auto">{seeding_count}</span> <span class="text-sm font-bold flex items-center justify-center h-full">{first_letter}</span>
</button>
</li>
<li>
<button class={move || format!("cursor-pointer {}", filter_class(crate::store::FilterStatus::Completed))} on:click=move |_| set_filter(crate::store::FilterStatus::Completed)>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
"Completed"
<span class="badge badge-sm badge-ghost ml-auto">{completed_count}</span>
</button>
</li>
<li>
<button class={move || format!("cursor-pointer {}", filter_class(crate::store::FilterStatus::Paused))} on:click=move |_| set_filter(crate::store::FilterStatus::Paused)>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 5.25v13.5m-7.5-13.5v13.5" />
</svg>
"Paused"
<span class="badge badge-sm badge-ghost ml-auto">{paused_count}</span>
</button>
</li>
<li>
<button class={move || format!("cursor-pointer {}", filter_class(crate::store::FilterStatus::Inactive))} on:click=move |_| set_filter(crate::store::FilterStatus::Inactive)>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636" />
</svg>
"Inactive"
<span class="badge badge-sm badge-ghost ml-auto">{inactive_count}</span>
</button>
</li>
</ul>
</div> </div>
<div class="p-4 border-t border-base-300 bg-base-200/50">
<div class="flex items-center gap-3">
<div class="avatar">
<div class="w-8 rounded-full bg-neutral text-neutral-content ring ring-primary ring-offset-base-100 ring-offset-1">
<span class="text-sm font-bold flex items-center justify-center h-full">{first_letter}</span>
</div>
</div>
<div class="flex-1 overflow-hidden">
<div class="font-bold text-sm truncate">{username}</div>
<div class="text-[10px] text-base-content/60 truncate">"Online"</div>
</div>
<button
class="btn btn-ghost btn-xs btn-square text-error hover:bg-error/10"
title="Logout"
on:click=handle_logout
>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15M12 9l-3 3m0 0l3 3m-3-3h12.75" />
</svg>
</button>
</div>
</div>
</div> </div>
<div class="flex-1 overflow-hidden">
}} <div class="font-bold text-sm truncate">{username}</div>
<div class="text-[10px] text-base-content/60 truncate">"Online"</div>
</div>
<button
class="btn btn-ghost btn-xs btn-square text-error hover:bg-error/10"
title="Logout"
on:click=handle_logout
>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15M12 9l-3 3m0 0l3 3m-3-3h12.75" />
</svg>
</button>
</div>
</div>
</div>
}
}

View File

@@ -1,11 +1,8 @@
use leptos::prelude::*; use leptos::prelude::*;
use leptos::logging;
use leptos::html; use leptos::html;
use leptos::task::spawn_local;
use leptos_use::storage::use_local_storage; use leptos_use::storage::use_local_storage;
use ::codee::string::FromToStringCodec; use ::codee::string::FromToStringCodec;
use shared::GlobalLimitRequest; use shared::GlobalLimitRequest;
use reactive_graph::traits::{Get, Set, GetUntracked};
use crate::api; use crate::api;
fn format_bytes(bytes: i64) -> String { fn format_bytes(bytes: i64) -> String {
@@ -33,16 +30,16 @@ pub fn StatusBar() -> impl IntoView {
let store = use_context::<crate::store::TorrentStore>().expect("store not provided"); let store = use_context::<crate::store::TorrentStore>().expect("store not provided");
let stats = store.global_stats; let stats = store.global_stats;
// Use leptos-use for reactive localStorage management
let (current_theme, set_current_theme, _) = use_local_storage::<String, FromToStringCodec>("vibetorrent_theme"); let (current_theme, set_current_theme, _) = use_local_storage::<String, FromToStringCodec>("vibetorrent_theme");
// Initialize with default if empty // 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()); set_current_theme.set("dark".to_string());
} }
// Automatically sync theme to document attribute // Automatically sync theme to document attribute
create_effect(move |_| { Effect::new(move |_| {
let theme = current_theme.get().to_lowercase(); let theme = current_theme.get().to_lowercase();
if let Some(doc) = document().document_element() { if let Some(doc) = document().document_element() {
let _ = doc.set_attribute("data-theme", &theme); let _ = doc.set_attribute("data-theme", &theme);
@@ -50,7 +47,7 @@ pub fn StatusBar() -> impl IntoView {
}); });
// Preset limits in bytes/s // Preset limits in bytes/s
let limits: Vec<(i64, &str)> = vec![ let limits: Vec<(i64, &str)> = vec!(
(0, "Unlimited"), (0, "Unlimited"),
(100 * 1024, "100 KB/s"), (100 * 1024, "100 KB/s"),
(500 * 1024, "500 KB/s"), (500 * 1024, "500 KB/s"),
@@ -59,11 +56,11 @@ pub fn StatusBar() -> impl IntoView {
(5 * 1024 * 1024, "5 MB/s"), (5 * 1024 * 1024, "5 MB/s"),
(10 * 1024 * 1024, "10 MB/s"), (10 * 1024 * 1024, "10 MB/s"),
(20 * 1024 * 1024, "20 MB/s"), (20 * 1024 * 1024, "20 MB/s"),
]; );
let set_limit = move |limit_type: &str, val: i64| { let set_limit = move |limit_type: &str, val: i64| {
let limit_type = limit_type.to_string(); 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" { let req = if limit_type == "down" {
GlobalLimitRequest { 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 { 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 { } 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 = NodeRef::<html::Details>::new();
let down_details_ref = create_node_ref::<html::Details>(); let up_details_ref = NodeRef::<html::Details>::new();
let up_details_ref = create_node_ref::<html::Details>(); let theme_details_ref = NodeRef::<html::Details>::new();
let theme_details_ref = create_node_ref::<html::Details>();
// Helper to close a details element let close_details = move |node_ref: NodeRef<html::Details>| {
let close_details = |node_ref: NodeRef<html::Details>| {
if let Some(el) = node_ref.get_untracked() { if let Some(el) = node_ref.get_untracked() {
el.set_open(false); el.set_open(false);
} }
@@ -199,16 +194,19 @@ pub fn StatusBar() -> impl IntoView {
"light", "dark", "dim", "nord", "cupcake", "dracula", "cyberpunk", "emerald", "sunset", "abyss" "light", "dark", "dim", "nord", "cupcake", "dracula", "cyberpunk", "emerald", "sunset", "abyss"
]; ];
themes.into_iter().map(|theme| { 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! { view! {
<li> <li>
<button <button
class=move || if current_theme.get() == theme { "bg-primary/10 text-primary font-bold text-xs capitalize" } else { "text-xs capitalize" } class=move || if current_theme.get() == theme_name_for_class { "bg-primary/10 text-primary font-bold text-xs capitalize" } else { "text-xs capitalize" }
on:click=move |_| { on:click=move |_| {
set_current_theme.set(theme.to_string()); set_current_theme.set(theme_name_for_onclick.clone());
close_details(theme_details_ref); close_details(theme_details_ref);
} }
> >
{theme} {theme_name}
</button> </button>
</li> </li>
} }
@@ -221,7 +219,7 @@ pub fn StatusBar() -> impl IntoView {
title="Settings & Notification Permissions" title="Settings & Notification Permissions"
on:click=move |_| { on:click=move |_| {
// Request push notification permission when settings button is clicked // 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"); log::info!("Settings button clicked - requesting push notification permission");
// Check current permission state before requesting // Check current permission state before requesting
@@ -266,11 +264,11 @@ pub fn StatusBar() -> impl IntoView {
} }
> >
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4">
<path stroke-linecap="round" stroke-linejoin="round" d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.24-.438.613-.431.992a6.759 6.759 0 010 .255c-.007.378.138.75.43.99l1.005.828c.424.35.534.954.26 1.43l-1.298 2.247a1.125 1.125 0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.57 6.57 0 01-.22.128c-.331.183-.581.495-.644.869l-.212 1.28c-.09.543-.56.941-1.11.941h-2.594c-.55 0-1.02-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 1.125 0 01.26-1.431l1.004-.827c.292-.24.437-.613.43-.992a6.932 6.932 0 010-.255c.007-.378-.138-.75-.43-.99l-1.004-.828a1.125 1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281z" /> <path stroke-linecap="round" stroke-linejoin="round" d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.24-.438.613-.431.992a6.759 6.759 0 010 .255c-.007.378.138.75.43.99l1.005.828c.424.35.534.954.26 1.43l-1.298 2.247a1.125 1.125 0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.57 6.57 0 01-.22.128c-.331.183-.581.495-.644.869l-.212 1.28c-.09.543-.56.941-1.11.941h-2.594c-.55 0-1.02-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 1.125 0 012.6-1.431l1.004-.827c.292-.24.437-.613.43-.992a6.932 6.932 0 010-.255c.007-.378-.138-.75-.43-.99l-1.004-.828a1.125 1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /> <path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
</svg> </svg>
</button> </button>
</div> </div>
</div> </div>
} }
} }

View File

@@ -1,11 +1,9 @@
use leptos::prelude::*; use leptos::prelude::*;
use leptos::logging; use crate::components::torrent::add_torrent::AddTorrentDialog;
use leptos::html;
use leptos::task::spawn_local;
#[component] #[component]
pub fn Toolbar() -> impl IntoView { 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::<crate::store::TorrentStore>().expect("store not provided"); let store = use_context::<crate::store::TorrentStore>().expect("store not provided");
view! { view! {
@@ -14,54 +12,48 @@ pub fn Toolbar() -> impl IntoView {
<label for="my-drawer" class="btn btn-square btn-ghost lg:hidden drawer-button"> <label for="my-drawer" class="btn btn-square btn-ghost lg:hidden drawer-button">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-5 h-5 stroke-current"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-5 h-5 stroke-current"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path></svg>
</label> </label>
<div class="flex gap-2"> <div class="flex items-center gap-3">
<button <button
class="btn btn-sm btn-primary gap-2 font-normal" class="btn btn-primary btn-sm md:btn-md gap-2 shadow-md hover:shadow-primary/20 transition-all"
title="Add Magnet Link" on:click=move |_| show_add_modal.1.set(true)
on:click=move |_| set_show_add_modal.set(true)
> >
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-4 h-4 md:w-5 md:h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" /> <path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
</svg> </svg>
"Add Torrent" <span class="hidden sm:inline">"Add Torrent"</span>
<span class="sm:hidden">"Add"</span>
</button> </button>
</div> </div>
</div> </div>
<div class="navbar-end gap-2 px-4"> <div class="navbar-center hidden md:flex">
<div class="join"> <div class="join shadow-sm border border-base-200">
<input <div class="relative">
type="text" <input
placeholder="Search..." type="text"
class="input input-sm input-bordered join-item w-full max-w-xs focus:outline-none" placeholder="Search..."
prop:value=move || store.search_query.get() class="input input-sm input-bordered join-item w-full max-w-xs focus:outline-none"
on:input=move |ev| store.search_query.set(event_target_value(&ev)) prop:value=move || store.search_query.get()
on:keydown=move |ev: web_sys::KeyboardEvent| { on:input=move |ev| store.search_query.set(event_target_value(&ev))
if ev.key() == "Escape" { />
store.search_query.set(String::new()); <Show when=move || !store.search_query.get().is_empty()>
} <button
} class="absolute right-2 top-1/2 -translate-y-1/2 btn btn-ghost btn-xs btn-circle"
/> on:click=move |_| store.search_query.set(String::new())
<Show when=move || !store.search_query.get().is_empty()> >
<button "×"
class="btn btn-sm btn-ghost join-item border-base-content/20 border-l-0 px-2" </button>
title="Clear Search" </Show>
on:click=move |_| store.search_query.set(String::new()) </div>
> </div>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4 opacity-70">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</Show>
</div>
</div> </div>
<Show when=move || show_add_modal.get()> <div class="navbar-end px-4 gap-2">
<crate::components::torrent::add_torrent::AddTorrentModal on_close=move |_| set_show_add_modal.set(false) /> <Show when=move || show_add_modal.0.get()>
</Show> <AddTorrentDialog on_close=Callback::new(move |()| show_add_modal.1.set(false)) />
</Show>
</div>
</div> </div>
} }
} }

View File

@@ -1,12 +1,9 @@
use leptos::prelude::*; use leptos::prelude::*;
use leptos::logging;
use leptos::html;
use leptos::task::spawn_local;
#[component] #[component]
pub fn Modal( pub fn Modal(
#[prop(into)] title: String, #[prop(into)] title: String,
children: Children, children: ChildrenFn,
#[prop(into)] on_confirm: Callback<()>, #[prop(into)] on_confirm: Callback<()>,
#[prop(into)] on_cancel: Callback<()>, #[prop(into)] on_cancel: Callback<()>,
#[prop(into)] visible: Signal<bool>, #[prop(into)] visible: Signal<bool>,
@@ -15,8 +12,6 @@ pub fn Modal(
#[prop(into, default = false)] is_danger: bool, #[prop(into, default = false)] is_danger: bool,
) -> impl IntoView { ) -> impl IntoView {
let title = StoredValue::new_local(title); 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_confirm = StoredValue::new_local(on_confirm);
let on_cancel = StoredValue::new_local(on_cancel); let on_cancel = StoredValue::new_local(on_cancel);
let confirm_text = StoredValue::new_local(confirm_text); let confirm_text = StoredValue::new_local(confirm_text);
@@ -26,10 +21,10 @@ pub fn Modal(
<Show when=move || visible.get() fallback=|| ()> <Show when=move || visible.get() fallback=|| ()>
<div class="fixed inset-0 bg-background/80 backdrop-blur-sm flex items-end md:items-center justify-center z-[200] animate-in fade-in duration-200 sm:p-4"> <div class="fixed inset-0 bg-background/80 backdrop-blur-sm flex items-end md:items-center justify-center z-[200] animate-in fade-in duration-200 sm:p-4">
<div class="bg-card p-6 rounded-t-2xl md:rounded-lg w-full max-w-sm shadow-xl border border-border ring-0 transform transition-all animate-in slide-in-from-bottom-10 md:slide-in-from-bottom-0 md:zoom-in-95"> <div class="bg-card p-6 rounded-t-2xl md:rounded-lg w-full max-w-sm shadow-xl border border-border ring-0 transform transition-all animate-in slide-in-from-bottom-10 md:slide-in-from-bottom-0 md:zoom-in-95">
<h3 class="text-lg font-semibold text-card-foreground mb-4">{title.get_value()}</h3> <h3 class="text-lg font-semibold text-card-foreground mb-4">{move || title.get_value()}</h3>
<div class="text-muted-foreground mb-6 text-sm"> <div class="text-muted-foreground mb-6 text-sm">
{child_view.with_value(|c| c.clone())} {children()}
</div> </div>
<div class="flex justify-end gap-3"> <div class="flex justify-end gap-3">
@@ -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" 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(())) on:click=move |_| on_cancel.with_value(|cb| cb.run(()))
> >
{cancel_text.get_value()} {move || cancel_text.get_value()}
</button> </button>
<button <button
class=move || crate::utils::cn(format!("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 h-10 px-4 py-2 {}", class=move || crate::utils::cn(format!("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 h-10 px-4 py-2 {}",
@@ -45,11 +40,11 @@ pub fn Modal(
else { "bg-primary text-primary-foreground hover:bg-primary/90" } else { "bg-primary text-primary-foreground hover:bg-primary/90" }
)) ))
on:click=move |_| { on:click=move |_| {
logging::log!("Modal: Confirm clicked"); log::info!("Modal: Confirm clicked");
on_confirm.with_value(|cb| cb.run(())) on_confirm.with_value(|cb| cb.run(()))
} }
> >
{confirm_text.get_value()} {move || confirm_text.get_value()}
</button> </button>
</div> </div>
</div> </div>

View File

@@ -1,66 +1,64 @@
use leptos::prelude::*; use leptos::prelude::*;
use leptos::logging;
use leptos::html; use leptos::html;
use leptos::task::spawn_local; use leptos::task::spawn_local;
use leptos::html::Dialog; use crate::store::TorrentStore;
use crate::store::{show_toast_with_signal, TorrentStore};
use crate::api; use crate::api;
use shared::NotificationLevel;
#[component] #[component]
pub fn AddTorrentModal( pub fn AddTorrentDialog(
#[prop(into)]
on_close: Callback<()>, on_close: Callback<()>,
) -> impl IntoView { ) -> impl IntoView {
let store = use_context::<TorrentStore>().expect("TorrentStore not provided"); let store = use_context::<TorrentStore>().expect("TorrentStore not provided");
let notifications = store.notifications; let notifications = store.notifications;
let dialog_ref = create_node_ref::<Dialog>();
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::<String>::None);
create_effect(move |_| { let dialog_ref = NodeRef::<html::Dialog>::new();
let uri = signal(String::new());
let is_loading = signal(false);
let error_msg = signal(Option::<String>::None);
Effect::new(move |_| {
if let Some(dialog) = dialog_ref.get() { if let Some(dialog) = dialog_ref.get() {
let _ = dialog.show_modal(); let _ = dialog.show_modal();
} }
}); });
let handle_submit = move |_| { let handle_submit = move |ev: web_sys::SubmitEvent| {
let uri_val = uri.get(); ev.prevent_default();
let uri_val = uri.0.get();
if uri_val.is_empty() { if uri_val.is_empty() {
show_toast_with_signal(notifications, NotificationLevel::Warning, "Lütfen bir Magnet URI veya URL girin"); error_msg.1.set(Some("Please enter a Magnet URI or URL".to_string()));
set_error_msg.set(Some("Please enter a Magnet URI or URL".to_string()));
return; return;
} }
set_loading.set(true); is_loading.1.set(true);
set_error_msg.set(None); error_msg.1.set(None);
let uri_val = uri_val; let on_close = on_close.clone();
spawn_local(async move { spawn_local(async move {
match api::torrent::add(&uri_val).await { match api::torrent::add(&uri_val).await {
Ok(_) => { Ok(_) => {
logging::log!("Torrent added successfully"); log::info!("Torrent added successfully");
show_toast_with_signal(notifications, NotificationLevel::Success, "Torrent eklendi"); crate::store::show_toast_with_signal(
set_loading.set(false); notifications,
shared::NotificationLevel::Success,
"Torrent başarıyla eklendi"
);
if let Some(dialog) = dialog_ref.get() { if let Some(dialog) = dialog_ref.get() {
dialog.close(); dialog.close();
} }
on_close.run(()); on_close.run(());
} }
Err(e) => { Err(e) => {
logging::error!("Failed to add torrent: {:?}", e); log::error!("Failed to add torrent: {:?}", e);
show_toast_with_signal(notifications, NotificationLevel::Error, "Torrent eklenemedi"); error_msg.1.set(Some(format!("Hata: {:?}", e)));
set_error_msg.set(Some(format!("Error: {:?}", e))); is_loading.1.set(false);
set_loading.set(false);
} }
} }
}); });
}; };
let handle_close = move |_| { let handle_cancel = move |_| {
if let Some(dialog) = dialog_ref.get() { if let Some(dialog) = dialog_ref.get() {
dialog.close(); dialog.close();
} }
@@ -71,37 +69,40 @@ pub fn AddTorrentModal(
<dialog node_ref=dialog_ref class="modal modal-bottom sm:modal-middle"> <dialog node_ref=dialog_ref class="modal modal-bottom sm:modal-middle">
<div class="modal-box"> <div class="modal-box">
<h3 class="font-bold text-lg">"Add Torrent"</h3> <h3 class="font-bold text-lg">"Add Torrent"</h3>
<p class="py-4">"Enter a Magnet URI or direct URL to a .torrent file."</p> <p class="py-4 text-sm opacity-70">"Enter a Magnet link or a .torrent file URL."</p>
<div class="form-control w-full"> <form on:submit=handle_submit>
<input <div class="form-control w-full">
type="text" <input
placeholder="magnet:?xt=urn:btih:..." type="text"
class="input input-bordered w-full" placeholder="magnet:?xt=urn:btih:..."
prop:value=uri class="input input-bordered w-full"
on:input=move |ev| set_uri.set(event_target_value(&ev)) prop:value=move || uri.0.get()
disabled=is_loading on:input=move |ev| uri.1.set(event_target_value(&ev))
/> disabled=move || is_loading.0.get()
</div> autofocus
/>
</div>
<div class="modal-action">
<button type="button" class="btn btn-ghost" on:click=handle_cancel>"Cancel"</button>
<button type="submit" class="btn btn-primary" disabled=move || is_loading.0.get()>
{move || if is_loading.0.get() {
leptos::either::Either::Left(view! { <span class="loading loading-spinner"></span> "Adding..." })
} else {
leptos::either::Either::Right(view! { "Add" })
}}
</button>
</div>
</form>
<div class="modal-action"> {move || error_msg.0.get().map(|msg| view! {
<button class="btn" on:click=handle_close disabled=is_loading>"Cancel"</button>
<button class="btn btn-primary" on:click=handle_submit disabled=is_loading>
{move || if is_loading.get() {
leptos::either::Either::Left(view! { <span class="loading loading-spinner"></span> "Adding..." })
} else {
leptos::either::Either::Right(view! { "Add" })
}}
</button>
</div>
{move || error_msg.get().map(|msg| view! {
<div class="text-error text-sm mt-2">{msg}</div> <div class="text-error text-sm mt-2">{msg}</div>
})} })}
</div> </div>
<form method="dialog" class="modal-backdrop"> <form method="dialog" class="modal-backdrop">
<button type="button" on:click=handle_close>"close"</button> <button on:click=handle_cancel>"close"</button>
</form> </form>
</dialog> </dialog>
} }
} }

View File

@@ -1,142 +1,80 @@
use leptos::prelude::*; use leptos::prelude::*;
use leptos::logging;
use leptos::html; use leptos::html;
use leptos::task::spawn_local; use leptos::task::spawn_local;
use leptos_use::{on_click_outside, use_timeout_fn}; use leptos_use::use_timeout_fn;
use crate::store::{get_action_messages, show_toast_with_signal, FilterStatus}; use crate::store::{get_action_messages, show_toast_with_signal};
use crate::api; use crate::api;
use shared::{NotificationLevel, Torrent}; use shared::{NotificationLevel, Torrent};
use std::collections::HashMap;
fn format_bytes(bytes: i64) -> String { fn format_bytes(bytes: i64) -> String {
const UNITS: [&str; 6] = ["B", "KB", "MB", "GB", "TB", "PB"]; const UNITS: [&str; 6] = ["B", "KB", "MB", "GB", "TB", "PB"];
if bytes < 1024 { if bytes < 1024 { return format!("{} B", bytes); }
return format!("{} B", bytes);
}
let i = (bytes as f64).log2().div_euclid(10.0) as usize; let i = (bytes as f64).log2().div_euclid(10.0) as usize;
format!( format!("{:.1} {}", (bytes as f64) / 1024_f64.powi(i as i32), UNITS[i])
"{:.1} {}",
(bytes as f64) / 1024_f64.powi(i as i32),
UNITS[i]
)
} }
fn format_speed(bytes_per_sec: i64) -> String { fn format_speed(bytes_per_sec: i64) -> String {
if bytes_per_sec == 0 { if bytes_per_sec == 0 { return "0 B/s".to_string(); }
return "0 B/s".to_string();
}
format!("{}/s", format_bytes(bytes_per_sec)) format!("{}/s", format_bytes(bytes_per_sec))
} }
fn format_duration(seconds: i64) -> String { fn format_duration(seconds: i64) -> String {
if seconds <= 0 { if seconds <= 0 { return "".to_string(); }
return "".to_string();
}
let days = seconds / 86400; let days = seconds / 86400;
let hours = (seconds % 86400) / 3600; let hours = (seconds % 86400) / 3600;
let minutes = (seconds % 3600) / 60; let minutes = (seconds % 3600) / 60;
let secs = seconds % 60; let secs = seconds % 60;
if days > 0 { format!("{}d {}h", days, hours) }
if days > 0 { else if hours > 0 { format!("{}h {}m", hours, minutes) }
format!("{}d {}h", days, hours) else if minutes > 0 { format!("{}m {}s", minutes, secs) }
} else if hours > 0 { else { format!("{}s", secs) }
format!("{}h {}m", hours, minutes)
} else if minutes > 0 {
format!("{}m {}s", minutes, secs)
} else {
format!("{}s", secs)
}
} }
fn format_date(timestamp: i64) -> String { fn format_date(timestamp: i64) -> String {
if timestamp <= 0 { if timestamp <= 0 { return "N/A".to_string(); }
return "N/A".to_string();
}
let dt = chrono::DateTime::from_timestamp(timestamp, 0); let dt = chrono::DateTime::from_timestamp(timestamp, 0);
match dt { match dt { Some(dt) => dt.format("%d/%m/%Y %H:%M").to_string(), None => "N/A".to_string() }
Some(dt) => dt.format("%d/%m/%Y %H:%M").to_string(),
None => "N/A".to_string(),
}
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum SortColumn { enum SortColumn {
Name, Name, Size, Progress, Status, DownSpeed, UpSpeed, ETA, AddedDate,
Size,
Progress,
Status,
DownSpeed,
UpSpeed,
ETA,
AddedDate,
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum SortDirection { enum SortDirection { Ascending, Descending }
Ascending,
Descending,
}
#[component] #[component]
pub fn TorrentTable() -> impl IntoView { pub fn TorrentTable() -> impl IntoView {
let store = use_context::<crate::store::TorrentStore>().expect("store not provided"); let store = use_context::<crate::store::TorrentStore>().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 || { let filtered_hashes = move || {
store.torrents.with(|map| { store.torrents.with(|map| {
let mut torrents: Vec<&shared::Torrent> = map let mut torrents: Vec<&shared::Torrent> = map.values().filter(|t| {
.values() let filter = store.filter.get();
.filter(|t| { let search = store.search_query.get().to_lowercase();
let filter = store.filter.get(); let matches_filter = match filter {
let search = store.search_query.get().to_lowercase(); crate::store::FilterStatus::All => true,
crate::store::FilterStatus::Downloading => t.status == shared::TorrentStatus::Downloading,
let matches_filter = match filter { crate::store::FilterStatus::Seeding => t.status == shared::TorrentStatus::Seeding,
crate::store::FilterStatus::All => true, crate::store::FilterStatus::Completed => t.status == shared::TorrentStatus::Seeding || (t.status == shared::TorrentStatus::Paused && t.percent_complete >= 100.0),
crate::store::FilterStatus::Downloading => { crate::store::FilterStatus::Paused => t.status == shared::TorrentStatus::Paused,
t.status == shared::TorrentStatus::Downloading crate::store::FilterStatus::Inactive => t.status == shared::TorrentStatus::Paused || t.status == shared::TorrentStatus::Error,
} _ => true,
crate::store::FilterStatus::Seeding => { };
t.status == shared::TorrentStatus::Seeding let matches_search = if search.is_empty() { true } else { t.name.to_lowercase().contains(&search) };
} matches_filter && matches_search
crate::store::FilterStatus::Completed => { }).collect();
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| { torrents.sort_by(|a, b| {
let col = sort_col.get(); let col = sort_col.0.get();
let dir = sort_dir.get(); let dir = sort_dir.0.get();
let cmp = match col { let cmp = match col {
SortColumn::Name => a.name.to_lowercase().cmp(&b.name.to_lowercase()), SortColumn::Name => a.name.to_lowercase().cmp(&b.name.to_lowercase()),
SortColumn::Size => a.size.cmp(&b.size), SortColumn::Size => a.size.cmp(&b.size),
SortColumn::Progress => a SortColumn::Progress => a.percent_complete.partial_cmp(&b.percent_complete).unwrap_or(std::cmp::Ordering::Equal),
.percent_complete
.partial_cmp(&b.percent_complete)
.unwrap_or(std::cmp::Ordering::Equal),
SortColumn::Status => format!("{:?}", a.status).cmp(&format!("{:?}", b.status)), SortColumn::Status => format!("{:?}", a.status).cmp(&format!("{:?}", b.status)),
SortColumn::DownSpeed => a.down_rate.cmp(&b.down_rate), SortColumn::DownSpeed => a.down_rate.cmp(&b.down_rate),
SortColumn::UpSpeed => a.up_rate.cmp(&b.up_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), SortColumn::AddedDate => a.added_date.cmp(&b.added_date),
}; };
if dir == SortDirection::Descending { if dir == SortDirection::Descending { cmp.reverse() } else { cmp }
cmp.reverse()
} else {
cmp
}
}); });
torrents.into_iter().map(|t| t.hash.clone()).collect::<Vec<String>>() torrents.into_iter().map(|t| t.hash.clone()).collect::<Vec<String>>()
}) })
}; };
let handle_sort = move |col: SortColumn| { let handle_sort = move |col: SortColumn| {
if sort_col.get() == col { if sort_col.0.get() == col {
sort_dir.update(|d| { sort_dir.1.update(|d| {
*d = match d { *d = match d { SortDirection::Ascending => SortDirection::Descending, SortDirection::Descending => SortDirection::Ascending };
SortDirection::Ascending => SortDirection::Descending,
SortDirection::Descending => SortDirection::Ascending,
}
}); });
} else { } else {
sort_col.set(col); sort_col.1.set(col);
sort_dir.set(SortDirection::Ascending); sort_dir.1.set(SortDirection::Ascending);
} }
}; };
// Refs for click outside detection let sort_details_ref = NodeRef::<html::Details>::new();
let sort_details_ref = create_node_ref::<html::Details>();
let _ = on_click_outside(sort_details_ref, move |_| {
if let Some(el) = sort_details_ref.get_untracked() {
el.set_open(false);
}
});
let sort_arrow = move |col: SortColumn| { let sort_arrow = move |col: SortColumn| {
if sort_col.get() == col { if sort_col.0.get() == col {
match sort_dir.get() { match sort_dir.0.get() {
SortDirection::Ascending => { SortDirection::Ascending => view! { <span class="ml-1 text-xs">""</span> }.into_any(),
view! { <span class="ml-1 text-xs">""</span> }.into_any() SortDirection::Descending => view! { <span class="ml-1 text-xs">""</span> }.into_any(),
}
SortDirection::Descending => {
view! { <span class="ml-1 text-xs">""</span> }.into_any()
}
} }
} else { } else { view! { <span class="ml-1 text-xs opacity-0 group-hover:opacity-50">""</span> }.into_any() }
view! { <span class="ml-1 text-xs opacity-0 group-hover:opacity-50">""</span> }
.into_any()
}
}; };
let (selected_hash, set_selected_hash) = create_signal(Option::<String>::None); let selected_hash = signal(Option::<String>::None);
let (menu_visible, set_menu_visible) = create_signal(false); let menu_visible = signal(false);
let (menu_position, set_menu_position) = create_signal((0, 0)); let menu_position = signal((0, 0));
let handle_context_menu = move |e: web_sys::MouseEvent, hash: String| { let handle_context_menu = move |e: web_sys::MouseEvent, hash: String| {
e.prevent_default(); e.prevent_default();
set_menu_position.set((e.client_x(), e.client_y())); menu_position.1.set((e.client_x(), e.client_y()));
set_selected_hash.set(Some(hash)); // Select on right click too selected_hash.1.set(Some(hash));
set_menu_visible.set(true); menu_visible.1.set(true);
}; };
let on_action = move |(action, hash): (String, String)| { let on_action = move |(action, hash): (String, String)| {
logging::log!("TorrentTable Action: {} on {}", action, hash); let (success_msg_str, error_msg_str): (&'static str, &'static str) = get_action_messages(&action);
let success_msg = success_msg_str.to_string();
let (success_msg, error_msg) = get_action_messages(&action); let error_msg = error_msg_str.to_string();
let success_msg = success_msg.to_string();
let error_msg = error_msg.to_string();
let notifications = store.notifications; let notifications = store.notifications;
let hash = hash.clone();
let action = action.clone();
spawn_local(async move { spawn_local(async move {
let result = match action.as_str() { let result = match action.as_str() {
"delete" => api::torrent::delete(&hash).await, "delete" => api::torrent::delete(&hash).await,
@@ -227,16 +137,9 @@ pub fn TorrentTable() -> impl IntoView {
"stop" => api::torrent::stop(&hash).await, "stop" => api::torrent::stop(&hash).await,
_ => api::torrent::action(&hash, &action).await, _ => api::torrent::action(&hash, &action).await,
}; };
match result { match result {
Ok(_) => { Ok(_) => show_toast_with_signal(notifications, NotificationLevel::Success, success_msg),
logging::log!("Action {} executed successfully", action); Err(e) => show_toast_with_signal(notifications, NotificationLevel::Error, format!("{}: {:?}", error_msg, e)),
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));
}
} }
}); });
}; };
@@ -274,23 +177,10 @@ pub fn TorrentTable() -> impl IntoView {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<For <For each=move || filtered_hashes() key=|hash| hash.clone() children={
each=move || filtered_hashes() let handle_context_menu = handle_context_menu.clone();
key=|hash| hash.clone() move |hash| view! { <TorrentRow hash=hash.clone() selected_hash=selected_hash.0 set_selected_hash=selected_hash.1 on_context_menu=handle_context_menu.clone() /> }
children={ } />
let handle_context_menu = handle_context_menu.clone();
move |hash| {
view! {
<TorrentRow
hash=hash.clone()
selected_hash=selected_hash
set_selected_hash=set_selected_hash
on_context_menu=handle_context_menu.clone()
/>
}
}
}
/>
</tbody> </tbody>
</table> </table>
</div> </div>
@@ -298,53 +188,22 @@ pub fn TorrentTable() -> impl IntoView {
<div class="md:hidden flex flex-col h-full bg-base-200 relative cursor-pointer"> <div class="md:hidden flex flex-col h-full bg-base-200 relative cursor-pointer">
<div class="px-3 py-2 border-b border-base-200 flex justify-between items-center bg-base-100/95 backdrop-blur z-10 shrink-0 cursor-default"> <div class="px-3 py-2 border-b border-base-200 flex justify-between items-center bg-base-100/95 backdrop-blur z-10 shrink-0 cursor-default">
<span class="text-xs font-bold opacity-50 uppercase tracking-wider">"Torrents"</span> <span class="text-xs font-bold opacity-50 uppercase tracking-wider">"Torrents"</span>
<details class="dropdown dropdown-end" node_ref=sort_details_ref> <details class="dropdown dropdown-end" node_ref=sort_details_ref>
<summary class="btn btn-ghost btn-xs gap-1 opacity-70 font-normal list-none [&::-webkit-details-marker]:hidden cursor-pointer"> <summary class="btn btn-ghost btn-xs gap-1 opacity-70 font-normal list-none [&::-webkit-details-marker]:hidden cursor-pointer">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4 pointer-events-none"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4 pointer-events-none"><path stroke-linecap="round" stroke-linejoin="round" d="M3 7.5L7.5 3m0 0L12 7.5M7.5 3v13.5m13.5 0L16.5 21m0 0L12 16.5m4.5 4.5V7.5" /></svg>
<path stroke-linecap="round" stroke-linejoin="round" d="M3 7.5L7.5 3m0 0L12 7.5M7.5 3v13.5m13.5 0L16.5 21m0 0L12 16.5m4.5 4.5V7.5" />
</svg>
<span class="pointer-events-none">"Sort"</span> <span class="pointer-events-none">"Sort"</span>
</summary> </summary>
<ul class="dropdown-content z-[100] menu p-2 shadow bg-base-100 rounded-box w-48 mt-1 border border-base-200 text-xs cursor-default"> <ul class="dropdown-content z-[100] menu p-2 shadow bg-base-100 rounded-box w-48 mt-1 border border-base-200 text-xs cursor-default">
<li class="menu-title px-2 py-1 opacity-50 text-[10px] uppercase font-bold">"Sort By"</li> <li class="menu-title px-2 py-1 opacity-50 text-[10px] uppercase font-bold">"Sort By"</li>
{ {
let columns = vec![ let columns = vec![(SortColumn::Name, "Name"), (SortColumn::Size, "Size"), (SortColumn::Progress, "Progress"), (SortColumn::Status, "Status"), (SortColumn::DownSpeed, "DL Speed"), (SortColumn::UpSpeed, "Up Speed"), (SortColumn::ETA, "ETA"), (SortColumn::AddedDate, "Date")];
(SortColumn::Name, "Name"),
(SortColumn::Size, "Size"),
(SortColumn::Progress, "Progress"),
(SortColumn::Status, "Status"),
(SortColumn::DownSpeed, "DL Speed"),
(SortColumn::UpSpeed, "Up Speed"),
(SortColumn::ETA, "ETA"),
(SortColumn::AddedDate, "Date"),
];
columns.into_iter().map(|(col, label)| { columns.into_iter().map(|(col, label)| {
let is_active = move || sort_col.get() == col; let is_active = move || sort_col.0.get() == col;
let current_dir = move || sort_dir.get();
view! { view! {
<li> <li>
<button <button type="button" class=move || if is_active() { "bg-primary/10 text-primary font-bold flex justify-between" } else { "flex justify-between" } on:click=move |_| { handle_sort(col); if let Some(el) = sort_details_ref.get() { el.set_open(false); } }>
type="button"
class=move || if is_active() { "bg-primary/10 text-primary font-bold flex justify-between" } else { "flex justify-between" }
on:click=move |_| {
handle_sort(col);
if let Some(el) = sort_details_ref.get_untracked() {
el.set_open(false);
}
}
>
{label} {label}
<Show when=is_active fallback=|| ()> <Show when=is_active fallback=|| ()><span class="opacity-70 text-[10px]">{move || match sort_dir.0.get() { SortDirection::Ascending => "", SortDirection::Descending => "" }}</span></Show>
<span class="opacity-70 text-[10px]">
{move || match current_dir() {
SortDirection::Ascending => "",
SortDirection::Descending => "",
}}
</span>
</Show>
</button> </button>
</li> </li>
} }
@@ -353,38 +212,16 @@ pub fn TorrentTable() -> impl IntoView {
</ul> </ul>
</details> </details>
</div> </div>
<div class="overflow-y-auto p-3 pb-20 flex-1 grid grid-cols-1 content-start gap-3 cursor-pointer"> <div class="overflow-y-auto p-3 pb-20 flex-1 grid grid-cols-1 content-start gap-3 cursor-pointer">
<For <For each=move || filtered_hashes() key=|hash| hash.clone() children={
each=move || filtered_hashes() let handle_context_menu = handle_context_menu.clone();
key=|hash| hash.clone() move |hash| view! { <TorrentCard hash=hash.clone() selected_hash=selected_hash.0 set_selected_hash=selected_hash.1 set_menu_position=menu_position.1 set_menu_visible=menu_visible.1 on_context_menu=handle_context_menu.clone() /> }
children={ } />
let handle_context_menu = handle_context_menu.clone();
move |hash| {
view! {
<TorrentCard
hash=hash.clone()
selected_hash=selected_hash
set_selected_hash=set_selected_hash
set_menu_position=set_menu_position
set_menu_visible=set_menu_visible
on_context_menu=handle_context_menu.clone()
/>
}
}
}
/>
</div> </div>
</div> </div>
<Show when=move || menu_visible.get() fallback=|| ()> <Show when=move || menu_visible.0.get() fallback=|| ()>
<crate::components::context_menu::ContextMenu <crate::components::context_menu::ContextMenu position=menu_position.0.get() torrent_hash=selected_hash.0.get().unwrap_or_default() on_close=Callback::new(move |()| menu_visible.1.set(false)) on_action=Callback::new(move |args| on_action(args)) />
visible=true
position=menu_position.get()
torrent_hash=selected_hash.get().unwrap_or_default()
on_close=Callback::new(move |()| set_menu_visible.set(false))
on_action=Callback::new(move |args| on_action(args))
/>
</Show> </Show>
</div> </div>
} }
@@ -398,45 +235,29 @@ fn TorrentRow(
on_context_menu: impl Fn(web_sys::MouseEvent, String) + 'static + Clone + Send + Sync, on_context_menu: impl Fn(web_sys::MouseEvent, String) + 'static + Clone + Send + Sync,
) -> impl IntoView { ) -> impl IntoView {
let store = use_context::<crate::store::TorrentStore>().expect("store not provided"); let store = use_context::<crate::store::TorrentStore>().expect("store not provided");
let h = hash.clone(); let h = hash.clone();
// Memoized access to the specific torrent data. let torrent = Memo::new(move |_| store.torrents.with(|map| map.get(&h).cloned()));
// 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())
});
view! { view! {
<Show when=move || torrent.get().is_some() fallback=|| ()> <Show when=move || torrent.get().is_some() fallback=|| ()>
{ {
let on_context_menu = on_context_menu.clone(); let on_context_menu = on_context_menu.clone();
let hash = hash.clone(); let hash = hash.clone();
move || { move || {
let t = torrent.get().unwrap(); let t = torrent.get().unwrap();
let t_hash = hash.clone(); let t_hash = hash.clone();
let t_hash_class = t_hash.clone(); let t_name = t.name.clone();
let on_context_menu = on_context_menu.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 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 { let selected_hash_clone = selected_hash.clone();
shared::TorrentStatus::Seeding => "text-success", let t_hash_row = t_hash.clone();
shared::TorrentStatus::Downloading => "text-primary",
shared::TorrentStatus::Paused => "text-warning",
shared::TorrentStatus::Error => "text-error",
_ => "text-base-content/50"
};
view! { view! {
<tr <tr
class=move || { class=move || {
let base = "hover border-b border-base-200 select-none"; let base = "hover border-b border-base-200 select-none";
if selected_hash.get() == Some(t_hash_class.clone()) { if selected_hash_clone.get() == Some(t_hash_row.clone()) { format!("{} bg-primary/10", base) } else { base.to_string() }
format!("{} bg-primary/10", base)
} else {
base.to_string()
}
} }
on:contextmenu={ on:contextmenu={
let t_hash = t_hash.clone(); let t_hash = t_hash.clone();
@@ -445,12 +266,11 @@ fn TorrentRow(
} }
on:click={ on:click={
let t_hash = t_hash.clone(); let t_hash = t_hash.clone();
let set_selected_hash = set_selected_hash.clone();
move |_| set_selected_hash.set(Some(t_hash.clone())) move |_| set_selected_hash.set(Some(t_hash.clone()))
} }
> >
<td class="font-medium truncate max-w-xs" title={t.name.clone()}> <td class="font-medium truncate max-w-xs" title=t_name.clone()>{t_name.clone()}</td>
{t.name.clone()}
</td>
<td class="opacity-80 font-mono text-[11px]">{format_bytes(t.size)}</td> <td class="opacity-80 font-mono text-[11px]">{format_bytes(t.size)}</td>
<td> <td>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
@@ -458,7 +278,7 @@ fn TorrentRow(
<span class="text-[10px] opacity-70">{format!("{:.1}%", t.percent_complete)}</span> <span class="text-[10px] opacity-70">{format!("{:.1}%", t.percent_complete)}</span>
</div> </div>
</td> </td>
<td class={format!("text-[11px] font-medium {}", status_class)}>{status_str}</td> <td class={format!("text-[11px] font-medium {}", status_class)}>{format!("{:?}", t.status)}</td>
<td class="text-right font-mono text-[11px] opacity-80 text-success">{format_speed(t.down_rate)}</td> <td class="text-right font-mono text-[11px] opacity-80 text-success">{format_speed(t.down_rate)}</td>
<td class="text-right font-mono text-[11px] opacity-80 text-primary">{format_speed(t.up_rate)}</td> <td class="text-right font-mono text-[11px] opacity-80 text-primary">{format_speed(t.up_rate)}</td>
<td class="text-right font-mono text-[11px] opacity-80">{format_duration(t.eta)}</td> <td class="text-right font-mono text-[11px] opacity-80">{format_duration(t.eta)}</td>
@@ -481,84 +301,43 @@ fn TorrentCard(
on_context_menu: impl Fn(web_sys::MouseEvent, String) + 'static + Clone + Send + Sync, on_context_menu: impl Fn(web_sys::MouseEvent, String) + 'static + Clone + Send + Sync,
) -> impl IntoView { ) -> impl IntoView {
let store = use_context::<crate::store::TorrentStore>().expect("store not provided"); let store = use_context::<crate::store::TorrentStore>().expect("store not provided");
let h = hash.clone(); let h = hash.clone();
let torrent = create_memo(move |_| { let torrent = Memo::new(move |_| store.torrents.with(|map| map.get(&h).cloned()));
store.torrents.with(|map| map.get(&h).cloned())
});
view! { view! {
<Show when=move || torrent.get().is_some() fallback=|| ()> <Show when=move || torrent.get().is_some() fallback=|| ()>
{ {
let hash = hash.clone(); let hash = hash.clone();
let on_context_menu = on_context_menu.clone(); let on_context_menu = on_context_menu.clone();
move || { move || {
let t = torrent.get().unwrap(); let t = torrent.get().unwrap();
let t_hash = hash.clone(); let t_hash = hash.clone();
let t_hash_class = t_hash.clone(); let t_name = t.name.clone();
let on_context_menu = on_context_menu.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 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_hash_long = t_hash.clone(); 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)| { move |pos: (i32, i32)| {
set_menu_position.set(pos); set_menu_position.set(pos);
set_selected_hash.set(Some(t_hash_long.clone())); set_selected_hash.set(Some(t_hash_long.clone()));
set_menu_visible.set(true); set_menu_visible.set(true);
let _ = window().navigator().vibrate_with_duration(50);
// 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);
}
}
}, },
600.0, 600.0,
); );
let handle_touchstart = { let selected_hash_clone = selected_hash.clone();
let start = start.clone(); let t_hash_card = t_hash.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();
view! { view! {
<div <div
class=move || { class=move || {
let base = "card card-compact bg-base-100 shadow-sm border border-base-200 transition-transform active:scale-[0.99] select-none cursor-pointer"; let base = "card card-compact bg-base-100 shadow-sm border border-base-200 select-none cursor-pointer";
if selected_hash.get() == Some(t_hash_class.clone()) { if selected_hash_clone.get() == Some(t_hash_card.clone()) { format!("{} ring-2 ring-primary ring-inset", base) } else { base.to_string() }
format!("{} ring-2 ring-primary ring-inset", base)
} else {
base.to_string()
}
} }
style="user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;"
on:contextmenu={ on:contextmenu={
let t_hash = t_hash.clone(); let t_hash = t_hash.clone();
let on_context_menu = on_context_menu.clone(); let on_context_menu = on_context_menu.clone();
@@ -566,46 +345,31 @@ fn TorrentCard(
} }
on:click={ on:click={
let t_hash = t_hash.clone(); let t_hash = t_hash.clone();
let set_selected_hash = set_selected_hash.clone();
move |_| set_selected_hash.set(Some(t_hash.clone())) move |_| set_selected_hash.set(Some(t_hash.clone()))
} }
on:touchstart=handle_touchstart on:touchstart={
on:touchmove=handle_touchmove let start = start.clone();
on:touchend=handle_touchend move |e: web_sys::TouchEvent| if let Some(touch) = e.touches().get(0) { start((touch.client_x(), touch.client_y())); }
on:touchcancel=handle_touchcancel }
> >
<div class="card-body gap-3"> <div class="card-body gap-3">
<div class="flex justify-between items-start gap-2"> <div class="flex justify-between items-start gap-2">
<h3 class="font-medium text-sm line-clamp-2 leading-tight">{t.name}</h3> <h3 class="font-medium text-sm line-clamp-2 leading-tight">{t_name.clone()}</h3>
<div class={format!("badge badge-xs text-[10px] whitespace-nowrap {}", status_badge_class)}> <div class={format!("badge badge-xs text-[10px] whitespace-nowrap {}", status_badge_class)}>{format!("{:?}", t.status)}</div>
{status_str}
</div>
</div> </div>
<div class="flex flex-col gap-1"> <div class="flex flex-col gap-1">
<div class="flex justify-between text-[10px] opacity-70"> <div class="flex justify-between text-[10px] opacity-70">
<span>{format_bytes(t.size)}</span> <span>{format_bytes(t.size)}</span>
<span>{format!("{:.1}%", t.percent_complete)}</span> <span>{format!("{:.1}%", t.percent_complete)}</span>
</div> </div>
<progress class={format!("progress w-full h-1.5 {}", progress_class)} value={t.percent_complete} max="100"></progress> <progress class="progress w-full h-1.5" value={t.percent_complete} max="100"></progress>
</div> </div>
<div class="grid grid-cols-4 gap-2 text-[10px] font-mono opacity-80 pt-1 border-t border-base-200/50"> <div class="grid grid-cols-4 gap-2 text-[10px] font-mono opacity-80 pt-1 border-t border-base-200/50">
<div class="flex flex-col"> <div class="flex flex-col text-success"><span>"DL"</span><span>{format_speed(t.down_rate)}</span></div>
<span class="text-[9px] opacity-60 uppercase">"Down"</span> <div class="flex flex-col text-primary"><span>"UP"</span><span>{format_speed(t.up_rate)}</span></div>
<span class="text-success">{format_speed(t.down_rate)}</span> <div class="flex flex-col"><span>"ETA"</span><span>{format_duration(t.eta)}</span></div>
</div> <div class="flex flex-col text-right"><span>"DATE"</span><span>{format_date(t.added_date)}</span></div>
<div class="flex flex-col text-center border-l border-r border-base-200/50">
<span class="text-[9px] opacity-60 uppercase">"Up"</span>
<span class="text-primary">{format_speed(t.up_rate)}</span>
</div>
<div class="flex flex-col text-center border-r border-base-200/50">
<span class="text-[9px] opacity-60 uppercase">"ETA"</span>
<span>{format_duration(t.eta)}</span>
</div>
<div class="flex flex-col text-right">
<span class="text-[9px] opacity-60 uppercase">"Date"</span>
<span>{format_date(t.added_date)}</span>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,9 +1,9 @@
use futures::StreamExt; use futures::StreamExt;
use gloo_net::eventsource::futures::EventSource; use gloo_net::eventsource::futures::EventSource;
use leptos::prelude::*; use leptos::prelude::*;
use leptos::logging;
use leptos::task::spawn_local;
use shared::{AppEvent, GlobalStats, NotificationLevel, SystemNotification, Torrent}; use shared::{AppEvent, GlobalStats, NotificationLevel, SystemNotification, Torrent};
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct NotificationItem { 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( pub fn show_toast_with_signal(
notifications: RwSignal<Vec<NotificationItem>>, notifications: RwSignal<Vec<NotificationItem>>,
level: NotificationLevel, level: NotificationLevel,
@@ -33,7 +30,7 @@ pub fn show_toast_with_signal(
notifications.update(|list| list.push(item)); notifications.update(|list| list.push(item));
// Auto-remove after 5 seconds // Auto-remove after 5 seconds
let _ = set_timeout( leptos::prelude::set_timeout(
move || { move || {
notifications.update(|list| list.retain(|i| i.id != id)); 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<String>) { pub fn show_toast(level: NotificationLevel, message: impl Into<String>) {
if let Some(store) = use_context::<TorrentStore>() { if let Some(store) = use_context::<TorrentStore>() {
show_toast_with_signal(store.notifications, level, message); show_toast_with_signal(store.notifications, level, message);
} }
} }
/// Convenience function for success toasts (reactive scope only) pub fn toast_success(message: impl Into<String>) { show_toast(NotificationLevel::Success, message); }
pub fn toast_success(message: impl Into<String>) { pub fn toast_error(message: impl Into<String>) { show_toast(NotificationLevel::Error, message); }
show_toast(NotificationLevel::Success, message);
}
/// Convenience function for error toasts (reactive scope only)
pub fn toast_error(message: impl Into<String>) {
show_toast(NotificationLevel::Error, message);
}
/// Convenience function for info toasts (reactive scope only)
pub fn toast_info(message: impl Into<String>) {
show_toast(NotificationLevel::Info, message);
}
/// Convenience function for warning toasts (reactive scope only)
pub fn toast_warning(message: impl Into<String>) {
show_toast(NotificationLevel::Warning, 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) { pub fn get_action_messages(action: &str) -> (&'static str, &'static str) {
match action { match action {
"start" => ("Torrent başlatıldı", "Torrent başlatılamadı"), "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)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FilterStatus { pub enum FilterStatus {
All, All, Downloading, Seeding, Completed, Paused, Inactive, Active, Error,
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)] #[derive(Clone, Copy, Debug)]
pub struct TorrentStore { pub struct TorrentStore {
pub torrents: RwSignal<HashMap<String, Torrent>>, pub torrents: RwSignal<HashMap<String, Torrent>>,
@@ -128,393 +95,104 @@ pub struct TorrentStore {
} }
pub fn provide_torrent_store() { pub fn provide_torrent_store() {
let torrents = create_rw_signal(HashMap::new()); let torrents = RwSignal::new(HashMap::new());
let filter = create_rw_signal(FilterStatus::All); let filter = RwSignal::new(FilterStatus::All);
let search_query = create_rw_signal(String::new()); let search_query = RwSignal::new(String::new());
let global_stats = create_rw_signal(GlobalStats::default()); let global_stats = RwSignal::new(GlobalStats::default());
let notifications = create_rw_signal(Vec::<NotificationItem>::new()); let notifications = RwSignal::new(Vec::<NotificationItem>::new());
let user = create_rw_signal(Option::<String>::None); let user = RwSignal::new(Option::<String>::None);
// Browser notification hook
let show_browser_notification = crate::utils::notification::use_app_notification(); let show_browser_notification = crate::utils::notification::use_app_notification();
let store = TorrentStore { let store = TorrentStore { torrents, filter, search_query, global_stats, notifications, user };
torrents,
filter,
search_query,
global_stats,
notifications,
user,
};
provide_context(store); provide_context(store);
// Initialize SSE connection with auto-reconnect // SSE Connection
create_effect(move |_| { Effect::new(move |_| {
// Sadece kullanıcı giriş yapmışsa bağlantıyı başlat if user.get().is_none() { return; }
if user.get().is_none() {
logging::log!("SSE: User not authenticated, skipping connection.");
return;
}
let show_browser_notification = show_browser_notification.clone(); let show_browser_notification = show_browser_notification.clone();
spawn_local(async move { leptos::task::spawn_local(async move {
let mut backoff_ms: u32 = 1000; // Start with 1 second let mut backoff_ms: u32 = 1000;
let max_backoff_ms: u32 = 30000; // Max 30 seconds
let mut was_connected = false; let mut was_connected = false;
let mut disconnect_notified = false; // Track if we already showed disconnect toast let mut disconnect_notified = false;
let mut got_first_message; // Only count as "connected" after receiving data
loop { loop {
let es_result = EventSource::new("/api/events"); let es_result = EventSource::new("/api/events");
match es_result { match es_result {
Ok(mut es) => { Ok(mut es) => {
match es.subscribe("message") { if let Ok(mut stream) = es.subscribe("message") {
Ok(mut stream) => { let mut got_first_message = false;
// Don't show "connected" toast yet - wait for first real message while let Some(Ok((_, msg))) = stream.next().await {
got_first_message = false; if !got_first_message {
got_first_message = true;
// Process messages backoff_ms = 1000;
while let Some(Ok((_, msg))) = stream.next().await { if was_connected && disconnect_notified {
// First successful message = truly connected show_toast_with_signal(notifications, NotificationLevel::Success, "Sunucu bağlantısı yeniden kuruldu");
if !got_first_message { disconnect_notified = false;
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;
} }
was_connected = true;
}
if let Some(data_str) = msg.data().as_string() { if let Some(data_str) = msg.data().as_string() {
if let Ok(event) = serde_json::from_str::<AppEvent>(&data_str) { if let Ok(event) = serde_json::from_str::<AppEvent>(&data_str) {
match event { match event {
AppEvent::FullList { torrents: list, .. } => { AppEvent::FullList { torrents: list, .. } => {
torrents.update(|map| { torrents.update(|map| {
// 1. Create a set of new hashes for quick lookup let new_hashes: std::collections::HashSet<String> = list.iter().map(|t| t.hash.clone()).collect();
let new_hashes: std::collections::HashSet<String> = list.iter().map(|t| t.hash.clone()).collect(); map.retain(|hash, _| new_hashes.contains(hash));
for new_torrent in list {
// 2. Remove torrents that are no longer in the list map.insert(new_torrent.hash.clone(), new_torrent);
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
);
} }
});
}
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(_) => { if was_connected && !disconnect_notified {
// Failed to subscribe - only notify once show_toast_with_signal(notifications, NotificationLevel::Warning, "Sunucu bağlantısı kesildi, yeniden bağlanılıyor...");
if was_connected && !disconnect_notified { disconnect_notified = true;
show_toast_with_signal(
notifications,
NotificationLevel::Warning,
"Sunucu bağlantısı kesildi, yeniden bağlanılıyor...",
);
disconnect_notified = true;
}
} }
} }
} }
Err(_) => { Err(_) => {
// Failed to create EventSource - only notify once
if was_connected && !disconnect_notified { if was_connected && !disconnect_notified {
show_toast_with_signal( show_toast_with_signal(notifications, NotificationLevel::Warning, "Sunucu bağlantısı kurulamıyor...");
notifications,
NotificationLevel::Warning,
"Sunucu bağlantısı kesildi, yeniden bağlanılıyor...",
);
disconnect_notified = true; disconnect_notified = true;
} }
} }
} }
// Wait before reconnecting (exponential backoff)
gloo_timers::future::TimeoutFuture::new(backoff_ms).await; 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() { 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::<web_sys::ServiceWorkerRegistration>()
.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::<web_sys::PushSubscription>()
.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<js_sys::Uint8Array, JsValue> {
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[..]))
} }

View File

@@ -1,7 +1,6 @@
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use web_sys::{Notification, NotificationOptions}; use web_sys::{Notification, NotificationOptions};
use leptos::prelude::*; use leptos::prelude::*;
use reactive_graph::traits::Get; // Signal::get() için gerekli
use leptos_use::{use_web_notification, UseWebNotificationReturn, NotificationPermission}; use leptos_use::{use_web_notification, UseWebNotificationReturn, NotificationPermission};
/// Request browser notification permission from user /// Request browser notification permission from user
@@ -80,4 +79,4 @@ pub fn show_notification_if_enabled(title: &str, body: &str) -> bool {
} }
false false
} }