Add progress/recently-added sort to Library browser

The sort dropdown only had Name (A-Z/Z-A) - no way to surface "what
did I just download" or "what am I closest to finishing" without
scrolling. Adds Progress and Recently Added, backed by each course's
completion_percentage and folder mtime (already/newly attached in
list_library_directory and search_library_courses). Folders have
neither, so they naturally sort to the end under these two modes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-26 10:58:01 -04:00
co-authored by Claude Sonnet 5
parent bf0a02d008
commit 47e7214bd7
5 changed files with 27 additions and 5 deletions
+15 -3
View File
@@ -1243,6 +1243,8 @@
<select id="library-sort" class="library-sort-select" onchange="reapplySort()">
<option value="name-asc">Name (A→Z)</option>
<option value="name-desc">Name (Z→A)</option>
<option value="progress">Progress</option>
<option value="recently-added">Recently Added</option>
</select>
<div class="library-view-toggle">
<button type="button" class="view-toggle-btn" id="library-view-list-btn"
@@ -1889,9 +1891,19 @@
function sortLibraryItems(items) {
const order = document.getElementById('library-sort').value;
const sorted = items.slice();
sorted.sort((a, b) => order === 'name-desc'
? b.name.localeCompare(a.name)
: a.name.localeCompare(b.name));
// Directories have neither a completion_percentage nor an
// mtime (only courses do), so they naturally fall to the end
// under these two modes rather than needing separate grouping
// logic - falling back to name order among themselves/ties.
if (order === 'progress') {
sorted.sort((a, b) => (b.completion_percentage || 0) - (a.completion_percentage || 0) || a.name.localeCompare(b.name));
} else if (order === 'recently-added') {
sorted.sort((a, b) => (b.mtime || 0) - (a.mtime || 0) || a.name.localeCompare(b.name));
} else {
sorted.sort((a, b) => order === 'name-desc'
? b.name.localeCompare(a.name)
: a.name.localeCompare(b.name));
}
return sorted;
}