Bug fixes and clean up for the recent history of Journal Entries.

This commit is contained in:
Scott Idem
2025-09-10 17:31:04 -04:00
parent efa7833fb3
commit cc6186467a
4 changed files with 117 additions and 49 deletions

View File

@@ -29,7 +29,9 @@ let journals_local_data_struct: key_val = {
qry__journal_id: null, qry__journal_id: null,
journal_view_history_li: [], // Appended each time the journal is loaded. journal_view_history_li: [], // Appended each time the journal is loaded.
entry_view_history_li: [], // Appended each time the entry is loaded. entry_view_history_li: [], // NO LONGER USED: Appended each time the entry is loaded.
entry_view_history_kv: {}, // Keyed by journal_entry_id for quick lookup.
entry_view_history_max: 15, // Maximum number of journal entries to keep in history.
journal: { journal: {
edit: false, edit: false,

View File

@@ -48,7 +48,6 @@ import Journal_entry_obj_qry from './../ae_comp__journal_entry_obj_qry.svelte';
// let tmp_journal_obj_changed: boolean = $state(false); // let tmp_journal_obj_changed: boolean = $state(false);
// let tmp_journal_obj: key_val = $state({}); // let tmp_journal_obj: key_val = $state({});
let ae_acct = data[$slct.account_id]; let ae_acct = data[$slct.account_id];
if (log_lvl) { if (log_lvl) {
console.log(`ae_acct = `, ae_acct); console.log(`ae_acct = `, ae_acct);
@@ -183,8 +182,23 @@ let lq__journal_obj = $derived(liveQuery(async () => {
" "
> >
<!-- If middle click then open the all journals page in a new tab. Otherwise show/hide the menu. -->
<button <button
type="button" type="button"
onmousedown={
(event) => {
if (event.button === 1) {
// Middle click - open in new tab
// window.open('/journals', '_blank');
window.open('/journals');
// } else {
// // Left click - toggle menu
// event.preventDefault(); // Prevent default middle-click behavior
// show_menu__all_journals = !show_menu__all_journals;
}
}
}
onclick={() => { onclick={() => {
show_menu__all_journals = !show_menu__all_journals; show_menu__all_journals = !show_menu__all_journals;
}} }}
@@ -196,7 +210,7 @@ let lq__journal_obj = $derived(liveQuery(async () => {
hover:preset-filled-tertiary-300-700 hover:preset-filled-tertiary-300-700
transition-all transition-all
" "
title="View all journals menu: {$ae_loc.account_name}" title={`View all journals menu: "${$ae_loc?.user?.name}"\nMiddle-click to open in new tab`}
> >
<!-- <BookHeart /> --> <!-- <BookHeart /> -->
<!-- <Library /> --> <!-- <Library /> -->
@@ -207,6 +221,7 @@ let lq__journal_obj = $derived(liveQuery(async () => {
{/if} {/if}
<span class="hidden md:inline"> <span class="hidden md:inline">
Journals Journals
<!-- for {$ae_loc?.user?.name} -->
</span> </span>
</button> </button>
@@ -245,9 +260,10 @@ let lq__journal_obj = $derived(liveQuery(async () => {
</a> </a>
<!-- $journals_slct?.journal_id && -->
<!-- List of recent entries here... --> <!-- List of recent entries here... -->
<!-- $journals_loc.entry_view_history_li --> <!-- $journals_loc.entry_view_history_li -->
{#if $journals_loc?.entry_view_history_li?.length > 0} {#if $journals_loc.entry_view_history_kv && Object.keys($journals_loc.entry_view_history_kv).length > 0}
<select <select
bind:value={$journals_slct.journal_entry_id} bind:value={$journals_slct.journal_entry_id}
onchange={() => { onchange={() => {
@@ -264,11 +280,12 @@ let lq__journal_obj = $derived(liveQuery(async () => {
" "
> >
<option value="" disabled selected> <option value="" disabled selected>
Recent Entries... {Object.keys($journals_loc.entry_view_history_kv).length}&times; Recent Entries...
</option> </option>
{#each $journals_loc.entry_view_history_li as entry (entry.id)} <!-- loop through each key value -->
<option value={entry.id}> {#each Object.entries($journals_loc.entry_view_history_kv).reverse() as [journal_entry_id, journal_entry_obj]}
{entry.name} <option value={journal_entry_obj.id}>
{(journal_entry_obj?.name || journal_entry_obj?.id) ?? 'NONE'}
</option> </option>
{/each} {/each}
</select> </select>

View File

@@ -129,57 +129,106 @@ let lq__journal_entry_obj = $derived(liveQuery(async () => {
return results; return results;
})); }));
// $effect(() => {
// if (browser && $lq__journal_entry_obj?.journal_entry_id) {
// // $journals_loc.entry_view_history_li = [...new Set($journals_loc.entry_view_history_li)]
// let tmp_history_li = [
// ...new Set($journals_loc?.entry_view_history_li ?? [])
// ];
// // Limit to last 15 entries
// if (tmp_history_li.length > 15) {
// tmp_history_li = tmp_history_li.slice(tmp_history_li.length - 15);
// }
// // let chk_history_li = tmp_history_li?.filter(item => item.id === $lq__journal_entry_obj?.journal_entry_id);
// // if (chk_history_li?.length) {
// // // Already in history, do not add again
// // console.log(`Entry ID = ${$lq__journal_entry_obj?.journal_entry_id} already in history, not adding again.`, tmp_history_li);
// // // if (tmp_history_li !== $journals_loc.entry_view_history_li) {
// // if (JSON.stringify(tmp_history_li) !== JSON.stringify($journals_loc.entry_view_history_li)) {
// // $journals_loc.entry_view_history_li = tmp_history_li;
// // console.log(`$journals_loc.entry_view_history_li = `, $journals_loc.entry_view_history_li);
// // }
// // return;
// // }
// tmp_history_li.push({
// id: $lq__journal_entry_obj?.journal_entry_id ?? 'NONE',
// name: $lq__journal_entry_obj?.name ?? ae_util.iso_datetime_formatter($lq__journal_entry_obj?.created_on, 'datetime_iso_12_no_seconds'),
// url: `/journals/${$lq__journal_entry_obj?.journal_id ?? 'NONE'}/entry/${$lq__journal_entry_obj?.journal_entry_id ?? 'NONE'}`,
// });
// // Remove duplicates and keep most recent
// tmp_history_li = [...new Set(tmp_history_li.map(item => JSON.stringify(item)))].map(item => JSON.parse(item));
// // Limit to last 15 entries
// if (tmp_history_li.length > 15) {
// tmp_history_li = tmp_history_li.slice(tmp_history_li.length - 15);
// }
// if (JSON.stringify(tmp_history_li) !== JSON.stringify($journals_loc?.entry_view_history_li)) {
// $journals_loc.entry_view_history_li = tmp_history_li;
// console.log(`$journals_loc.entry_view_history_li = `, $journals_loc?.entry_view_history_li);
// }
// console.log(`$journals_loc.entry_view_history_li = `, $journals_loc?.entry_view_history_li);
// }
// });
$effect(() => { $effect(() => {
if (browser && $lq__journal_entry_obj?.journal_entry_id) { if (browser && $lq__journal_entry_obj?.journal_entry_id) {
log_lvl = 2;
// Start with the current KV or convert the LI to a KV if needed
let history_kv = { ...( $journals_loc?.entry_view_history_kv ?? {} ) };
// $journals_loc.entry_view_history_li = [...new Set($journals_loc.entry_view_history_li)] // Add or update the current entry
const entry_id = $lq__journal_entry_obj?.journal_entry_id ?? 'NONE';
history_kv[entry_id] = {
id: entry_id,
name: $lq__journal_entry_obj?.name ?? ae_util.iso_datetime_formatter($lq__journal_entry_obj?.created_on, 'datetime_iso_12_no_seconds'),
url: `/journals/${$lq__journal_entry_obj?.journal_id ?? 'NONE'}/entry/${entry_id}`,
};
let tmp_history_li = [ console.log(`history_kv (before limiting) = `, history_kv);
...new Set($journals_loc.entry_view_history_li)
];
// Limit to last 15 entries // // Convert KV to array, sort by most recent (last updated), and limit to 15
if (tmp_history_li.length > 15) { // let history_li = Object.values(history_kv);
tmp_history_li = tmp_history_li.slice(tmp_history_li.length - 15);
}
// let chk_history_li = tmp_history_li?.filter(item => item.id === $lq__journal_entry_obj?.journal_entry_id); // console.log(`history_li (before limiting) = `, history_li);
// if (chk_history_li?.length) { // // If you want to keep the most recent 15, you can use the order of insertion.
// // Already in history, do not add again // // To do this, remove the oldest if over 15.
// console.log(`Entry ID = ${$lq__journal_entry_obj?.journal_entry_id} already in history, not adding again.`, tmp_history_li); // if (history_li.length > 15) {
// // Remove the oldest entries (by insertion order)
// // if (tmp_history_li !== $journals_loc.entry_view_history_li) { // // Get the keys in insertion order
// if (JSON.stringify(tmp_history_li) !== JSON.stringify($journals_loc.entry_view_history_li)) { // const keys = Object.keys(history_kv);
// $journals_loc.entry_view_history_li = tmp_history_li; // const keys_to_remove = keys.slice(0, history_li.length - 15);
// for (const key of keys_to_remove) {
// console.log(`$journals_loc.entry_view_history_li = `, $journals_loc.entry_view_history_li); // delete history_kv[key];
// } // }
// return;
// } // }
tmp_history_li.push({ // Only update if changed
id: $lq__journal_entry_obj?.journal_entry_id ?? 'NONE', if (JSON.stringify(history_kv) !== JSON.stringify($journals_loc?.entry_view_history_kv)) {
name: $lq__journal_entry_obj?.name ?? ae_util.iso_datetime_formatter($lq__journal_entry_obj?.created_on, 'datetime_iso_12_no_seconds'), $journals_loc.entry_view_history_kv = history_kv;
url: `/journals/${$lq__journal_entry_obj?.journal_id ?? 'NONE'}/entry/${$lq__journal_entry_obj?.journal_entry_id ?? 'NONE'}`, console.log(`$journals_loc.entry_view_history_kv = `, $journals_loc.entry_view_history_kv);
}); } else {
if (log_lvl > 1) {
// Remove duplicates and keep most recent console.log(`$journals_loc.entry_view_history_kv has not changed.`);
tmp_history_li = [...new Set(tmp_history_li.map(item => JSON.stringify(item)))].map(item => JSON.parse(item)); }
// Limit to last 15 entries
if (tmp_history_li.length > 15) {
tmp_history_li = tmp_history_li.slice(tmp_history_li.length - 15);
} }
if (JSON.stringify(tmp_history_li) !== JSON.stringify($journals_loc.entry_view_history_li)) { // log_lvl = 1;
$journals_loc.entry_view_history_li = tmp_history_li;
console.log(`$journals_loc.entry_view_history_li = `, $journals_loc.entry_view_history_li);
}
console.log(`$journals_loc.entry_view_history_li = `, $journals_loc.entry_view_history_li);
} }
}); });
</script> </script>

View File

@@ -391,7 +391,7 @@ async function handle_update_journal() {
} }
}} }}
class="btn btn-sm preset-tonal-secondary border border-secondary-500 hover:preset-filled-secondary-500 transition *:hover:inline" class="btn btn-sm preset-tonal-secondary border border-secondary-500 hover:preset-filled-secondary-500 transition *:hover:inline"
title="Toggle visibility of Markdown copy button(s) on Journal Entry view page" title="Toggle hover or click to expand Entry content in the list"
> >
{#if tmp__journal_obj.cfg_json.expand_li_content == 'hover'} {#if tmp__journal_obj.cfg_json.expand_li_content == 'hover'}
<!-- <EyeOff strokeWidth="1" color="red" /> --> <!-- <EyeOff strokeWidth="1" color="red" /> -->
@@ -434,7 +434,7 @@ async function handle_update_journal() {
} }
}} }}
class="btn btn-sm preset-tonal-secondary border border-secondary-500 hover:preset-filled-secondary-500 transition group" class="btn btn-sm preset-tonal-secondary border border-secondary-500 hover:preset-filled-secondary-500 transition group"
title="Toggle append or prepend text to Journal Entry content" title="Toggle prepend (start) or append (end) text to Journal Entry content"
> >
{#if tmp__journal_obj.cfg_json.entry_add_text == 'append'} {#if tmp__journal_obj.cfg_json.entry_add_text == 'append'}
<!-- <EyeOff strokeWidth="1" color="red" /> --> <!-- <EyeOff strokeWidth="1" color="red" /> -->