fix(idb-sort): correct tmp_sort_* comparator direction in journals, IDAA recovery meetings, and BB post comments
build_tmp_sort() encodes priority=true as '0' for ascending sort. JS comparators were using b.localeCompare(a) (descending), inverting the encoding so priority=false items sorted first. Fixed to a.localeCompare(b) in ae_journals_search_helpers.ts (3 sites in recovery_meetings +page.svelte and wrapper component). Also fixes a Dexie anti-pattern in bb/[post_id]: .reverse() before .sortBy() is a no-op in Dexie; moved array .reverse() to after the await. Documents the encoding rule and legacy inverted-encoding modules in GUIDE__SvelteKit2_Svelte5_DexieJS.md and adds mistake #15 to BOOTSTRAP quickstart. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -73,12 +73,14 @@ let lq__post_comment_obj_li = $derived.by(() => {
|
||||
return liveQuery(async () => {
|
||||
if (!post_id) return [];
|
||||
|
||||
return await db_posts.comment
|
||||
// .reverse() before .sortBy() is a Dexie no-op — reverse the array after instead.
|
||||
// tmp_sort_1 here uses legacy encoding (priority=true→'1') designed for DESC order.
|
||||
const comments = await db_posts.comment
|
||||
.where('post_id')
|
||||
.equals(post_id)
|
||||
.reverse()
|
||||
.limit(limit)
|
||||
.sortBy('tmp_sort_1');
|
||||
return comments.reverse();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -255,8 +255,9 @@ async function handle_search_refresh(qry_key: string) {
|
||||
} else {
|
||||
// Robust Chronological Sort using pre-computed tmp_sort_1
|
||||
// Handles Priority, Manual Sort, and the updated_on/created_on fallback
|
||||
// tmp_sort_1 built by build_tmp_sort(): priority=true→'0', so ASC puts priority first.
|
||||
local_results.sort((a, b) =>
|
||||
(b.tmp_sort_1 ?? '').localeCompare(a.tmp_sort_1 ?? '')
|
||||
(a.tmp_sort_1 ?? '').localeCompare(b.tmp_sort_1 ?? '')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -335,8 +336,9 @@ async function handle_search_refresh(qry_key: string) {
|
||||
(b.name ?? '').localeCompare(a.name ?? '')
|
||||
);
|
||||
} else {
|
||||
// tmp_sort_1 built by build_tmp_sort(): priority=true→'0', so ASC puts priority first.
|
||||
api_results.sort((a, b) =>
|
||||
(b.tmp_sort_1 ?? '').localeCompare(a.tmp_sort_1 ?? '')
|
||||
(a.tmp_sort_1 ?? '').localeCompare(b.tmp_sort_1 ?? '')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -95,8 +95,10 @@ let lq__event_obj_li = $derived.by(() => {
|
||||
} else {
|
||||
// Robust Chronological Sort using pre-computed tmp_sort_1 (Refactored 2026-02-16)
|
||||
// This handles Group > Priority > Manual Sort > Date (with updated_on fallback)
|
||||
// tmp_sort_1 is built by build_tmp_sort() for ascending comparison:
|
||||
// priority=true encodes as '0', priority=false as '1', so ASC puts priority first.
|
||||
results.sort((a, b) =>
|
||||
(b.tmp_sort_1 ?? '').localeCompare(a.tmp_sort_1 ?? '')
|
||||
(a.tmp_sort_1 ?? '').localeCompare(b.tmp_sort_1 ?? '')
|
||||
);
|
||||
}
|
||||
return results;
|
||||
|
||||
Reference in New Issue
Block a user