Compare commits

..

6 Commits

Author SHA1 Message Date
spinline
851d79029a feat(ui): add mobile long-press support for context menus
All checks were successful
Build MIPS Binary / build (push) Successful in 1m58s
2026-02-21 01:46:21 +03:00
spinline
ab27cf3eb4 fix: use f.priority.set instead of deprecated f.set_priority for rTorrent API
All checks were successful
Build MIPS Binary / build (push) Successful in 2m0s
2026-02-21 01:42:07 +03:00
spinline
7b4c9ff336 fix(files): trigger refetch only after set_priority completes on server
All checks were successful
Build MIPS Binary / build (push) Successful in 2m1s
2026-02-21 01:36:21 +03:00
spinline
743596d701 fix(ci): remove tracing calls that caused compile error in shared crate
All checks were successful
Build MIPS Binary / build (push) Successful in 1m58s
2026-02-21 01:31:25 +03:00
spinline
598f038ea6 fix(files): use refetch callback instead of Action to avoid reactive disposal panic
Some checks failed
Build MIPS Binary / build (push) Failing after 1m10s
2026-02-21 01:29:26 +03:00
spinline
7f8c721115 debug: add tracing logs to set_file_priority for diagnosis
Some checks failed
Build MIPS Binary / build (push) Failing after 1m10s
2026-02-21 01:27:22 +03:00
3 changed files with 64 additions and 23 deletions

View File

@@ -15,10 +15,9 @@ pub fn TorrentFilesTab(hash: String) -> impl IntoView {
|h| async move { shared::server_fns::torrent::get_files(h).await.unwrap_or_default() }
);
// Refresh action
let refresh_files = Action::new(|h: &String| {
let h = h.clone();
async move { shared::server_fns::torrent::get_files(h).await.unwrap_or_default() }
// Callback to trigger a refetch — safe, doesn't destroy existing components
let on_refresh = Callback::new(move |_: ()| {
files_resource.refetch();
});
let stored_hash = StoredValue::new(hash);
@@ -26,10 +25,7 @@ pub fn TorrentFilesTab(hash: String) -> impl IntoView {
view! {
<Suspense fallback=move || view! { <FilesFallback /> }>
{move || {
let files = match refresh_files.value().get() {
Some(f) => f,
None => files_resource.get().unwrap_or_default(),
};
let files = files_resource.get().unwrap_or_default();
if files.is_empty() {
return view! {
@@ -61,12 +57,11 @@ pub fn TorrentFilesTab(hash: String) -> impl IntoView {
key=|f| f.index
children={move |f| {
let p_hash = stored_hash.get_value();
let r_files = refresh_files.clone();
view! {
<FileRow
file=f
hash=p_hash
refresh_action=r_files
on_refresh=on_refresh.clone()
/>
}
}}
@@ -86,11 +81,14 @@ pub fn TorrentFilesTab(hash: String) -> impl IntoView {
}
#[component]
fn FileRow(file: TorrentFile, hash: String, refresh_action: Action<String, Vec<TorrentFile>>) -> impl IntoView {
fn FileRow(file: TorrentFile, hash: String, on_refresh: Callback<()>) -> impl IntoView {
let f_idx = file.index;
let path_clone = file.path.clone();
let set_priority = Action::new(|req: &(String, u32, u8)| {
// on_refresh is called AFTER the server responds, not before
let on_refresh_stored = StoredValue::new(on_refresh);
let set_priority = Action::new(move |req: &(String, u32, u8)| {
let (h, idx, p) = req.clone();
async move {
let res = shared::server_fns::torrent::set_file_priority(h, idx, p).await;
@@ -98,6 +96,8 @@ fn FileRow(file: TorrentFile, hash: String, refresh_action: Action<String, Vec<T
crate::store::show_toast(shared::NotificationLevel::Error, format!("Öncelik değiştirilemedi: {:?}", e));
} else {
crate::store::show_toast(shared::NotificationLevel::Success, "Dosya önceliği güncellendi.".to_string());
// Refetch AFTER the server has saved the priority
on_refresh_stored.get_value().run(());
}
res
}
@@ -107,7 +107,6 @@ fn FileRow(file: TorrentFile, hash: String, refresh_action: Action<String, Vec<T
<FileContextMenu
torrent_hash=hash
file_index=f_idx
refresh_action=refresh_action
set_priority=set_priority
>
<TableRow class="hover:bg-muted/50 transition-colors group">
@@ -141,7 +140,6 @@ fn FileContextMenu(
children: Children,
torrent_hash: String,
file_index: u32,
refresh_action: Action<String, Vec<TorrentFile>>,
set_priority: Action<(String, u32, u8), Result<(), ServerFnError>>,
) -> impl IntoView {
let hash_c1 = torrent_hash.clone();
@@ -159,11 +157,9 @@ fn FileContextMenu(
<ContextMenuGroup>
<ContextMenuItem on:click={
let h = hash_c1;
let ra = refresh_action.clone();
let sp = set_priority.clone();
move |_| {
sp.dispatch((h.clone(), file_index, 2));
ra.dispatch(h.clone());
crate::components::ui::context_menu::close_context_menu();
}
}>
@@ -173,11 +169,9 @@ fn FileContextMenu(
<ContextMenuItem on:click={
let h = hash_c2;
let ra = refresh_action.clone();
let sp = set_priority.clone();
move |_| {
sp.dispatch((h.clone(), file_index, 1));
ra.dispatch(h.clone());
crate::components::ui::context_menu::close_context_menu();
}
}>
@@ -187,11 +181,9 @@ fn FileContextMenu(
<ContextMenuItem class="text-destructive focus:bg-destructive/10" on:click={
let h = hash_c3;
let ra = refresh_action.clone();
let sp = set_priority.clone();
move |_| {
sp.dispatch((h.clone(), file_index, 0));
ra.dispatch(h.clone());
crate::components::ui::context_menu::close_context_menu();
}
}>

View File

@@ -296,7 +296,7 @@ pub fn ContextMenuContent(
}}
}};
// Right-click on trigger
// Right-click on trigger (desktop)
trigger.addEventListener('contextmenu', (e) => {{
e.preventDefault();
e.stopPropagation();
@@ -307,6 +307,53 @@ pub fn ContextMenuContent(
openMenu(e.clientX, e.clientY);
}});
// Long-press on trigger (mobile)
let touchTimer = null;
let touchStartX = 0;
let touchStartY = 0;
const LONG_PRESS_DURATION = 500;
const MOVE_THRESHOLD = 10;
trigger.addEventListener('touchstart', (e) => {{
const touch = e.touches[0];
touchStartX = touch.clientX;
touchStartY = touch.clientY;
touchTimer = setTimeout(() => {{
e.preventDefault();
if (isOpen) {{
closeMenu();
}}
openMenu(touchStartX, touchStartY);
}}, LONG_PRESS_DURATION);
}}, {{ passive: false }});
trigger.addEventListener('touchmove', (e) => {{
if (touchTimer) {{
const touch = e.touches[0];
const dx = Math.abs(touch.clientX - touchStartX);
const dy = Math.abs(touch.clientY - touchStartY);
if (dx > MOVE_THRESHOLD || dy > MOVE_THRESHOLD) {{
clearTimeout(touchTimer);
touchTimer = null;
}}
}}
}});
trigger.addEventListener('touchend', () => {{
if (touchTimer) {{
clearTimeout(touchTimer);
touchTimer = null;
}}
}});
trigger.addEventListener('touchcancel', () => {{
if (touchTimer) {{
clearTimeout(touchTimer);
touchTimer = null;
}}
}});
// Close when action is clicked
const actions = menu.querySelectorAll('[data-context-close]');
actions.forEach(action => {{

View File

@@ -225,6 +225,7 @@ pub async fn set_file_priority(
let ctx = expect_context::<crate::ServerContext>();
let client = RtorrentClient::new(&ctx.scgi_socket_path);
// rTorrent f.set_priority takes: target = "HASH:fINDEX", value = priority
let target = format!("{}:f{}", hash, file_index);
let params = vec![
RpcParam::from(target.as_str()),
@@ -232,10 +233,11 @@ pub async fn set_file_priority(
];
client
.call("f.set_priority", &params)
.call("f.priority.set", &params)
.await
.map_err(|e| ServerFnError::new(format!("RPC error: {}", e)))?;
.map_err(|e| ServerFnError::new(format!("RPC error setting priority: {}", e)))?;
// Notify rTorrent to update its internal priority state
let _ = client
.call("d.update_priorities", &[RpcParam::from(hash.as_str())])
.await;