Remove legacy smile TypeScript functionality

This commit is contained in:
Andreas Nedbal 2023-10-31 23:33:30 +01:00 committed by Andreas Nedbal
parent 4e434dd268
commit e318763801
4 changed files with 0 additions and 122 deletions

View File

@ -2,7 +2,6 @@ import registerEvents from "retrospring/utilities/registerEvents";
import { commentDestroyHandler } from "./destroy";
import { commentComposeEnd, commentComposeStart, commentCreateClickHandler, commentCreateKeyboardHandler } from "./new";
import { commentReportHandler } from "./report";
import { commentSmileHandler } from "./smile";
import { commentToggleHandler } from "./toggle";
import { commentHotkeyHandler } from "retrospring/features/answerbox/comment/hotkey";
@ -10,7 +9,6 @@ export default (): void => {
registerEvents([
{ type: 'click', target: '[name=ab-comments]', handler: commentToggleHandler, global: true },
{ type: 'click', target: '[name=ab-open-and-comment]', handler: commentHotkeyHandler, global: true },
{ type: 'click', target: '[name=ab-smile-comment]', handler: commentSmileHandler, global: true },
{ type: 'click', target: '[data-action=ab-comment-report]', handler: commentReportHandler, global: true },
{ type: 'click', target: '[data-action=ab-comment-destroy]', handler: commentDestroyHandler, global: true },
{ type: 'compositionstart', target: '[name=ab-comment-new]', handler: commentComposeStart, global: true },

View File

@ -1,59 +0,0 @@
import { post } from '@rails/request.js';
import I18n from 'retrospring/i18n';
import { showNotification, showErrorNotification } from 'utilities/notifications';
export function commentSmileHandler(event: Event): void {
const button = event.target as HTMLButtonElement;
const id = button.dataset.cId;
const action = button.dataset.action;
let count = Number(document.querySelector(`#ab-comment-smile-count-${id}`).innerHTML);
let success = false;
let targetUrl;
if (action === 'smile') {
count++;
targetUrl = '/ajax/create_comment_smile';
}
else if (action === 'unsmile') {
count--;
targetUrl = '/ajax/destroy_comment_smile';
}
button.disabled = true;
post(targetUrl, {
body: {
id: id
},
contentType: 'application/json'
})
.then(async response => {
const data = await response.json;
success = data.success;
if (success) {
document.querySelector(`#ab-comment-smile-count-${id}`).innerHTML = String(count);
}
showNotification(data.message, data.success);
})
.catch(err => {
console.log(err);
showErrorNotification(I18n.translate('frontend.error.message'));
})
.finally(() => {
button.disabled = false;
if (success) {
switch(action) {
case 'smile':
button.dataset.action = 'unsmile';
break;
case 'unsmile':
button.dataset.action = 'smile';
break;
}
}
});
}

View File

@ -2,13 +2,11 @@ import registerEvents from 'utilities/registerEvents';
import registerAnswerboxCommentEvents from './comment';
import { answerboxDestroyHandler } from './destroy';
import { answerboxReportHandler } from './report';
import { answerboxSmileHandler } from './smile';
export default (): void => {
registerEvents([
{ type: 'click', target: '[data-action=ab-report]', handler: answerboxReportHandler, global: true },
{ type: 'click', target: '[data-action=ab-destroy]', handler: answerboxDestroyHandler, global: true },
{ type: 'click', target: '[name=ab-smile]', handler: answerboxSmileHandler, global: true }
]);
registerAnswerboxCommentEvents();

View File

@ -1,59 +0,0 @@
import { post } from '@rails/request.js';
import I18n from 'retrospring/i18n';
import { showNotification, showErrorNotification } from 'utilities/notifications';
export function answerboxSmileHandler(event: Event): void {
const button = event.target as HTMLButtonElement;
const id = button.dataset.aId;
const action = button.dataset.action;
let count = Number(document.querySelector(`#ab-smile-count-${id}`).innerHTML);
let success = false;
let targetUrl;
if (action === 'smile') {
count++;
targetUrl = '/ajax/create_smile';
}
else if (action === 'unsmile') {
count--;
targetUrl = '/ajax/destroy_smile';
}
button.disabled = true;
post(targetUrl, {
body: {
id: id
},
contentType: 'application/json'
})
.then(async response => {
const data = await response.json;
success = data.success;
if (success) {
document.querySelector(`#ab-smile-count-${id}`).innerHTML = String(count);
}
showNotification(data.message, data.success);
})
.catch(err => {
console.log(err);
showErrorNotification(I18n.translate('frontend.error.message'));
})
.finally(() => {
button.disabled = false;
if (success) {
switch(action) {
case 'smile':
button.dataset.action = 'unsmile';
break;
case 'unsmile':
button.dataset.action = 'smile';
break;
}
}
});
}