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:
@@ -77,7 +77,7 @@
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
`Triggered: $journals_trig.journal_entry_qry: ${$journals_loc.qry__search_text}`
|
||||
`Triggered: $journals_trig.journal_entry_qry: ${$journals_loc.entry.qry__search_text}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -85,36 +85,31 @@
|
||||
$journals_prom.load__journal_entry_obj_li = await journals_func.qry__journal_entry({
|
||||
api_cfg: $ae_api,
|
||||
journal_id: $lq__journal_obj?.journal_id ?? '',
|
||||
qry_str: $journals_loc.qry__search_text,
|
||||
qry_str: $journals_loc.entry.qry__search_text,
|
||||
|
||||
// qry_created_on: null,
|
||||
// qry_alert: null,
|
||||
// qry_priority: null,
|
||||
// qry_type: and_type,
|
||||
|
||||
enabled: 'enabled', // $journals_loc.qry__enabled,
|
||||
hidden: 'not_hidden', // $journals_loc.qry__hidden,
|
||||
// order_by_li: $journals_loc.qry__order_by_li,
|
||||
// limit: $journals_loc.qry__limit,
|
||||
enabled: $journals_loc.entry.qry__enabled ?? 'enabled',
|
||||
hidden: $journals_loc.entry.qry__hidden ?? 'not_hidden',
|
||||
// order_by_li: $journals_loc.entry.qry__order_by_li,
|
||||
// limit: $journals_loc.entry.qry__limit,
|
||||
// try_cache: try_cache,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
if ($journals_prom.load__journal_entry_obj_li.length) {
|
||||
|
||||
if (!$journals_loc.entry.qry__search_text) {
|
||||
// If search text was cleared or empty, reset to default view (null)
|
||||
$journals_sess.entry_li = null;
|
||||
} else if ($journals_prom.load__journal_entry_obj_li && $journals_prom.load__journal_entry_obj_li.length > 0) {
|
||||
$journals_sess.entry_li = $journals_prom.load__journal_entry_obj_li;
|
||||
|
||||
$journals_sess = {
|
||||
...$journals_sess
|
||||
}; // ensure session is updated
|
||||
|
||||
// $journals_trig.journal_entry_li = true; // trigger the entry list to refresh
|
||||
// $journals_trig.journal_entry_li = $journals_prom.load__journal_entry_obj_li;
|
||||
$journals_sess = { ...$journals_sess }; // ensure session is updated
|
||||
} else {
|
||||
console.log('Clear the search results: no entries found for that query.');
|
||||
// $journals_sess.entry_li = [''];
|
||||
$journals_sess.entry_li = null;
|
||||
// $journals_trig.journal_entry_li = true;
|
||||
// alert('No journal entries found for that search query.');
|
||||
// $journals_sess = $journals_sess;
|
||||
// Explicitly set to empty array to indicate "0 results found" (vs null which is "default view")
|
||||
$journals_sess.entry_li = [];
|
||||
}
|
||||
|
||||
if (log_lvl) {
|
||||
@@ -131,10 +126,10 @@
|
||||
disabled={false}
|
||||
type="text"
|
||||
placeholder="Search Journal Entries"
|
||||
bind:value={$journals_loc.qry__search_text}
|
||||
bind:value={$journals_loc.entry.qry__search_text}
|
||||
onkeyup={(event) => {
|
||||
if (event.key === 'Enter') {
|
||||
// $journals_loc.qry__search_text = (event.target as HTMLInputElement).value;
|
||||
// $journals_loc.entry.qry__search_text = (event.target as HTMLInputElement).value;
|
||||
$journals_trig.journal_entry_qry = true;
|
||||
}
|
||||
}}
|
||||
@@ -151,11 +146,11 @@
|
||||
<!-- Clear search text button -->
|
||||
<button
|
||||
type="button"
|
||||
class:hidden={!$journals_loc.qry__search_text}
|
||||
class:hidden={!$journals_loc.entry.qry__search_text}
|
||||
onclick={() => {
|
||||
console.log(`TESTING - 1 - Cleared search query: ${$journals_loc.qry__search_text}`);
|
||||
$journals_loc.qry__search_text = '';
|
||||
console.log(`TESTING - 2 - Cleared search query: ${$journals_loc.qry__search_text}`);
|
||||
console.log(`TESTING - 1 - Cleared search query: ${$journals_loc.entry.qry__search_text}`);
|
||||
$journals_loc.entry.qry__search_text = '';
|
||||
console.log(`TESTING - 2 - Cleared search query: ${$journals_loc.entry.qry__search_text}`);
|
||||
$journals_trig.journal_entry_qry = true;
|
||||
}}
|
||||
class="
|
||||
@@ -209,13 +204,13 @@
|
||||
hover:preset-filled-tertiary-100-900
|
||||
transition-all
|
||||
"
|
||||
bind:value={$journals_loc.qry__category_code}
|
||||
bind:value={$journals_loc.entry.qry__category_code}
|
||||
onchange={(event) => {
|
||||
// WARNING: This will cause pages to reset if the journal entry list is being filtered by category. This is a bug that should be fixed.
|
||||
$journals_loc.qry__category_code = (event.target as HTMLInputElement).value;
|
||||
$journals_loc.filter__category_code = (event.target as HTMLInputElement).value;
|
||||
$journals_loc.entry.qry__category_code = (event.target as HTMLInputElement).value;
|
||||
// $journals_loc.entry.qry__category_code = (event.target as HTMLInputElement).value;
|
||||
$journals_trig.journal_entry_li = true;
|
||||
console.log('Selected category:', $journals_loc.qry__category_code);
|
||||
console.log('Selected category:', $journals_loc.entry.qry__category_code);
|
||||
}}
|
||||
title="Select a category for the new journal entry"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user