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.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user