Compare commits

...

3 Commits

Author SHA1 Message Date
spinline
a08fd9698f refactor: açılır menüler leptos-use::on_click_outside ile modernize edildi, şeffaf backdrop katmanları kaldırıldı
All checks were successful
Build MIPS Binary / build (push) Successful in 5m52s
2026-02-08 20:16:05 +03:00
spinline
7d46dbd437 refactor: tema yönetimi leptos-use::use_local_storage ile reaktif hale getirildi
All checks were successful
Build MIPS Binary / build (push) Successful in 4m28s
2026-02-08 20:02:01 +03:00
spinline
5f107299e3 refactor: long press mantığı leptos-use::use_timeout_fn ile modernize edildi
All checks were successful
Build MIPS Binary / build (push) Successful in 4m29s
2026-02-08 19:53:10 +03:00
4 changed files with 64 additions and 89 deletions

View File

@@ -54,3 +54,5 @@ 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.13"
codee = "0.2"

View File

@@ -1,4 +1,5 @@
use leptos::*; use leptos::*;
use leptos_use::on_click_outside;
#[component] #[component]
pub fn ContextMenu( pub fn ContextMenu(
@@ -8,6 +9,10 @@ pub fn ContextMenu(
on_close: Callback<()>, on_close: Callback<()>,
on_action: Callback<(String, String)>, // (Action, Hash) on_action: Callback<(String, String)>, // (Action, Hash)
) -> impl IntoView { ) -> impl IntoView {
let container_ref = create_node_ref::<html::Div>();
let _ = on_click_outside(container_ref, move |_| on_close.call(()));
let handle_action = move |action: &str| { let handle_action = move |action: &str| {
let hash = torrent_hash.clone(); let hash = torrent_hash.clone();
let action_str = action.to_string(); let action_str = action.to_string();
@@ -22,16 +27,8 @@ pub fn ContextMenu(
} }
view! { view! {
// Backdrop to catch clicks outside
<div
class="fixed inset-0 z-[99] cursor-default"
role="button"
tabindex="-1"
on:click=move |_| on_close.call(())
on:contextmenu=move |e| e.prevent_default()
></div>
<div <div
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", position.0, position.1)
on:contextmenu=move |e| e.prevent_default() on:contextmenu=move |e| e.prevent_default()

View File

@@ -1,4 +1,7 @@
use leptos::*; use leptos::*;
use leptos_use::on_click_outside;
use leptos_use::storage::use_local_storage;
use codee::string::FromToStringCodec;
use shared::GlobalLimitRequest; use shared::GlobalLimitRequest;
fn format_bytes(bytes: i64) -> String { fn format_bytes(bytes: i64) -> String {
@@ -26,34 +29,19 @@ 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;
let initial_theme = if let Some(win) = web_sys::window() { // Use leptos-use for reactive localStorage management
if let Some(doc) = win.document() { let (current_theme, set_current_theme, _) = use_local_storage::<String, FromToStringCodec>("vibetorrent_theme");
doc.document_element()
.and_then(|el| el.get_attribute("data-theme"))
.unwrap_or_else(|| "dark".to_string())
} else {
"dark".to_string()
}
} else {
"dark".to_string()
};
let (current_theme, set_current_theme) = create_signal(initial_theme); // Initialize with default if empty
if current_theme.get_untracked().is_empty() {
set_current_theme.set("dark".to_string());
}
// Automatically sync theme to document attribute
create_effect(move |_| { create_effect(move |_| {
if let Some(win) = web_sys::window() { let theme = current_theme.get().to_lowercase();
if let Some(storage) = win.local_storage().ok().flatten() { if let Some(doc) = document().document_element() {
if let Ok(Some(stored_theme)) = storage.get_item("vibetorrent_theme") { let _ = doc.set_attribute("data-theme", &theme);
let theme = stored_theme.to_lowercase();
set_current_theme.set(theme.clone());
if let Some(doc) = win.document() {
let _ = doc
.document_element()
.unwrap()
.set_attribute("data-theme", &theme);
}
}
}
} }
}); });
@@ -127,19 +115,20 @@ pub fn StatusBar() -> impl IntoView {
set_active_dropdown.set(0); set_active_dropdown.set(0);
}; };
view! { // Refs for click outside detection
// Transparent overlay to close dropdowns when clicking outside let down_ref = create_node_ref::<html::Div>();
<Show when=move || active_dropdown.get() != 0> let up_ref = create_node_ref::<html::Div>();
<div let theme_ref = create_node_ref::<html::Div>();
class="fixed inset-0 z-[98] cursor-default"
on:pointerdown=move |_| close_all()
></div>
</Show>
let _ = on_click_outside(down_ref, move |_| if active_dropdown.get_untracked() == 1 { close_all() });
let _ = on_click_outside(up_ref, move |_| if active_dropdown.get_untracked() == 2 { close_all() });
let _ = on_click_outside(theme_ref, move |_| if active_dropdown.get_untracked() == 3 { close_all() });
view! {
<div class="fixed bottom-0 left-0 right-0 h-8 min-h-8 bg-base-200 border-t border-base-300 flex items-center px-4 text-xs gap-4 text-base-content/70 z-[99]"> <div class="fixed bottom-0 left-0 right-0 h-8 min-h-8 bg-base-200 border-t border-base-300 flex items-center px-4 text-xs gap-4 text-base-content/70 z-[99]">
// --- DOWNLOAD SPEED DROPDOWN --- // --- DOWNLOAD SPEED DROPDOWN ---
<div class="relative"> <div class="relative" node_ref=down_ref>
<div <div
class="flex items-center gap-2 cursor-pointer hover:text-primary transition-colors select-none" class="flex items-center gap-2 cursor-pointer hover:text-primary transition-colors select-none"
title="Global Download Speed - Click to Set Limit" title="Global Download Speed - Click to Set Limit"
@@ -192,7 +181,7 @@ pub fn StatusBar() -> impl IntoView {
</div> </div>
// --- UPLOAD SPEED DROPDOWN --- // --- UPLOAD SPEED DROPDOWN ---
<div class="relative"> <div class="relative" node_ref=up_ref>
<div <div
class="flex items-center gap-2 cursor-pointer hover:text-primary transition-colors select-none" class="flex items-center gap-2 cursor-pointer hover:text-primary transition-colors select-none"
title="Global Upload Speed - Click to Set Limit" title="Global Upload Speed - Click to Set Limit"
@@ -245,7 +234,7 @@ pub fn StatusBar() -> impl IntoView {
</div> </div>
<div class="ml-auto flex items-center gap-4"> <div class="ml-auto flex items-center gap-4">
<div class="relative"> <div class="relative" node_ref=theme_ref>
<div <div
class="btn btn-ghost btn-xs btn-square" class="btn btn-ghost btn-xs btn-square"
title="Change Theme" title="Change Theme"
@@ -275,14 +264,6 @@ pub fn StatusBar() -> impl IntoView {
on:pointerdown=move |e| { on:pointerdown=move |e| {
e.stop_propagation(); e.stop_propagation();
set_current_theme.set(theme.to_string()); set_current_theme.set(theme.to_string());
if let Some(win) = web_sys::window() {
if let Some(doc) = win.document() {
let _ = doc.document_element().unwrap().set_attribute("data-theme", theme);
}
if let Some(storage) = win.local_storage().ok().flatten() {
let _ = storage.set_item("vibetorrent_theme", theme);
}
}
close_all(); close_all();
} }
> >

View File

@@ -1,4 +1,5 @@
use leptos::*; use leptos::*;
use leptos_use::use_timeout_fn;
use crate::store::{get_action_messages, show_toast_with_signal}; use crate::store::{get_action_messages, show_toast_with_signal};
use shared::NotificationLevel; use shared::NotificationLevel;
@@ -421,50 +422,44 @@ pub fn TorrentTable() -> impl IntoView {
let _t_hash = t.hash.clone(); let _t_hash = t.hash.clone();
let t_hash_click = t.hash.clone(); let t_hash_click = t.hash.clone();
let (timer_handle, set_timer_handle) = create_signal(Option::<leptos::leptos_dom::helpers::TimeoutHandle>::None);
let t_hash_long = t.hash.clone(); let t_hash_long = t.hash.clone();
let leptos_use::UseTimeoutFnReturn { start, stop, .. } = use_timeout_fn(
move |pos: (i32, i32)| {
set_menu_position.set(pos);
set_selected_hash.set(Some(t_hash_long.clone()));
set_menu_visible.set(true);
let clear_long_press_timer = move || { // Haptic feedback
if let Some(handle) = timer_handle.get_untracked() { let navigator = window().navigator();
handle.clear(); if let Ok(vibrate) = js_sys::Reflect::get(&navigator, &"vibrate".into()) {
set_timer_handle.set(None); if vibrate.is_function() {
} let _ = navigator.vibrate_with_duration(50);
}; }
}
},
600.0,
);
let handle_touchstart = { let handle_touchstart = {
let t_hash = t_hash_long.clone(); let start = start.clone();
move |e: web_sys::TouchEvent| { move |e: web_sys::TouchEvent| {
clear_long_press_timer();
if let Some(touch) = e.touches().get(0) { if let Some(touch) = e.touches().get(0) {
let x = touch.client_x(); start((touch.client_x(), touch.client_y()));
let y = touch.client_y();
let hash = t_hash.clone();
// Use Leptos set_timeout: cleaner, safer, no manual Closure needed
let handle = set_timeout_with_handle(move || {
set_menu_position.set((x, y));
set_selected_hash.set(Some(hash.clone()));
set_menu_visible.set(true);
// Haptic feedback
let navigator = window().navigator();
if let Ok(vibrate) = js_sys::Reflect::get(&navigator, &"vibrate".into()) {
if vibrate.is_function() {
let _ = navigator.vibrate_with_duration(50);
}
}
set_timer_handle.set(None);
}, std::time::Duration::from_millis(600));
if let Ok(h) = handle {
set_timer_handle.set(Some(h));
}
} }
} }
}; };
let handle_touchmove = move |_| clear_long_press_timer(); let handle_touchmove = {
let handle_touchend = move |_| clear_long_press_timer(); let stop = stop.clone();
move |_| stop()
};
let handle_touchend = {
let stop = stop.clone();
move |_| stop()
};
let handle_touchcancel = move |_| stop();
view! { view! {
<div <div
@@ -483,7 +478,7 @@ pub fn TorrentTable() -> impl IntoView {
on:touchstart=handle_touchstart on:touchstart=handle_touchstart
on:touchmove=handle_touchmove on:touchmove=handle_touchmove
on:touchend=handle_touchend on:touchend=handle_touchend
on:touchcancel=handle_touchend 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">