fix(ui): first click on sort header sets default direction instead of toggling

This commit is contained in:
Administrator 2026-06-08 19:22:29 +02:00
parent 169817f707
commit f4b5fadc5f

View File

@ -63,10 +63,12 @@ const queueSortState = { key: 'filename', direction: 'asc' };
// History state // History state
let historyRowsData = []; let historyRowsData = [];
let historySortState = { key: 'date', direction: 'desc' }; let historySortState = { key: 'date', direction: 'desc' };
let _historySortClicked = false;
// Session-specific files for the "Files" panel (resets each session) // Session-specific files for the "Files" panel (resets each session)
let sessionFilesData = []; let sessionFilesData = [];
const recentSortState = { key: 'date', direction: 'desc' }; const recentSortState = { key: 'date', direction: 'desc' };
let _recentSortClicked = false;
const selectedRecentIds = new Set(); const selectedRecentIds = new Set();
// Maintained incrementally — avoids O(n) filter() scans every 250ms in the status bar. // Maintained incrementally — avoids O(n) filter() scans every 250ms in the status bar.
let _sessionDoneCount = 0; let _sessionDoneCount = 0;
@ -4150,8 +4152,14 @@ function renderHistoryTable(container) {
const th = e.target.closest('th.sortable'); const th = e.target.closest('th.sortable');
if (th && container.contains(th)) { if (th && container.contains(th)) {
const key = th.dataset.historySort; const key = th.dataset.historySort;
if (historySortState.key === key) historySortState.direction = historySortState.direction === 'asc' ? 'desc' : 'asc'; const defaultDir = key === 'date' ? 'desc' : 'asc';
else { historySortState.key = key; historySortState.direction = key === 'date' ? 'desc' : 'asc'; } if (!_historySortClicked || historySortState.key !== key) {
_historySortClicked = true;
historySortState.key = key;
historySortState.direction = defaultDir;
} else {
historySortState.direction = historySortState.direction === 'asc' ? 'desc' : 'asc';
}
renderHistoryTable(container); renderHistoryTable(container);
return; return;
} }
@ -4207,11 +4215,13 @@ function setupListeners() {
const th = e.target.closest('th[data-recent-sort]'); const th = e.target.closest('th[data-recent-sort]');
if (!th) return; if (!th) return;
const key = th.dataset.recentSort; const key = th.dataset.recentSort;
if (recentSortState.key === key) { const defaultDir = key === 'date' ? 'desc' : 'asc';
recentSortState.direction = recentSortState.direction === 'desc' ? 'asc' : 'desc'; if (!_recentSortClicked || recentSortState.key !== key) {
} else { _recentSortClicked = true;
recentSortState.key = key; recentSortState.key = key;
recentSortState.direction = key === 'date' ? 'desc' : 'asc'; recentSortState.direction = defaultDir;
} else {
recentSortState.direction = recentSortState.direction === 'desc' ? 'asc' : 'desc';
} }
renderRecentUploadsPanel(); renderRecentUploadsPanel();
}); });