Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default moderation queue filtering to spam #6280

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});