From e464b6ecb605ede44edc932ad5ac809809275d11 Mon Sep 17 00:00:00 2001 From: Tasos Katsoulas Date: Tue, 8 Oct 2024 18:46:42 +0300 Subject: [PATCH] Default moderation queue filtering to spam --- kitsune/flagit/views.py | 7 +++- kitsune/sumo/static/sumo/js/flagit.js | 54 +++++++++++++++++---------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/kitsune/flagit/views.py b/kitsune/flagit/views.py index d09f9577f29..2b19e722c94 100644 --- a/kitsune/flagit/views.py +++ b/kitsune/flagit/views.py @@ -88,7 +88,12 @@ def flagged_queue(request): return render( request, "flagit/queue.html", - {"objects": objects, "locale": request.LANGUAGE_CODE, "reasons": FlaggedObject.REASONS}, + { + "objects": objects, + "locale": request.LANGUAGE_CODE, + "reasons": FlaggedObject.REASONS, + "selected_reason": reason, + }, ) diff --git a/kitsune/sumo/static/sumo/js/flagit.js b/kitsune/sumo/static/sumo/js/flagit.js index 46d97c62be1..d9329694c9e 100644 --- a/kitsune/sumo/static/sumo/js/flagit.js +++ b/kitsune/sumo/static/sumo/js/flagit.js @@ -1,15 +1,16 @@ document.addEventListener('DOMContentLoaded', () => { - const { reasonFilter, flaggedQueue, topicDropdown, updateStatusButton } = { + let isInitialLoad = true; + + const { reasonFilter, flaggedQueue } = { reasonFilter: document.getElementById('flagit-reason-filter'), flaggedQueue: document.getElementById('flagged-queue'), }; - function disableUpdateStatusButtons() { const updateStatusButtons = document.querySelectorAll('form.update.inline-form input[type="submit"]'); updateStatusButtons.forEach(button => { button.disabled = true; - }) + }); } disableUpdateStatusButtons(); @@ -24,12 +25,23 @@ document.addEventListener('DOMContentLoaded', () => { url.searchParams.delete(param); window.history.replaceState({}, '', url.pathname); } - } - else if (action === 'get') { + } else if (action === 'get') { return url.searchParams.get(param); } } + async function fetchAndUpdateContent(url) { + const response = await fetchData(url); + if (response) { + const data = await response.text(); + const parser = new DOMParser(); + const doc = parser.parseFromString(data, 'text/html'); + flaggedQueue.innerHTML = doc.querySelector('#flagged-queue').innerHTML; + disableUpdateStatusButtons(); + handleDropdownChange(); + } + } + async function fetchData(url, options = {}) { try { const response = await fetch(url, { @@ -50,25 +62,27 @@ document.addEventListener('DOMContentLoaded', () => { } } - const reason = updateUrlParameter('get', 'reason'); - if (reason) { + let reason = updateUrlParameter('get', 'reason'); + + if (!reason) { + reason = 'spam'; + updateUrlParameter('set', 'reason', reason); + reasonFilter.value = 'spam'; + fetchAndUpdateContent(new URL(window.location.href)); + } else { reasonFilter.value = reason; } + reasonFilter.addEventListener('change', async () => { const selectedReason = reasonFilter.value; - updateUrlParameter('set', 'reason', selectedReason); - - const url = new URL(window.location.href); - const response = await fetchData(url); - if (response) { - const data = await response.text(); - const parser = new DOMParser(); - const doc = parser.parseFromString(data, 'text/html'); - flaggedQueue.innerHTML = doc.querySelector('#flagged-queue').innerHTML; - disableUpdateStatusButtons(); - handleDropdownChange(); + if (isInitialLoad) { + isInitialLoad = false; + return; } + + updateUrlParameter('set', 'reason', selectedReason); + fetchAndUpdateContent(new URL(window.location.href)); }); function handleDropdownChange() { @@ -103,6 +117,7 @@ document.addEventListener('DOMContentLoaded', () => { const data = await response.json(); currentTopic.textContent = data.updated_topic; currentTopic.classList.add('updated'); + const updateStatusSelect = updateButton.previousElementSibling; if (updateStatusSelect && updateStatusSelect.tagName === 'SELECT') { updateStatusSelect.value = '1'; @@ -110,7 +125,8 @@ document.addEventListener('DOMContentLoaded', () => { } } }); - }) + }); } + handleDropdownChange(); });