fix(pres_mgmt): sort presentations by priority > sort > start_datetime > code > name
Replaced single-field sortBy('name') with toArray() + JS comparator to
implement the full desired sort chain. Dexie's sortBy() only supports a
single indexed field, so multi-field ordering requires a JS sort pass.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -67,16 +67,40 @@ let lq__event_session_obj = $derived(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// 2. Presentation List Observable
|
// 2. Presentation List Observable
|
||||||
|
// WHY: Dexie sortBy() is single-field only. Multi-field sort requires toArray() + JS comparator.
|
||||||
|
// Desired order: priority DESC → sort ASC → start_datetime ASC → code ASC → name ASC
|
||||||
let lq__event_presentation_obj_li = $derived(
|
let lq__event_presentation_obj_li = $derived(
|
||||||
liveQuery(async () => {
|
liveQuery(async () => {
|
||||||
if (log_lvl)
|
if (log_lvl)
|
||||||
console.log(
|
console.log(
|
||||||
`[LQ] Querying Presentations for Session: ${url_session_id}`
|
`[LQ] Querying Presentations for Session: ${url_session_id}`
|
||||||
);
|
);
|
||||||
return await db_events.presentation
|
const results = await db_events.presentation
|
||||||
.where('event_session_id')
|
.where('event_session_id')
|
||||||
.equals(url_session_id)
|
.equals(url_session_id)
|
||||||
.sortBy('name');
|
.toArray();
|
||||||
|
return results.sort((a, b) => {
|
||||||
|
// priority DESC (true first)
|
||||||
|
const pa = a.priority ? 1 : 0;
|
||||||
|
const pb = b.priority ? 1 : 0;
|
||||||
|
if (pb !== pa) return pb - pa;
|
||||||
|
// sort ASC
|
||||||
|
const sa = a.sort ?? 0;
|
||||||
|
const sb = b.sort ?? 0;
|
||||||
|
if (sa !== sb) return sa - sb;
|
||||||
|
// start_datetime ASC
|
||||||
|
const da = a.start_datetime ?? '';
|
||||||
|
const db_val = b.start_datetime ?? '';
|
||||||
|
if (da !== db_val) return da < db_val ? -1 : 1;
|
||||||
|
// code ASC
|
||||||
|
const ca = a.code ?? '';
|
||||||
|
const cb = b.code ?? '';
|
||||||
|
if (ca !== cb) return ca < cb ? -1 : 1;
|
||||||
|
// name ASC
|
||||||
|
const na = a.name ?? '';
|
||||||
|
const nb = b.name ?? '';
|
||||||
|
return na < nb ? -1 : na > nb ? 1 : 0;
|
||||||
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user