diff --git a/.gitignore b/.gitignore index e2cac34fa97..257b6a357c3 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,4 @@ geckodriver.log chromedriver.log .node_repl_history .cursor-server +.gk/ 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..8c651cb0e29 100644 --- a/kitsune/sumo/static/sumo/js/flagit.js +++ b/kitsune/sumo/static/sumo/js/flagit.js @@ -1,15 +1,15 @@ document.addEventListener('DOMContentLoaded', () => { - const { reasonFilter, flaggedQueue, topicDropdown, updateStatusButton } = { + + 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 +24,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 +61,22 @@ 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(); - } + updateUrlParameter('set', 'reason', selectedReason); + fetchAndUpdateContent(new URL(window.location.href)); }); function handleDropdownChange() { @@ -103,6 +111,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 +119,8 @@ document.addEventListener('DOMContentLoaded', () => { } } }); - }) + }); } + handleDropdownChange(); });