Skip to content

Commit

Permalink
Merge pull request #6280 from akatsoulas/moderation-default-spam
Browse files Browse the repository at this point in the history
Default moderation queue filtering to spam
  • Loading branch information
akatsoulas authored Oct 9, 2024
2 parents 0c743ca + a6df7a2 commit ad827ac
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ geckodriver.log
chromedriver.log
.node_repl_history
.cursor-server
.gk/
7 changes: 6 additions & 1 deletion kitsune/flagit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)


Expand Down
50 changes: 30 additions & 20 deletions kitsune/sumo/static/sumo/js/flagit.js
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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, {
Expand All @@ -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() {
Expand Down Expand Up @@ -103,14 +111,16 @@ 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';
}
}
}
});
})
});
}

handleDropdownChange();
});

0 comments on commit ad827ac

Please sign in to comment.