Skip to content

Commit

Permalink
Default moderation queue filtering to spam
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsoulas committed Oct 8, 2024
1 parent 0c743ca commit e464b6e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
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
54 changes: 35 additions & 19 deletions kitsune/sumo/static/sumo/js/flagit.js
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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, {
Expand All @@ -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() {
Expand Down Expand Up @@ -103,14 +117,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 e464b6e

Please sign in to comment.