From 18f4b026ea640685e35b446c4acfa31e87a9556d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Tue, 1 Jul 2025 18:43:28 +0300 Subject: [PATCH] remove entered text from localstorage when sending response --- app/templates/common/macros.html | 2 +- data/static/js/babycode-editor.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/templates/common/macros.html b/app/templates/common/macros.html index aa1a77e..cb859ea 100644 --- a/app/templates/common/macros.html +++ b/app/templates/common/macros.html @@ -67,7 +67,7 @@
- + {% endmacro %} {% macro babycode_editor_form(ta_name, prefill = "", cancel_url="", endpoint="") %} diff --git a/data/static/js/babycode-editor.js b/data/static/js/babycode-editor.js index 5247e83..441c6f0 100644 --- a/data/static/js/babycode-editor.js +++ b/data/static/js/babycode-editor.js @@ -4,6 +4,9 @@ ta.addEventListener("keydown", (e) => { if(e.key === "Enter" && e.ctrlKey) { // console.log(e.target.form) + if (inThread()) { + localStorage.removeItem(window.location.pathname); + } e.target.form?.submit(); } }) @@ -18,7 +21,17 @@ localStorage.setItem(window.location.pathname, ta.value); }) - + + if (inThread()) { + const form = ta.closest('.post-edit-form'); + console.log(ta.closest('.post-edit-form')); + if (form){ + form.addEventListener("submit", () => { + localStorage.removeItem(window.location.pathname); + }) + } + } + document.addEventListener("DOMContentLoaded", () => { if (!inThread()) return; const prevContent = localStorage.getItem(window.location.pathname);