From 693a2e42c4c07cd17d44556e473cc39c95657636 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Wed, 14 Jan 2026 16:04:15 -0500 Subject: [PATCH] fix(journals): resolve decryption UI update and background sync issues - Cleared 'content_encrypted' from local state upon successful decryption to update UI. - Modified background sync effect to preserve decrypted content during active sessions. - Enhanced decryption logging for better diagnostics. --- src/lib/ae_journals/ae_journals_decryption.ts | 2 +- .../ae_comp__journal_entry_obj_id_view.svelte | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/lib/ae_journals/ae_journals_decryption.ts b/src/lib/ae_journals/ae_journals_decryption.ts index 97ae0506..b7796d5c 100644 --- a/src/lib/ae_journals/ae_journals_decryption.ts +++ b/src/lib/ae_journals/ae_journals_decryption.ts @@ -81,7 +81,7 @@ export async function decrypt_journal_entry( } } - console.log('decrypt_journal_entry: SUCCESS'); + console.log(`decrypt_journal_entry: SUCCESS. Content length: ${decrypted_text.length}. Preview: ${decrypted_text.substring(0, 20)}...`); return { success: true, content: decrypted_text, diff --git a/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte b/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte index bbe4bd14..001504ea 100644 --- a/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte +++ b/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte @@ -75,9 +75,19 @@ // 1. Initial Load & Background Sync $effect(() => { const entry = $lq__journal_entry_obj; + const journal = $lq__journal_obj; if (entry && (entry.updated_on || entry.created_on)) { + // Determine if we are in a decrypted state for this journal + const is_decrypted = $journals_sess?.journal_kv[journal?.id]?.journal_passcode_decrypted === true; + // Only sync if saved and not currently processing/editing if (save_status === 'saved' && !has_unsaved_changes && !is_processing) { + // If the journal is already decrypted, we MUST NOT overwrite the decrypted content with null from DB + if (is_decrypted && tmp_entry_obj.content && !entry.content) { + console.log('ae_view: Background sync skipped to preserve decrypted content.'); + return; + } + const base = { ...entry, content: entry.content ?? null, @@ -150,9 +160,19 @@ } // SUCCESS + console.log(`ae_view: Decryption SUCCESS. Updating state.`); tmp_entry_obj.content = result.content; tmp_entry_obj.content_md_html = handle_marked(result.content || ''); - if (orig_entry_obj) orig_entry_obj.content = result.content; + + // CRITICAL: Clear encrypted fields in local state so UI doesn't think it's still locked + tmp_entry_obj.content_encrypted = null; + tmp_entry_obj.history_encrypted = null; + + if (orig_entry_obj) { + orig_entry_obj.content = result.content; + orig_entry_obj.content_encrypted = null; + orig_entry_obj.history_encrypted = null; + } if (result.history) { tmp_entry_obj.history = result.history;