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