implement a nasty hack to fix a bug

This commit is contained in:
mystie 2024-09-28 19:46:43 +03:00
parent ea2378fac7
commit 98d8b9e9fe

View file

@ -170,7 +170,7 @@
{% else %} {% else %}
<li><button class="dropdown-item" hx-post="{{ url_for('api.unpinQuestion', question_id=item.question.id) }}" hx-target="#top-response-container" hx-swap="none"><i class="bi bi-pin-angle me-1"></i> Unpin</button></li> <li><button class="dropdown-item" hx-post="{{ url_for('api.unpinQuestion', question_id=item.question.id) }}" hx-target="#top-response-container" hx-swap="none"><i class="bi bi-pin-angle me-1"></i> Unpin</button></li>
{% endif %} {% endif %}
<li><button class="bg-hover-danger text-danger dropdown-item" hx-post="{{ url_for('api.returnToInbox', question_id=item.question.id) }}" hx-target="#question-{{ item.question.id }}" hx-swap="none"><i class="bi bi-arrow-return-left me-1"></i> Return to inbox</button></li> <li><button class="bg-hover-danger text-danger dropdown-item" hx-post="{{ url_for('api.returnToInbox', question_id=item.question.id) }}" hx-target="#top-response-container" hx-swap="none" data-returntoinbox data-target="question-{{ item.question.id }}"><i class="bi bi-arrow-return-left me-1"></i> Return to inbox</button></li>
{% endif %} {% endif %}
</ul> </ul>
</div> </div>
@ -292,9 +292,12 @@
const parsed = JSON.parse(jsonResponse); const parsed = JSON.parse(jsonResponse);
const alertType = event.detail.successful ? 'success' : 'danger'; const alertType = event.detail.successful ? 'success' : 'danger';
msgType = event.detail.successful ? parsed.message : parsed.error; msgType = event.detail.successful ? parsed.message : parsed.error;
const targetElementId = event.detail.target.id; let targetElementId = event.detail.target.id;
if (targetElementId != "question-count") { if (targetElementId != "question-count") {
if (document.getElementById(targetElementId) && targetElementId.includes("question-")) { // WARNING: HACK
// we use this hack to avoid triggering the event listener twice when making a request to api.returnToInbox
if (document.getElementById(targetElementId) && event.detail.requestConfig.elt.dataset.returntoinbox === "") {
targetElementId = event.detail.requestConfig.elt.dataset.target;
document.getElementById(targetElementId).outerHTML = ''; document.getElementById(targetElementId).outerHTML = '';
} }
if (msgType) { if (msgType) {