Fix broken experience level button in moderation panel (#11797)

This commit is contained in:
rhymes 2020-12-08 10:20:35 +01:00 committed by GitHub
parent ce9272c914
commit 9870021eec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 48 deletions

View file

@ -116,15 +116,22 @@ function clearExpLevels() {
});
}
async function updateExperienceLevel(currentUserId, articleId, rating, group) {
export async function updateExperienceLevel(
currentUserId,
articleId,
rating,
group,
) {
try {
const response = await request('/rating_votes', {
method: 'POST',
body: JSON.stringify({
user_id: currentUserId,
article_id: articleId,
rating,
group,
rating_vote: {
user_id: currentUserId,
article_id: articleId,
rating,
group,
},
}),
});

View file

@ -1,3 +1,5 @@
import { updateExperienceLevel } from '../actionsPanel/actionsPanel';
function applyReactedClass(category) {
const upVote = document.querySelector("[data-category='thumbsup']");
const downVote = document.querySelector("[data-category='thumbsdown']");
@ -48,49 +50,6 @@ async function updateMainReactions(reactableType, category, reactableId) {
}
// Experience-Level JS
function clearExpLevels() {
Array.from(
document.getElementsByClassName('level-rating-button selected'),
).forEach((el) => {
el.classList.remove('selected');
});
}
async function updateExperienceLevel(currentUserId, articleId, rating, group) {
try {
const response = await fetch('/rating_votes', {
method: 'POST',
headers: {
Accept: 'application/json',
'X-CSRF-Token': window.csrfToken,
'Content-Type': 'application/json',
},
credentials: 'same-origin',
body: JSON.stringify({
user_id: currentUserId,
article_id: articleId,
rating,
group,
}),
});
const outcome = await response.json();
if (outcome.result === 'Success') {
clearExpLevels();
document
.getElementById(`js__rating__vote__${rating}`)
.classList.add('selected');
} else {
// eslint-disable-next-line no-alert
alert(outcome.error);
}
} catch (error) {
// eslint-disable-next-line no-alert
alert(error);
}
}
Array.from(document.getElementsByClassName('level-rating-button')).forEach(
(btn) => {
btn.addEventListener('click', () => {