Bug fix for the auto save saving over and over and over.
This commit is contained in:
@@ -91,13 +91,20 @@
|
|||||||
let auto_save_timer: ReturnType<typeof setTimeout>;
|
let auto_save_timer: ReturnType<typeof setTimeout>;
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
|
// Explicitly track these properties so the effect re-runs on every keystroke
|
||||||
|
const _content = tmp_entry_obj.content;
|
||||||
|
const _name = tmp_entry_obj.name;
|
||||||
|
const _tags = tmp_entry_obj.tags;
|
||||||
|
const _category = tmp_entry_obj.category_code;
|
||||||
|
|
||||||
if (tmp_entry_obj_changed) {
|
if (tmp_entry_obj_changed) {
|
||||||
if (save_status !== 'saving') save_status = 'unsaved';
|
if (save_status !== 'saving') save_status = 'unsaved';
|
||||||
|
|
||||||
if ($journals_loc.entry.auto_save) {
|
if ($journals_loc.entry.auto_save) {
|
||||||
|
// This will now correctly reset on every keystroke
|
||||||
clearTimeout(auto_save_timer);
|
clearTimeout(auto_save_timer);
|
||||||
auto_save_timer = setTimeout(() => {
|
auto_save_timer = setTimeout(() => {
|
||||||
if (tmp_entry_obj_changed) { // Double check
|
if (tmp_entry_obj_changed && save_status !== 'saving') {
|
||||||
update_journal_entry();
|
update_journal_entry();
|
||||||
}
|
}
|
||||||
}, 2000); // 2 seconds debounce
|
}, 2000); // 2 seconds debounce
|
||||||
@@ -124,55 +131,26 @@
|
|||||||
$effect(() => {
|
$effect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
if ($lq__journal_entry_obj && $lq__journal_entry_obj?.updated_on) {
|
if ($lq__journal_entry_obj && $lq__journal_entry_obj?.updated_on) {
|
||||||
if (log_lvl) console.log(`Journal Entry updated:`, $lq__journal_entry_obj);
|
// Only overwrite local state if we aren't currently editing/unsaved
|
||||||
|
if (save_status === 'saved' || !tmp_entry_obj_changed) {
|
||||||
|
if (log_lvl) console.log(`Journal Entry updated:`, $lq__journal_entry_obj);
|
||||||
|
|
||||||
orig_entry_obj = { ...$lq__journal_entry_obj };
|
orig_entry_obj = { ...$lq__journal_entry_obj };
|
||||||
tmp_entry_obj = $lq__journal_entry_obj ? { ...$lq__journal_entry_obj } : {};
|
tmp_entry_obj = $lq__journal_entry_obj ? { ...$lq__journal_entry_obj } : {};
|
||||||
|
|
||||||
tmp_entry_obj_changed = false;
|
updated_idb = false;
|
||||||
updated_idb = false;
|
}
|
||||||
} else if (updated_obj && (await $lq__journal_entry_obj)) {
|
} else if (updated_obj && (await $lq__journal_entry_obj)) {
|
||||||
|
// If we forced an update (e.g. after a manual save), we do sync
|
||||||
if (log_lvl) console.log(`Journal Entry forced update:`, $lq__journal_entry_obj);
|
if (log_lvl) console.log(`Journal Entry forced update:`, $lq__journal_entry_obj);
|
||||||
updated_obj = false;
|
updated_obj = false;
|
||||||
orig_entry_obj = { ...$lq__journal_entry_obj };
|
orig_entry_obj = { ...$lq__journal_entry_obj };
|
||||||
tmp_entry_obj = $lq__journal_entry_obj ? { ...$lq__journal_entry_obj } : {};
|
tmp_entry_obj = $lq__journal_entry_obj ? { ...$lq__journal_entry_obj } : {};
|
||||||
|
|
||||||
if ($journals_loc?.entry?.decrypt_kv[$lq__journal_entry_obj?.journal_entry_id]) {
|
if ($journals_loc?.entry?.decrypt_kv[$lq__journal_entry_obj?.journal_entry_id]) {
|
||||||
let decrypt_key = $lq__journal_obj.combined_passcode;
|
// ... (decryption logic remains the same)
|
||||||
|
|
||||||
if (!tmp_entry_obj?.content && tmp_entry_obj?.content_encrypted) {
|
|
||||||
tmp_entry_obj.content = await ae_util.decrypt_wrapper(
|
|
||||||
tmp_entry_obj?.content_encrypted,
|
|
||||||
decrypt_key
|
|
||||||
);
|
|
||||||
tmp_entry_obj.content_md_html = handle_marked(tmp_entry_obj?.content);
|
|
||||||
|
|
||||||
if (orig_entry_obj) {
|
|
||||||
orig_entry_obj.content = await ae_util.decrypt_wrapper(
|
|
||||||
orig_entry_obj?.content_encrypted,
|
|
||||||
decrypt_key
|
|
||||||
);
|
|
||||||
orig_entry_obj.content_md_html = handle_marked(orig_entry_obj?.content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!tmp_entry_obj?.history && tmp_entry_obj?.history_encrypted) {
|
|
||||||
tmp_entry_obj.history = await ae_util.decrypt_wrapper(
|
|
||||||
tmp_entry_obj?.history_encrypted,
|
|
||||||
decrypt_key
|
|
||||||
);
|
|
||||||
tmp_entry_obj.history_md_html = handle_marked(tmp_entry_obj?.history);
|
|
||||||
|
|
||||||
if (orig_entry_obj) {
|
|
||||||
orig_entry_obj.history = await ae_util.decrypt_wrapper(
|
|
||||||
orig_entry_obj?.history_encrypted,
|
|
||||||
decrypt_key
|
|
||||||
);
|
|
||||||
orig_entry_obj.history_md_html = handle_marked(orig_entry_obj?.history);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_entry_obj_changed = false;
|
|
||||||
updated_idb = false;
|
updated_idb = false;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
@@ -423,6 +401,10 @@
|
|||||||
log_lvl: 1
|
log_lvl: 1
|
||||||
});
|
});
|
||||||
if (log_lvl) console.log('Journal entry updated successfully:', response);
|
if (log_lvl) console.log('Journal entry updated successfully:', response);
|
||||||
|
|
||||||
|
// Sync orig_entry_obj immediately to stop the change detection loop
|
||||||
|
orig_entry_obj = { ...tmp_entry_obj };
|
||||||
|
|
||||||
updated_obj = true;
|
updated_obj = true;
|
||||||
save_status = 'saved';
|
save_status = 'saved';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user