Prefer richer price history by default

This commit is contained in:
TopherMayor
2026-05-01 12:04:14 -07:00
parent e3dfd90ecc
commit 0b6d698ba7

View File

@@ -2113,6 +2113,23 @@
return sources; return sources;
} }
function getPreferredSourceForTab(opt, tabId = activeTab) {
const sources = getAvailableSourcesForTab(opt, tabId);
if (!sources.length) return null;
return [...sources].sort((a, b) => {
const aPoints = a.pointCount || 0;
const bPoints = b.pointCount || 0;
if (aPoints !== bPoints) return bPoints - aPoints;
const aChecked = Date.parse(a.latestCheckedAt || '') || 0;
const bChecked = Date.parse(b.latestCheckedAt || '') || 0;
if (aChecked !== bChecked) return bChecked - aChecked;
return String(a.sourceLabel || '').localeCompare(String(b.sourceLabel || ''));
})[0] || null;
}
function getVisibleOptionsForTab(tabId = activeTab) { function getVisibleOptionsForTab(tabId = activeTab) {
const sourcesForTab = (opt) => getAvailableSourcesForTab(opt, tabId).length > 0; const sourcesForTab = (opt) => getAvailableSourcesForTab(opt, tabId).length > 0;
if (tabId === BUNDLE_TAB_ID) { if (tabId === BUNDLE_TAB_ID) {
@@ -2169,7 +2186,8 @@
return normalizedStored; return normalizedStored;
} }
const defaultKey = normalizeSourceKey(opt.currentSourceKey || opt.defaultSourceKey || availableSources[0]?.sourceKey); const preferredKey = getPreferredSourceForTab(opt, tabId)?.sourceKey;
const defaultKey = normalizeSourceKey(preferredKey || opt.currentSourceKey || opt.defaultSourceKey || availableSources[0]?.sourceKey);
return availableSources.some(source => source.sourceKey === defaultKey) return availableSources.some(source => source.sourceKey === defaultKey)
? defaultKey ? defaultKey
: availableSources[0]?.sourceKey || 'unknown-source'; : availableSources[0]?.sourceKey || 'unknown-source';