Remove moderation comment functionality from TypeScript

This commit is contained in:
Andreas Nedbal 2022-07-18 23:59:00 +02:00 committed by Karina Kwiatek
parent b7bdf2de02
commit 5c3d003c2b
6 changed files with 0 additions and 138 deletions

View File

@ -1,19 +0,0 @@
export function commentCharacterHandler(event: Event): void {
const input = event.target as HTMLInputElement;
const id = input.dataset.id;
const counter = document.querySelector(`#mod-comment-charcount-${id}`);
const group = document.querySelector(`[name=mod-comment-new-group][data-id="${id}"]`);
if (group.classList.contains('has-error')) {
group.classList.remove('has-error');
}
counter.innerHTML = String(160 - input.value.length);
if (Number(counter.innerHTML) < 0) {
counter.classList.remove('text-muted');
counter.classList.add('text-danger');
} else {
counter.classList.remove('text-danger');
counter.classList.add('text-muted');
}
}

View File

@ -1,48 +0,0 @@
import Rails from '@rails/ujs';
import swal from 'sweetalert';
import I18n from 'retrospring/i18n';
import { showNotification, showErrorNotification } from 'utilities/notifications';
export function destroyCommentHandler(event: Event): void {
const button = event.target as HTMLButtonElement;
const id = button.dataset.id;
event.preventDefault();
button.disabled = true;
swal({
title: I18n.translate('frontend.destroy_comment.confirm.title'),
text: I18n.translate('frontend.destroy_comment.confirm.text'),
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: I18n.translate('views.actions.delete'),
cancelButtonText: I18n.translate('views.actions.cancel'),
closeOnConfirm: true
}, (returnValue) => {
if (returnValue === false) {
button.disabled = false;
return;
}
Rails.ajax({
url: '/ajax/mod/destroy_comment',
type: 'POST',
data: new URLSearchParams({
comment: id
}).toString(),
success: (data) => {
if (!data.success) return false;
showNotification(data.message);
document.querySelector(`[data-comment-id="${id}"]`).remove();
},
error: (data, status, xhr) => {
console.log(data, status, xhr);
showErrorNotification(I18n.translate('frontend.error.message'));
button.disabled = false;
}
});
});
}

View File

@ -1,14 +0,0 @@
import registerEvents from 'utilities/registerEvents';
import { commentCharacterHandler } from './count';
import { destroyCommentHandler } from './destroy';
import { commentCreateHandler } from './new';
import { entryCommentToggle } from './toggle';
export default (): void => {
registerEvents([
{ type: 'click', target: '[name=mod-comments]', handler: entryCommentToggle, global: true },
{ type: 'input', target: '[name=mod-comment-new]', handler: commentCharacterHandler, global: true },
{ type: 'click', target: '[data-action=mod-comment-destroy]', handler: destroyCommentHandler, global: true },
{ type: 'keyup', target: '[name=mod-comment-new]', handler: commentCreateHandler, global: true }
]);
}

View File

@ -1,48 +0,0 @@
import Rails from '@rails/ujs';
import I18n from 'retrospring/i18n';
import { showNotification, showErrorNotification } from 'utilities/notifications';
export function commentCreateHandler(event: KeyboardEvent): boolean {
const input = event.target as HTMLInputElement;
const id = input.dataset.id;
const counter = document.querySelector(`#mod-comment-charcount-${id}`);
const group = document.querySelector(`[name=mod-comment-new-group][data-id="${id}"]`);
if (event.which === 13) {
event.preventDefault();
if (input.value.length > 160) {
group.classList.add('has-error');
return true;
}
input.disabled = true;
Rails.ajax({
url: '/ajax/mod/create_comment',
type: 'POST',
data: new URLSearchParams({
id: id,
comment: input.value
}).toString(),
success: (data) => {
if (data.success) {
document.querySelector(`#mod-comments-${id}`).insertAdjacentHTML('beforeend', data.render);
document.querySelector(`#mod-comment-count-${id}`).innerHTML = data.count;
input.value = '';
counter.innerHTML = String(160);
}
showNotification(data.message, data.success);
},
error: (data, status, xhr) => {
console.log(data, status, xhr);
showErrorNotification(I18n.translate('frontend.error.message'));
},
complete: () => {
input.disabled = false;
}
});
}
}

View File

@ -1,6 +0,0 @@
export function entryCommentToggle(event: Event): void {
const button = event.target as HTMLButtonElement;
const id = button.dataset.id;
document.querySelector(`#mod-comments-section-${id}`).classList.toggle('d-none');
}

View File

@ -1,5 +1,4 @@
import registerEvents from 'utilities/registerEvents';
import registerCommentEvents from './comment';
import { banCheckboxHandler, banFormHandler, permanentBanCheckboxHandler } from './ban';
import { destroyReportHandler } from './destroy';
import { privilegeCheckHandler } from './privilege';
@ -12,6 +11,4 @@ export default (): void => {
{ type: 'change', target: '[name="permaban"][type="checkbox"]', handler: permanentBanCheckboxHandler, global: true },
{ type: 'submit', target: '#modal-ban form', handler: banFormHandler, global: true }
]);
registerCommentEvents();
}