Compare commits

..

1 Commits

Author SHA1 Message Date
spinline
c34133ded1 refactor: manuel Closure ve timer yönetimi Leptos set_timeout ile değiştirildi
All checks were successful
Build MIPS Binary / build (push) Successful in 4m16s
2026-02-08 19:39:38 +03:00

View File

@@ -1,6 +1,4 @@
use leptos::*; use leptos::*;
use wasm_bindgen::closure::Closure;
use wasm_bindgen::JsCast;
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;
@@ -423,57 +421,50 @@ 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_id, set_timer_id) = create_signal(Option::<i32>::None); 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 clear_timer = move || { let clear_long_press_timer = move || {
if let Some(id) = timer_id.get_untracked() { if let Some(handle) = timer_handle.get_untracked() {
window().clear_timeout_with_handle(id); handle.clear();
set_timer_id.set(None); set_timer_handle.set(None);
} }
}; };
let handle_touchstart = { let handle_touchstart = {
let t_hash = t_hash_long.clone(); let t_hash = t_hash_long.clone();
move |e: web_sys::TouchEvent| { move |e: web_sys::TouchEvent| {
clear_timer(); 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(); let x = touch.client_x();
let y = touch.client_y(); let y = touch.client_y();
let hash = t_hash.clone(); let hash = t_hash.clone();
let closure = Closure::wrap(Box::new(move || { // Use Leptos set_timeout: cleaner, safer, no manual Closure needed
let handle = set_timeout_with_handle(move || {
set_menu_position.set((x, y)); set_menu_position.set((x, y));
set_selected_hash.set(Some(hash.clone())); set_selected_hash.set(Some(hash.clone()));
set_menu_visible.set(true); set_menu_visible.set(true);
// Haptic feedback (iOS Safari doesn't support vibrate) // Haptic feedback
let navigator = window().navigator(); let navigator = window().navigator();
if js_sys::Reflect::has(&navigator, &wasm_bindgen::JsValue::from_str("vibrate")).unwrap_or(false) { if let Ok(vibrate) = js_sys::Reflect::get(&navigator, &"vibrate".into()) {
if vibrate.is_function() {
let _ = navigator.vibrate_with_duration(50); let _ = navigator.vibrate_with_duration(50);
} }
}) as Box<dyn Fn()>); }
set_timer_handle.set(None);
}, std::time::Duration::from_millis(600));
let id = window() if let Ok(h) = handle {
.set_timeout_with_callback_and_timeout_and_arguments_0( set_timer_handle.set(Some(h));
closure.as_ref().unchecked_ref(), }
600
)
.unwrap_or(0);
closure.forget();
set_timer_id.set(Some(id));
} }
} }
}; };
let handle_touchmove = move |_| { let handle_touchmove = move |_| clear_long_press_timer();
clear_timer(); let handle_touchend = move |_| clear_long_press_timer();
};
let handle_touchend = move |_| {
clear_timer();
};
view! { view! {
<div <div