remove entered text from localstorage when sending response

This commit is contained in:
Lera Elvoé 2025-07-01 18:43:28 +03:00
parent c4ee9d883e
commit 18f4b026ea
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
2 changed files with 15 additions and 2 deletions

View File

@ -67,7 +67,7 @@
<div id="babycode-preview-container"></div> <div id="babycode-preview-container"></div>
</div> </div>
</div> </div>
<script src="/static/js/babycode-editor.js?v=1"></script> <script src="/static/js/babycode-editor.js?v=2"></script>
{% endmacro %} {% endmacro %}
{% macro babycode_editor_form(ta_name, prefill = "", cancel_url="", endpoint="") %} {% macro babycode_editor_form(ta_name, prefill = "", cancel_url="", endpoint="") %}

View File

@ -4,6 +4,9 @@
ta.addEventListener("keydown", (e) => { ta.addEventListener("keydown", (e) => {
if(e.key === "Enter" && e.ctrlKey) { if(e.key === "Enter" && e.ctrlKey) {
// console.log(e.target.form) // console.log(e.target.form)
if (inThread()) {
localStorage.removeItem(window.location.pathname);
}
e.target.form?.submit(); e.target.form?.submit();
} }
}) })
@ -18,7 +21,17 @@
localStorage.setItem(window.location.pathname, ta.value); 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", () => { document.addEventListener("DOMContentLoaded", () => {
if (!inThread()) return; if (!inThread()) return;
const prevContent = localStorage.getItem(window.location.pathname); const prevContent = localStorage.getItem(window.location.pathname);