style(journals): apply expanded 80-width formatting and snake_case

- Batch formatted all Journals module files using Prettier with printWidth: 80.
- Refactored preventDefault to prevent_default across all Svelte components.
- Standardized line breaks for imports and long attribute lists for better readability.
- Ensured consistent snake_case naming for internal identifiers.
This commit is contained in:
Scott Idem
2026-02-06 14:15:43 -05:00
parent 07dd6c18a1
commit 2f3125c64b
37 changed files with 3033 additions and 1133 deletions

View File

@@ -35,11 +35,16 @@
let lq__journal_obj = $derived(
liveQuery(async () => {
let results = await db_journals.journal.get($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
let results = await db_journals.journal.get(
$journals_slct?.journal_id ?? ''
); // null or undefined does not reset things like '' does
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_obj && results) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(results)) {
if (
JSON.stringify($journals_slct.journal_obj) !==
JSON.stringify(results)
) {
$journals_slct.journal_obj = { ...results };
}
}
@@ -50,11 +55,14 @@
$effect(() => {
if (log_lvl) {
console.log(`lq__journal_obj: journal_id = ${$journals_slct?.journal_id}`);
console.log(
`lq__journal_obj: journal_id = ${$journals_slct?.journal_id}`
);
console.log(`lq__journal_obj: results = `, lq__journal_obj);
if ($journals_slct.journal_obj && lq__journal_obj) {
if (
JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(lq__journal_obj)
JSON.stringify($journals_slct.journal_obj) !==
JSON.stringify(lq__journal_obj)
) {
console.log(
`Session slct stored version has changed for ID = ${$journals_slct.journal_id}`,
@@ -99,7 +107,8 @@
"
>
<!-- If middle click then open the all journals page in a new tab. Otherwise show/hide the menu. -->
<button type="button"
<button
type="button"
onmousedown={(event) => {
if (event.button === 1) {
// Middle click - open in new tab
@@ -107,7 +116,7 @@
window.open('/journals');
// } else {
// // Left click - toggle menu
// event.preventDefault(); // Prevent default middle-click behavior
// event.prevent_default(); // Prevent default middle-click behavior
// show_menu__all_journals = !show_menu__all_journals;
}
}}
@@ -191,13 +200,15 @@ Middle-click to open in new tab`}
"
>
<option value="" disabled selected>
{Object.keys($journals_loc.entry_view_history_kv).length}&times; Recent
Entries...
{Object.keys($journals_loc.entry_view_history_kv)
.length}&times; Recent Entries...
</option>
<!-- loop through each key value -->
{#each Object.entries($journals_loc.entry_view_history_kv as Record<string, ae_JournalEntry>).reverse() as [journal_entry_id, journal_entry_obj]}
{#each Object.entries($journals_loc.entry_view_history_kv as Record).reverse() as [journal_entry_id, journal_entry_obj]}
<option value={journal_entry_obj.id}>
{(journal_entry_obj?.name || journal_entry_obj?.id) ?? 'NONE'}
{(journal_entry_obj?.name ||
journal_entry_obj?.id) ??
'NONE'}
</option>
{/each}
</select>
@@ -237,7 +248,8 @@ Middle-click to open in new tab`}
<!-- <span class="text-sm text-gray-500 hidden md:inline">
New entry:
</span> -->
<button type="button"
<button
type="button"
onclick={() => {
// $journals_sess.show__modal_new__journal_entry_obj = true;
@@ -245,10 +257,14 @@ Middle-click to open in new tab`}
category_code: null
};
if ($journals_loc.entry.qry__category_code) {
data_kv.category_code = $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);
console.log(
'Creating new journal entry with data_kv:',
data_kv
);
}
journals_func
.create_ae_obj__journal_entry({
@@ -259,16 +275,24 @@ Middle-click to open in new tab`}
})
.then((results) => {
if (log_lvl) {
console.log('New journal entry created:', results);
console.log(
'New journal entry created:',
results
);
}
$journals_slct.journal_entry_id = results?.journal_entry_id_random;
$journals_slct.journal_entry_id =
results?.journal_entry_id_random;
// $journals_loc.entry.edit = true;
$journals_loc.entry.edit_kv[$journals_slct.journal_entry_id] =
'current';
$journals_loc.entry.edit_kv[
$journals_slct.journal_entry_id
] = 'current';
// alert(`Journal entry created successfully! ${$journals_slct.journal_entry_id}`);
})
.catch((error) => {
console.error('Error updating journal entry:', error);
console.error(
'Error updating journal entry:',
error
);
alert('Failed to update journal entry.');
})
.finally(() => {
@@ -299,6 +323,6 @@ Middle-click to open in new tab`}
</div>
<div class="overflow-auto">
{@render children?.()}
{@render children?.()}
</div>
</section>
</section>

View File

@@ -15,7 +15,9 @@ export async function load({ params, parent }) {
let ae_acct = data[account_id];
if (!ae_acct) {
console.warn(`ae Journals [journal_id] +layout.ts: Account ${account_id} not found. Initializing ghost acct.`);
console.warn(
`ae Journals [journal_id] +layout.ts: Account ${account_id} not found. Initializing ghost acct.`
);
ae_acct = {
api: data.ae_api || {},
slct: {
@@ -36,10 +38,13 @@ export async function load({ params, parent }) {
ae_acct.slct.journal_id = journal_id;
if (browser) {
if (log_lvl) console.log(`ae_journals journals [journal_id] +layout.ts (Non-Blocking)`);
if (log_lvl)
console.log(
`ae_journals journals [journal_id] +layout.ts (Non-Blocking)`
);
// OPTIMIZATION: Fire the journal load in the background.
// The journal module now uses SWR, and components watching IDB
// The journal module now uses SWR, and components watching IDB
// will update automatically when the refresh completes.
journals_func.load_ae_obj_id__journal({
api_cfg: ae_acct.api,

View File

@@ -46,7 +46,7 @@
let ae_acct = data[$slct.account_id];
let show_export_modal = $state(false);
let show_import_modal = $state(false);
let search_id_li: Array<string> = $state([]);
let search_debounce_timer: any = null;
let last_search_id = 0;
@@ -54,7 +54,8 @@
function handle_import_complete() {
// Trigger a refresh of the journal entry list
if ($journals_loc.entry.search_version === undefined) $journals_loc.entry.search_version = 0;
if ($journals_loc.entry.search_version === undefined)
$journals_loc.entry.search_version = 0;
$journals_loc.entry.search_version++;
}
@@ -63,12 +64,14 @@
let lq__journal_obj = $derived(
liveQuery(async () => {
return await db_journals.journal.get($journals_slct?.journal_id ?? '');
return await db_journals.journal.get(
$journals_slct?.journal_id ?? ''
);
})
);
// Stable LiveQuery Pattern (Aether UI V3)
// Re-wrapped in $derived to ensure the observable instance remains stable
// Re-wrapped in $derived to ensure the observable instance remains stable
// unless the underlying dependencies (ids, search context) change.
let lq__journal_entry_obj_li = $derived(
liveQuery(async () => {
@@ -79,14 +82,18 @@
// SCENARIO 1: Specific IDs provided (Search Results)
if (Array.isArray(ids) && ids.length > 0) {
if (log_lvl) console.log(`Journal Page LQ: bulkGet ${ids.length} IDs`);
if (log_lvl)
console.log(`Journal Page LQ: bulkGet ${ids.length} IDs`);
const results = await db_journals.journal_entry.bulkGet(ids);
return results.filter(item => item !== undefined);
return results.filter((item) => item !== undefined);
}
// SCENARIO 2: Fallback to broad search (Default view)
if (journal_id && !search_text && !cat_code) {
if (log_lvl) console.log(`Journal Page LQ: Fallback search for journal: ${journal_id}`);
if (log_lvl)
console.log(
`Journal Page LQ: Fallback search for journal: ${journal_id}`
);
return await db_journals.journal_entry
.where('journal_id')
.equals(journal_id)
@@ -139,14 +146,17 @@
const current_search_id = ++last_search_id;
const journal_id = params.journal_id;
const remote_first = params.remote_first;
if (log_lvl) console.log(`[Journal Search #${current_search_id}] Refreshing entries (remote=${remote_first}, journal=${journal_id})...`);
if (log_lvl)
console.log(
`[Journal Search #${current_search_id}] Refreshing entries (remote=${remote_first}, journal=${journal_id})...`
);
// 2. Setup State
untrack(() => {
$journals_sess.entry.qry__status = 'loading';
});
const qry_str = params.str;
const cat_code = params.cat;
@@ -160,30 +170,46 @@
let local_results = await db_journals.journal_entry
.where('journal_id')
.equals(journal_id)
.filter(entry => {
if (cat_code && entry.category_code !== cat_code) return false;
.filter((entry) => {
if (cat_code && entry.category_code !== cat_code)
return false;
if (qry_str) {
const name = (entry.name ?? '').toLowerCase();
const content = (entry.content ?? '').toLowerCase();
return name.includes(qry_str) || content.includes(qry_str);
const content = (
entry.content ?? ''
).toLowerCase();
return (
name.includes(qry_str) ||
content.includes(qry_str)
);
}
return true;
})
.toArray();
local_results.sort((a, b) => {
const dateA = a.updated_on ? new Date(a.updated_on).getTime() : 0;
const dateB = b.updated_on ? new Date(b.updated_on).getTime() : 0;
const dateA = a.updated_on
? new Date(a.updated_on).getTime()
: 0;
const dateB = b.updated_on
? new Date(b.updated_on).getTime()
: 0;
return dateB - dateA;
});
local_ids = local_results.map(e => e.id || e.journal_entry_id_random).filter(Boolean);
local_ids = local_results
.map((e) => e.id || e.journal_entry_id_random)
.filter(Boolean);
if (current_search_id === last_search_id) {
if (log_lvl) console.log(`[Journal Search #${current_search_id}] Fast Path found ${local_ids.length} items locally.`);
if (log_lvl)
console.log(
`[Journal Search #${current_search_id}] Fast Path found ${local_ids.length} items locally.`
);
untrack(() => {
search_id_li = local_ids;
if (local_ids.length > 0) $journals_sess.entry.qry__status = 'done';
if (local_ids.length > 0)
$journals_sess.entry.qry__status = 'done';
});
}
}
@@ -208,10 +234,17 @@
if (current_search_id === last_search_id) {
const api_results = results || [];
const api_ids = api_results.map((e: any) => e.id || e.journal_entry_id_random).filter(Boolean);
const api_ids = api_results
.map((e: any) => e.id || e.journal_entry_id_random)
.filter(Boolean);
// Protect UI cache if API returns empty during revalidation
if (api_ids.length === 0 && local_ids.length > 0 && !remote_first && !qry_str) {
if (
api_ids.length === 0 &&
local_ids.length > 0 &&
!remote_first &&
!qry_str
) {
untrack(() => {
$journals_sess.entry.qry__status = 'done';
});
@@ -223,7 +256,10 @@
search_id_li = api_ids;
$journals_sess.entry.qry__status = 'done';
});
if (log_lvl) console.log(`[Journal Search #${current_search_id}] Revalidation Complete. Found ${api_ids.length} items.`);
if (log_lvl)
console.log(
`[Journal Search #${current_search_id}] Revalidation Complete. Found ${api_ids.length} items.`
);
}
} catch (error) {
if (current_search_id === last_search_id) {
@@ -239,7 +275,10 @@
}
if (browser) {
window.parent.postMessage({ journal_id: $journals_slct?.journal_id ?? null }, '*');
window.parent.postMessage(
{ journal_id: $journals_slct?.journal_id ?? null },
'*'
);
}
import { LoaderCircle } from 'lucide-svelte';
@@ -252,7 +291,9 @@
</svelte:head>
{#if $lq__journal_obj === undefined}
<div class="flex flex-col items-center justify-center p-20 opacity-50 text-center">
<div
class="flex flex-col items-center justify-center p-20 opacity-50 text-center"
>
<LoaderCircle size="3em" class="animate-spin mb-4 mx-auto" />
<p class="text-xl">Loading Journal...</p>
</div>
@@ -260,15 +301,15 @@
<AeCompJournalObjIdView
{lq__journal_obj}
{lq__journal_entry_obj_li}
on_show_export={() => show_export_modal = true}
on_show_import={() => show_import_modal = true}
on_show_export={() => (show_export_modal = true)}
on_show_import={() => (show_import_modal = true)}
/>
<Journal_entry_obj_li_wrapper
{lq__journal_obj}
<Journal_entry_obj_li_wrapper
{lq__journal_obj}
{lq__journal_entry_obj_li}
show_found_header={false}
{log_lvl}
{log_lvl}
/>
<Journal_obj_id_edit
@@ -286,11 +327,15 @@
<AeCompModalJournalImport
bind:open={show_import_modal}
on_close={() => show_import_modal = false}
on_close={() => (show_import_modal = false)}
on_import_complete={handle_import_complete}
/>
{:else}
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
<p class="text-center">You must be logged in as the owner to view this Journal.</p>
<section
class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center"
>
<p class="text-center">
You must be logged in as the owner to view this Journal.
</p>
</section>
{/if}
{/if}

View File

@@ -59,11 +59,16 @@
$journals_slct.journal_id = ae_acct.slct.journal_id;
let lq__journal_obj = $derived(
liveQuery(async () => {
let results = await db_journals.journal.get($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
let results = await db_journals.journal.get(
$journals_slct?.journal_id ?? ''
); // null or undefined does not reset things like '' does
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_obj && results) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(results)) {
if (
JSON.stringify($journals_slct.journal_obj) !==
JSON.stringify(results)
) {
$journals_slct.journal_obj = { ...results };
}
}
@@ -74,11 +79,14 @@
$effect(() => {
if (log_lvl) {
console.log(`lq__journal_obj: journal_id = ${$journals_slct?.journal_id}`);
console.log(
`lq__journal_obj: journal_id = ${$journals_slct?.journal_id}`
);
console.log(`lq__journal_obj: results = `, lq__journal_obj);
if ($journals_slct.journal_obj && lq__journal_obj) {
if (
JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(lq__journal_obj)
JSON.stringify($journals_slct.journal_obj) !==
JSON.stringify(lq__journal_obj)
) {
console.log(
`Session slct stored version has changed for ID = ${$journals_slct.journal_id}`,
@@ -104,7 +112,8 @@
// Check if results are different than the current session version stored under $journals_slct
if (
$journals_slct.journal_obj_li &&
JSON.stringify($journals_slct.journal_obj_li) !== JSON.stringify(results)
JSON.stringify($journals_slct.journal_obj_li) !==
JSON.stringify(results)
) {
$journals_slct.journal_obj_li = [...results];
}
@@ -119,7 +128,8 @@
console.log(`lq__journal_obj_li: results = `, lq__journal_obj_li);
if (
$journals_slct.journal_obj_li &&
JSON.stringify($journals_slct.journal_obj_li) !== JSON.stringify(lq__journal_obj_li)
JSON.stringify($journals_slct.journal_obj_li) !==
JSON.stringify(lq__journal_obj_li)
) {
console.log(
`Session slct li stored version has changed for ID = ${$ae_loc.person_id}`,
@@ -147,7 +157,10 @@
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_entry_obj && results) {
if (JSON.stringify($journals_slct.journal_entry_obj) !== JSON.stringify(results)) {
if (
JSON.stringify($journals_slct.journal_entry_obj) !==
JSON.stringify(results)
) {
$journals_slct.journal_entry_obj = { ...results };
}
}
@@ -161,7 +174,10 @@
console.log(
`lq__journal_entry_obj: journal_entry_id = ${$journals_slct?.journal_entry_id}`
);
console.log(`lq__journal_entry_obj: results = `, lq__journal_entry_obj);
console.log(
`lq__journal_entry_obj: results = `,
lq__journal_entry_obj
);
if ($journals_slct.journal_entry_obj && lq__journal_entry_obj) {
if (
JSON.stringify($journals_slct.journal_entry_obj) !==
@@ -180,11 +196,12 @@
}
});
$effect(() => {
if (browser && $lq__journal_entry_obj?.journal_entry_id) {
// Start with the current KV or convert the LI to a KV if needed
let history_kv = { ...($journals_loc?.entry_view_history_kv ?? {}) };
let history_kv = {
...($journals_loc?.entry_view_history_kv ?? {})
};
// Add or update the current entry
const entry_id = $lq__journal_entry_obj?.journal_entry_id ?? 'NONE';
@@ -220,7 +237,8 @@
// Only update if changed
if (
JSON.stringify(history_kv) !== JSON.stringify($journals_loc?.entry_view_history_kv)
JSON.stringify(history_kv) !==
JSON.stringify($journals_loc?.entry_view_history_kv)
) {
$journals_loc.entry_view_history_kv = history_kv;
console.log(
@@ -229,7 +247,9 @@
);
} else {
if (log_lvl > 1) {
console.log(`$journals_loc.entry_view_history_kv has not changed.`);
console.log(
`$journals_loc.entry_view_history_kv has not changed.`
);
}
}
@@ -261,7 +281,12 @@
"
>
<!-- {#if $lq__journal_entry_obj} -->
<Journal_entry_view {lq__journal_obj} {lq__journal_obj_li} {lq__journal_entry_obj} on_show_export={() => show_export_modal = true} />
<Journal_entry_view
{lq__journal_obj}
{lq__journal_obj_li}
{lq__journal_entry_obj}
on_show_export={() => (show_export_modal = true)}
/>
<!-- {/if} -->
</section>
@@ -269,10 +294,14 @@
bind:open={show_export_modal}
entries={$lq__journal_entry_obj ? [$lq__journal_entry_obj] : []}
journal={$lq__journal_obj}
on_close={() => show_export_modal = false}
on_close={() => (show_export_modal = false)}
/>
{:else}
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
<p class="text-center">You must be logged in as the owner to view this Journal Entry.</p>
<section
class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center"
>
<p class="text-center">
You must be logged in as the owner to view this Journal Entry.
</p>
</section>
{/if}

View File

@@ -4,7 +4,10 @@ console.log(`ae_p_journals [journal_entry_id] +page.ts start`);
import { browser } from '$app/environment';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
import { db_journals, journal_entry_field_li } from '$lib/ae_journals/db_journals';
import {
db_journals,
journal_entry_field_li
} from '$lib/ae_journals/db_journals';
import { load_ae_obj_id } from '$lib/ae_core/core__crud_generic';
export async function load({ params, parent }) {
@@ -18,7 +21,9 @@ export async function load({ params, parent }) {
let ae_acct = data[account_id];
if (!ae_acct) {
console.warn(`ae Journals [journal_entry_id] +page.ts: Account ${account_id} not found. Initializing ghost acct.`);
console.warn(
`ae Journals [journal_entry_id] +page.ts: Account ${account_id} not found. Initializing ghost acct.`
);
ae_acct = {
api: data.ae_api || {},
slct: {
@@ -72,7 +77,9 @@ export async function load({ params, parent }) {
});
if (!load_journal_entry_obj) {
console.warn(`ae Journals [journal_entry_id] +page.ts: Entry ${journal_entry_id} not found via API or Cache.`);
console.warn(
`ae Journals [journal_entry_id] +page.ts: Entry ${journal_entry_id} not found via API or Cache.`
);
// error(404, {
// message: 'Journals - Journal Entry not found'
// });