Skip to content

mobile: reevaluate sort order dynamically on fetch with rank-change visual feedback - #3570

Open
jakobbg wants to merge 3 commits into
Novik:masterfrom
jakobbg:mobile-dynamic-sort
Open

jakobbg wants to merge 3 commits into
Novik:masterfrom
jakobbg:mobile-dynamic-sort

Conversation

@jakobbg

@jakobbg jakobbg commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Summary

In mobile view, when sorting by attributes such as upload speed (-ul), download speed (-dl), size, ratio, or seeding time, the order was only evaluated once during initial list creation. Subsequent periodic poll updates (plugin.processTorrents) updated row speeds, metrics, and progress bars in-place without re-sorting the DOM table rows. As a result, when a torrent's speed or status changed significantly, its position in the list remained static.

This PR reevaluates the user-specified sort order on every polling cycle, updates the DOM order when ranks shift, and provides subtle, non-intrusive visual feedback.

Changes

  • Dynamic sort reevaluation on poll updates:

    • plugin.processTorrents: Reevaluates sort order against torrentArray on every poll cycle.
    • Compares the current tbody DOM ordering with the new sort order. When order changes, plugin.reorderRows reorders the table rows using modern Element.prototype.moveBefore (when available) or appendChild.
    • Normalizes numeric sort properties (ul, dl, size, ratio, eta, etc.) with parseFloat / Number to prevent string-comparison ordering bugs.
    • Implements deterministic multi-tier tie-breaking (primary sort -> secondary by name -> tertiary by hash) so rows do not fluctuate when speeds match.
  • Graceful rank-change visual feedback:

    • When rows change rank in the active view, a subtle accent-color inset pulse (.rank-highlight) is applied to shifted rows for 1.5 seconds.
    • Layered directly on top of Bootstrap's underlying table striping (var(--bs-table-bg-state, var(--bs-table-bg-type, var(--bs-table-accent-bg))), ensuring the highlight fades smoothly into each line's alternating background color with zero post-fade color jump.
    • Avoids layout shifts, FLIP translateY transforms, or sliding row animations that disrupt touch targets mid-tap on mobile touchscreens.
    • Suppresses highlights on initial paint (rowsPrimed = false) so startup remains clean.
    • Fully respects prefers-reduced-motion: reduce via declarative CSS media query.
  • Accessibility:

    • Added an aria-live announcement region (<div id="sortLiveStatus" role="status" class="visually-hidden">) in mobile.html and updated plugin.setSort to announce sort field and direction changes to screen readers.
  • Tests:

    • Added unit test suite in tests/plugins/mobile/sort.spec.js covering numeric sort ordering, deterministic tie-breaking, DOM reordering on speed changes, rank-shift tracking, initial render suppression, and moveBefore DOM reordering.
    • All 86 test suites pass (1036/1036 tests), and ESLint reports 0 errors.

Testing

  • Tested on FreeBSD 15.1-RELEASE-p7 with 100+ Linux torrents running simultaneously under active upload and download churn. Row reordering is smooth, responsive, and visual rank changes are clear and seamless.

Note: This pull request was prepared with AI assistance.

In mobile view, the sort order was only applied during initial paint or
when explicitly chosen from the sort dialog. On subsequent polling cycles
from the engine, changes in upload/download speeds, completion percentage,
or other sort metrics did not reorder existing DOM rows, leaving the list
in a stale order until an explicit sort or reload occurred.

Reevaluate the DOM row order in processTorrents after receiving updated
torrent data. When row placement differs from the active sort order,
reorder existing rows via reorderRows using moveBefore and appendChild to
preserve DOM element identity and focus.

Animate the reordering so torrents visually flow up or down into their
new positions using the View Transitions API (document-level and scoped
transitions) with unique per-row view-transition-names. Provide a FLIP
(First, Last, Invert, Play) transform fallback for browsers without View
Transitions support. Skip animations when prefers-reduced-motion is active
or for lists exceeding 200 items.

Normalize numeric sort comparison in dynamicSort to avoid string-ordering
and falsy-zero comparison bugs, with deterministic secondary (name) and
tertiary (hash) tie-breaking. Announce sort changes to assistive technology
through a visually hidden role="status" live region.

Includes unit test coverage for dynamicSort, live DOM reordering, View
Transitions, FLIP fallbacks, and motion preferences.

Assisted-by: AI (Google DeepMind / Antigravity)
Implement Option A: graceful, minimal visual feedback for dynamically
reordered torrents in the mobile interface.

- Replace table-row View Transitions and transform-based FLIP with a
  subtle accent-color inset pulse animation (rank-highlight).
- Apply .rank-highlight to table cells when a torrent changes rank in
  active view during background poll cycles; automatically cleans up
  after 1.5 seconds.
- Respect prefers-reduced-motion via declarative media query.
- Maintain DOM stability without shifting touch targets mid-tap.
- Update mobile sort unit tests to verify rank tracking and pulse
  lifecycle.
Preserve Bootstrap's underlying table striping layer in the rank-change
and added-torrent highlight box-shadows.

Previously, @Keyframes rank-highlight and added-highlight set a single
inset box-shadow, overwriting Bootstrap's table-striped shadow during the
animation and causing odd rows to fade into the plain background before
abruptly snapping back to the striped color when the highlight class was
removed. Layering the accent highlight on top of the table's active/type
background state allows the highlight to fade smoothly into the correct
alternating background color for every line with zero post-fade color jump.
Copilot AI balanced review requested due to automatic review settings November 22, 2026 16:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@xirvik
xirvik self-requested a review November 22, 2026 22:35

@xirvik xirvik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one needs some polishing

  • The whole list flashes. A row counts as "moved" when its position number changes, so one torrent jumping to the top flashes all 300 rows.
  • Cost per update: on desktop at 300 rows with 10% of torrents changing, about 7 ms on master against 53–88 ms on the PR. At 2000 rows, 99 ms against 405 ms. Phones will be slower.
  • Rows move under your finger while you're scrolled into the list, so a tap can hit the wrong torrent.
  • Some tests can't fail, and name sorting quietly changes from numeric-aware ("2 x" before "10 x") to plain text order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants