From e3187638016f720007d2b78b3f7b8a493b8b406a Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 31 Oct 2023 23:33:30 +0100 Subject: [PATCH] Remove legacy smile TypeScript functionality --- .../features/answerbox/comment/index.ts | 2 - .../features/answerbox/comment/smile.ts | 59 ------------------- .../retrospring/features/answerbox/index.ts | 2 - .../retrospring/features/answerbox/smile.ts | 59 ------------------- 4 files changed, 122 deletions(-) delete mode 100644 app/javascript/retrospring/features/answerbox/comment/smile.ts delete mode 100644 app/javascript/retrospring/features/answerbox/smile.ts diff --git a/app/javascript/retrospring/features/answerbox/comment/index.ts b/app/javascript/retrospring/features/answerbox/comment/index.ts index 3e5a0f81..649ec286 100644 --- a/app/javascript/retrospring/features/answerbox/comment/index.ts +++ b/app/javascript/retrospring/features/answerbox/comment/index.ts @@ -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 }, diff --git a/app/javascript/retrospring/features/answerbox/comment/smile.ts b/app/javascript/retrospring/features/answerbox/comment/smile.ts deleted file mode 100644 index b80d5bd5..00000000 --- a/app/javascript/retrospring/features/answerbox/comment/smile.ts +++ /dev/null @@ -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; - } - } - }); -} \ No newline at end of file diff --git a/app/javascript/retrospring/features/answerbox/index.ts b/app/javascript/retrospring/features/answerbox/index.ts index cf088f8b..423d9ef4 100644 --- a/app/javascript/retrospring/features/answerbox/index.ts +++ b/app/javascript/retrospring/features/answerbox/index.ts @@ -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(); diff --git a/app/javascript/retrospring/features/answerbox/smile.ts b/app/javascript/retrospring/features/answerbox/smile.ts deleted file mode 100644 index fc154b0d..00000000 --- a/app/javascript/retrospring/features/answerbox/smile.ts +++ /dev/null @@ -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; - } - } - }); -} \ No newline at end of file