Compare commits

..

2 Commits

Author SHA1 Message Date
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
3 changed files with 45 additions and 69 deletions

View File

@@ -54,3 +54,5 @@ tailwind_fuse = "0.3.2"
js-sys = "0.3.85"
base64 = "0.22.1"
serde-wasm-bindgen = "0.6.5"
leptos-use = "0.13"
codee = "0.2"

View File

@@ -1,4 +1,6 @@
use leptos::*;
use leptos_use::storage::use_local_storage;
use codee::string::FromToStringCodec;
use shared::GlobalLimitRequest;
fn format_bytes(bytes: i64) -> String {
@@ -26,34 +28,19 @@ pub fn StatusBar() -> impl IntoView {
let store = use_context::<crate::store::TorrentStore>().expect("store not provided");
let stats = store.global_stats;
let initial_theme = if let Some(win) = web_sys::window() {
if let Some(doc) = win.document() {
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()
};
// 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) = 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 |_| {
if let Some(win) = web_sys::window() {
if let Some(storage) = win.local_storage().ok().flatten() {
if let Ok(Some(stored_theme)) = storage.get_item("vibetorrent_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);
}
}
}
let theme = current_theme.get().to_lowercase();
if let Some(doc) = document().document_element() {
let _ = doc.set_attribute("data-theme", &theme);
}
});
@@ -275,14 +262,6 @@ pub fn StatusBar() -> impl IntoView {
on:pointerdown=move |e| {
e.stop_propagation();
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();
}
>

View File

@@ -1,4 +1,5 @@
use leptos::*;
use leptos_use::use_timeout_fn;
use crate::store::{get_action_messages, show_toast_with_signal};
use shared::NotificationLevel;
@@ -421,50 +422,44 @@ pub fn TorrentTable() -> impl IntoView {
let _t_hash = 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 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 || {
if let Some(handle) = timer_handle.get_untracked() {
handle.clear();
set_timer_handle.set(None);
}
};
// 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,
);
let handle_touchstart = {
let t_hash = t_hash_long.clone();
move |e: web_sys::TouchEvent| {
clear_long_press_timer();
let start = start.clone();
move |e: web_sys::TouchEvent| {
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);
// 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));
}
start((touch.client_x(), touch.client_y()));
}
}
};
let handle_touchmove = move |_| clear_long_press_timer();
let handle_touchend = move |_| clear_long_press_timer();
let handle_touchmove = {
let stop = stop.clone();
move |_| stop()
};
let handle_touchend = {
let stop = stop.clone();
move |_| stop()
};
let handle_touchcancel = move |_| stop();
view! {
<div
@@ -483,7 +478,7 @@ pub fn TorrentTable() -> impl IntoView {
on:touchstart=handle_touchstart
on:touchmove=handle_touchmove
on:touchend=handle_touchend
on:touchcancel=handle_touchend
on:touchcancel=handle_touchcancel
>
<div class="card-body gap-3">
<div class="flex justify-between items-start gap-2">