fix(badges): apply print_count-first sort to all three badge display paths

The default sort (unprinted first, then name) was only wired into the API
order_by_li. Two IDB-local paths were left behind:

1. SCENARIO 2 fallback (no active filters, no text query): used Dexie
   .sortBy('given_name') — bypassed entirely on initial page load.
   Fixed: fetch .toArray() then JS-sort by print_count ASC → given_name ASC.

2. Fast-path IDB sort default case: also sorted by given_name only, causing
   a visible flash of name-ordered results before the API response landed.
   Fixed: same print_count ASC → given_name ASC comparator.

All three paths (API, fast-path IDB, fallback IDB) now agree on sort order.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Scott Idem
2026-06-09 09:13:47 -04:00
parent 6e04145514
commit 3122725610

View File

@@ -139,11 +139,17 @@ let lq__event_badge_obj_li = $derived.by(() => {
console.log(
`Badge Page LQ: Fallback search for event: ${event_id}`
);
return await db_events.badge
// Dexie sortBy supports only one field; sort by print_count then name in JS.
const fallback_results = await db_events.badge
.where('event_id')
.equals(event_id)
.limit(fallback_limit)
.sortBy('given_name');
.toArray();
fallback_results.sort((a, b) =>
(a.print_count ?? 0) - (b.print_count ?? 0) ||
(a.given_name ?? '').localeCompare(b.given_name ?? '')
);
return fallback_results;
}
return [];
@@ -366,8 +372,10 @@ async function handle_search_refresh(params: any) {
)
);
default:
return (a.given_name ?? '').localeCompare(
b.given_name ?? ''
// Matches the API default: unprinted first, then alphabetical.
return (
(a.print_count ?? 0) - (b.print_count ?? 0) ||
(a.given_name ?? '').localeCompare(b.given_name ?? '')
);
}
});