Fix board date sorting on downloads page#1761
Merged
makermelissa merged 2 commits intoadafruit:mainfrom Apr 21, 2026
Merged
Conversation
The sort comparator had several issues causing date sorting to produce unexpected results: 1. Exact tag match promotion ran before the sort type switch for all sort modes, overriding date and alphabetical sorts. Tag match promotion now only applies to the default (downloads) sort. 2. The tag match only checked item 'a' and returned -2, not comparing 'b'. Both items are now compared symmetrically. 3. Date and download count comparators used ternary conditional returns instead of subtraction, never returning 0 for equal values. Changed to use arithmetic subtraction for proper three-way comparison. 4. The filterResults tag-match DOM reordering also ignored the current sort selection. Now respects the active sort choice. Fixes adafruit#1760
Boards without a valid date_added value now sort to the end of the list for both date-asc and date-desc sort modes, instead of appearing in unpredictable positions due to NaN comparisons.
Collaborator
|
Tested locally and it is behaving as expected. Actually, a bit better because new boards are now at the end of the list. |
makermelissa
approved these changes
Apr 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Sorting boards on the downloads page by date (newest/oldest first) produces unexpected results, as reported in #1760.
Root Cause
The sort comparator in
downloads.jshad several issues:Tag match overrides all sort modes: The exact tag match promotion (
return -2) ran before the sort-type switch statement for all sort modes, so when a search term was active, matching boards were always pushed to the top — even when the user explicitly selected date or alphabetical sorting.Asymmetric tag comparison: Only item
awas checked for tag match; itembwas never tested. This made the comparator inconsistent (violating the sort contract wherecompare(a,b)andcompare(b,a)should be symmetric).Missing equality case in comparators: The date and download-count comparators used ternary returns (
< ? -1 : 1) instead of subtraction, so they never returned0for equal values. This produced unstable sort results for boards sharing the same date or download count.filterResults also ignores sort selection: The
filterResultsfunction prepends tag-matched boards to the DOM regardless of the currently selected sort, undoing an explicit date or alphabetical sort whenever filtering re-runs.Fix
downloads(the default)aandbare checked for tag matches symmetricallyfilterResultschecks the active sort radio before doing tag-match reorderingTesting