Hide the reply section after submitting a response

This commit is contained in:
Julian Rota 2022-09-05 12:30:40 -04:00 committed by Ben Rog-Wilhelm
parent bb142eda53
commit cf9819ca5b

View file

@ -218,14 +218,12 @@ function comment_edit(id){
function post_comment(fullname){ function post_comment(fullname){
const previewPlaceholderHTML= '<p class="preview-msg">Comment preview</p>'; const previewPlaceholderHTML= '<p class="preview-msg">Comment preview</p>';
function reset_preview(element_id) { function reset_preview(element_id) {
try { const element = document.getElementById(element_id);
document.getElementById(element_id).innerHTML = previewPlaceholderHTML; if (element) {
} catch (e) { element.innerHTML = previewPlaceholderHTML;
// We fail silently if the element doesnt exist return true;
if (!e instanceof TypeError) {
throw(e);
}
} }
return false;
} }
const btn = document.getElementById('save-reply-to-'+fullname) const btn = document.getElementById('save-reply-to-'+fullname)
@ -281,8 +279,13 @@ function post_comment(fullname){
// when called from top-level comment, clear top-level preview // when called from top-level comment, clear top-level preview
reset_preview('form-preview-'+id); reset_preview('form-preview-'+id);
// when called from comment reply, clear comment reply preview // when called from comment reply, clear comment reply preview
reset_preview('reply-edit-'+id); if(reset_preview('reply-edit-'+id)) {
// We are in a comment reply, need to find and hide the comment section
const replyArea = document.getElementById(`reply-to-${id}`);
if (replyArea) {
replyArea.classList.add('d-none');
}
}
} }
else { else {
if (data && data["error"]) document.getElementById('toast-post-error-text').innerText = data["error"]; if (data && data["error"]) document.getElementById('toast-post-error-text').innerText = data["error"];