From 322abc26916f9190ec994e115581a3f3abfc046f Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 28 May 2026 13:38:13 -0400 Subject: [PATCH] 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 --- .../session/[session_id]/+page.svelte | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/routes/events/[event_id]/(pres_mgmt)/session/[session_id]/+page.svelte b/src/routes/events/[event_id]/(pres_mgmt)/session/[session_id]/+page.svelte index 0d770f4b..47e61413 100644 --- a/src/routes/events/[event_id]/(pres_mgmt)/session/[session_id]/+page.svelte +++ b/src/routes/events/[event_id]/(pres_mgmt)/session/[session_id]/+page.svelte @@ -67,16 +67,40 @@ let lq__event_session_obj = $derived( ); // 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( liveQuery(async () => { if (log_lvl) console.log( `[LQ] Querying Presentations for Session: ${url_session_id}` ); - return await db_events.presentation + const results = await db_events.presentation .where('event_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; + }); }) );