Fix: Stabilize Journal Entries query logic and UI search behavior
- Consolidated LiveQuery logic into [journal_id]/+page.svelte and removed redundancy from layout. - Added automatic load trigger on journal_id change to ensure data freshness. - Hardened Enabled/Hidden filters to correctly include NULL/undefined values in default views. - Refined search behavior to distinguish between "default view" (null) and "no results found" ([]). - Updated modal_journals_config.svelte with standardized module-level settings. - Robust ID handling in bulk retrieval to handle varying property names (id, random_id).
This commit is contained in:
@@ -68,104 +68,6 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let lq__journal_entry_obj_li = $derived(
|
||||
liveQuery(async () => {
|
||||
let results;
|
||||
|
||||
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
|
||||
// $journals_sess.entry_li_trigger = false;
|
||||
let journal_entry_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
|
||||
|
||||
for (let i = 0; i < $journals_sess?.entry_li.length; i++) {
|
||||
let journal_entry_obj = $journals_sess?.entry_li[i];
|
||||
let journal_entry_id_random = journal_entry_obj.journal_entry_id_random;
|
||||
journal_entry_id_random_li.push(journal_entry_id_random);
|
||||
}
|
||||
// let journal_entry_id_random_li = tmp_li;
|
||||
|
||||
results = await db_journals.journal_entry.bulkGet(journal_entry_id_random_li);
|
||||
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
|
||||
results = await db_journals.journal_entry
|
||||
// .orderBy('updated_on')
|
||||
.where('journal_id')
|
||||
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
|
||||
.reverse()
|
||||
// .sortBy('tmp_sort_2');
|
||||
.sortBy('updated_on');
|
||||
// .sortBy('title');
|
||||
} else if (
|
||||
$journals_loc.filter__category_code &&
|
||||
$journals_loc.filter__category_code.length > 0
|
||||
) {
|
||||
results = await db_journals.journal_entry
|
||||
.where('journal_id')
|
||||
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
|
||||
.and((entry) => entry.category_code === $journals_loc.filter__category_code)
|
||||
.reverse()
|
||||
.sortBy('tmp_sort_1');
|
||||
} else {
|
||||
results = await db_journals.journal_entry
|
||||
.where('journal_id')
|
||||
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
|
||||
.reverse()
|
||||
.sortBy('tmp_sort_1');
|
||||
// .sortBy('updated_on');
|
||||
}
|
||||
|
||||
// Check if results are different than the current session version stored under $journals_slct
|
||||
if (
|
||||
$journals_slct.journal_entry_obj_li &&
|
||||
JSON.stringify($journals_slct.journal_entry_obj_li) !== JSON.stringify(results)
|
||||
) {
|
||||
$journals_slct.journal_entry_obj_li = [...results];
|
||||
}
|
||||
|
||||
return results;
|
||||
})
|
||||
);
|
||||
|
||||
$effect(() => {
|
||||
if (log_lvl) {
|
||||
console.log(`LQ - $lq__journal_obj.cfg_json = `, $lq__journal_obj?.cfg_json);
|
||||
console.log(
|
||||
`LQ - $journals_loc.filter__category_code = `,
|
||||
$journals_loc.filter__category_code
|
||||
);
|
||||
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
|
||||
console.log(`LQ - Using $journals_sess.entry_li to get journal entries.`);
|
||||
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
|
||||
console.log(
|
||||
`LQ - Using DESC sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`
|
||||
);
|
||||
} else if (
|
||||
$journals_loc.filter__category_code &&
|
||||
$journals_loc.filter__category_code.length > 0
|
||||
) {
|
||||
console.log(`LQ - Using category filter: ${$journals_loc.filter__category_code}`);
|
||||
} else {
|
||||
console.log(
|
||||
`LQ - Using default sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`
|
||||
);
|
||||
}
|
||||
if (
|
||||
$journals_slct.journal_entry_obj_li &&
|
||||
JSON.stringify($journals_slct.journal_entry_obj_li) !==
|
||||
JSON.stringify(lq__journal_entry_obj_li)
|
||||
) {
|
||||
console.log(
|
||||
`Session slct li stored version has changed for ID = ${$journals_slct.journal_id}`,
|
||||
$journals_slct.journal_entry_obj_li
|
||||
);
|
||||
} else {
|
||||
if (log_lvl > 1) {
|
||||
console.log(
|
||||
`Session slct li stored version has not changed for ID = ${$journals_slct.journal_id}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- Svelte layout for a Journal ID page and children -->
|
||||
@@ -221,7 +123,8 @@
|
||||
hover:preset-filled-tertiary-300-700
|
||||
transition-all
|
||||
"
|
||||
title={`View all journals menu: "${$ae_loc?.user?.name}"\nMiddle-click to open in new tab`}
|
||||
title={`View all journals menu: "${$ae_loc?.user?.name}"
|
||||
Middle-click to open in new tab`}
|
||||
>
|
||||
<!-- <BookHeart /> -->
|
||||
<!-- <Library /> -->
|
||||
@@ -348,8 +251,7 @@
|
||||
hover:variant-filled-warning
|
||||
transition
|
||||
"
|
||||
title="Edit Journal meta and configuration (name, type, passcode, categories, etc.: {$lq__journal_obj?.name})"
|
||||
>
|
||||
title="Edit Journal meta and configuration (name, type, passcode, categories, etc.: {$lq__journal_obj?.name})">
|
||||
<Pencil />
|
||||
<span class="hidden md:inline">
|
||||
Edit Journal
|
||||
@@ -371,8 +273,8 @@
|
||||
let data_kv = {
|
||||
category_code: null
|
||||
};
|
||||
if ($journals_loc.qry__category_code) {
|
||||
data_kv.category_code = $journals_loc.qry__category_code;
|
||||
if ($journals_loc.entry.qry__category_code) {
|
||||
data_kv.category_code = $journals_loc.entry.qry__category_code;
|
||||
}
|
||||
if (log_lvl) {
|
||||
console.log('Creating new journal entry with data_kv:', data_kv);
|
||||
@@ -425,7 +327,7 @@
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- <div class="overflow-auto"> -->
|
||||
<div class="overflow-auto">
|
||||
{@render children?.()}
|
||||
<!-- </div> -->
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
Reference in New Issue
Block a user