refactor: long press mantığı leptos-use::use_timeout_fn ile modernize edildi
All checks were successful
Build MIPS Binary / build (push) Successful in 4m29s
All checks were successful
Build MIPS Binary / build (push) Successful in 4m29s
This commit is contained in:
@@ -54,3 +54,4 @@ 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"
|
||||||
|
|||||||
@@ -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,29 +422,11 @@ 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(
|
||||||
let clear_long_press_timer = move || {
|
move |pos: (i32, i32)| {
|
||||||
if let Some(handle) = timer_handle.get_untracked() {
|
set_menu_position.set(pos);
|
||||||
handle.clear();
|
set_selected_hash.set(Some(t_hash_long.clone()));
|
||||||
set_timer_handle.set(None);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let handle_touchstart = {
|
|
||||||
let t_hash = t_hash_long.clone();
|
|
||||||
move |e: web_sys::TouchEvent| {
|
|
||||||
clear_long_press_timer();
|
|
||||||
if let Some(touch) = e.touches().get(0) {
|
|
||||||
let x = touch.client_x();
|
|
||||||
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);
|
set_menu_visible.set(true);
|
||||||
|
|
||||||
// Haptic feedback
|
// Haptic feedback
|
||||||
@@ -453,18 +436,30 @@ pub fn TorrentTable() -> impl IntoView {
|
|||||||
let _ = navigator.vibrate_with_duration(50);
|
let _ = navigator.vibrate_with_duration(50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_timer_handle.set(None);
|
},
|
||||||
}, std::time::Duration::from_millis(600));
|
600.0,
|
||||||
|
);
|
||||||
|
|
||||||
if let Ok(h) = handle {
|
let handle_touchstart = {
|
||||||
set_timer_handle.set(Some(h));
|
let start = start.clone();
|
||||||
}
|
move |e: web_sys::TouchEvent| {
|
||||||
|
if let Some(touch) = e.touches().get(0) {
|
||||||
|
start((touch.client_x(), touch.client_y()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let handle_touchmove = 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">
|
||||||
|
|||||||
Reference in New Issue
Block a user