Implement reactive sorting for IDAA Archives

- Forced priority archives to the top of the list.
- Implemented descending (DESC) sort by the 'sort' field within groups.
- Added a sort selector to the archive list component.
- Centralized sorting logic in-memory within LiveQuery for immediate reactivity.
This commit is contained in:
Scott Idem
2026-02-08 18:12:54 -05:00
parent 84cfed97ca
commit f84d6b638d
2 changed files with 58 additions and 11 deletions

View File

@@ -44,17 +44,26 @@
let lq__archive_obj_li = $derived(
liveQuery(async () => {
let results = await db_archives.archive
const results = await db_archives.archive
.where('account_id')
.equals($slct.account_id)
// .orderBy('updated_on')
// .toArray()
// .reverse() // Removed reverse: sortBy('sort') already provides the correct 1, 2, 3... order
.sortBy('sort');
// .sortBy('updated_on');
// .sortBy('updated_on, created_on');
// .sortBy('[updated_on+created_on]');
// .sortBy('[created_on+updated_on]');
.toArray();
// In-memory sort: Priority (desc) then Sort (desc)
results.sort((a, b) => {
// Priority: True (1) before False (0)
const prioA = a.priority ? 1 : 0;
const prioB = b.priority ? 1 : 0;
if (prioA !== prioB) return prioB - prioA;
// Sort: 9, 8, 7...
const sortA = a.sort ?? 0;
const sortB = b.sort ?? 0;
if (sortA !== sortB) return sortB - sortA;
// Fallback: Name
return (a.name ?? '').localeCompare(b.name ?? '');
});
return results;
})