From 3cabd39b89132afe9f2e7fd6f56877dc09f5e919 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Mon, 18 Jul 2022 22:29:48 +0200 Subject: [PATCH] Remove vote functionality from TypeScript --- .../retrospring/features/moderation/index.ts | 2 - .../retrospring/features/moderation/vote.ts | 66 ------------------- 2 files changed, 68 deletions(-) delete mode 100644 app/javascript/retrospring/features/moderation/vote.ts diff --git a/app/javascript/retrospring/features/moderation/index.ts b/app/javascript/retrospring/features/moderation/index.ts index 53bcbedb..f791a799 100644 --- a/app/javascript/retrospring/features/moderation/index.ts +++ b/app/javascript/retrospring/features/moderation/index.ts @@ -3,11 +3,9 @@ import registerCommentEvents from './comment'; import { banCheckboxHandler, banFormHandler, permanentBanCheckboxHandler } from './ban'; import { destroyReportHandler } from './destroy'; import { privilegeCheckHandler } from './privilege'; -import { voteReportHandler } from './vote'; export default (): void => { registerEvents([ - { type: 'click', target: '[name=mod-vote]', handler: voteReportHandler, global: true }, { type: 'click', target: '[type=checkbox][name=check-your-privileges]', handler: privilegeCheckHandler, global: true }, { type: 'click', target: '[name=mod-delete-report]', handler: destroyReportHandler, global: true }, { type: 'change', target: '[name="ban"][type="checkbox"]', handler: banCheckboxHandler, global: true }, diff --git a/app/javascript/retrospring/features/moderation/vote.ts b/app/javascript/retrospring/features/moderation/vote.ts deleted file mode 100644 index c17eaec1..00000000 --- a/app/javascript/retrospring/features/moderation/vote.ts +++ /dev/null @@ -1,66 +0,0 @@ -import Rails from '@rails/ujs'; - -import I18n from 'retrospring/i18n'; -import { showNotification, showErrorNotification } from 'utilities/notifications'; - -export function voteReportHandler(event: Event): void { - const button = event.target as HTMLButtonElement; - const id = button.dataset.id; - const action = button.dataset.action; - const upvote = button.dataset.voteType === 'upvote'; - button.disabled = true; - - let success = false; - let targetUrl; - - if (action === 'vote') { - targetUrl = '/ajax/mod/create_vote'; - } - else if (action === 'unvote') { - targetUrl = '/ajax/mod/destroy_vote'; - } - - Rails.ajax({ - url: targetUrl, - type: 'POST', - data: new URLSearchParams({ - id: id, - upvote: String(upvote) - }).toString(), - success: (data) => { - success = data.success; - if (success) { - document.querySelector(`span#mod-count-${id}`).innerHTML = data.count; - } - - showNotification(data.message); - }, - error: (data, status, xhr) => { - console.log(data, status, xhr); - showErrorNotification(I18n.translate('frontend.error.message')); - }, - complete: () => { - if (success) { - const inverseVoteButton = document.querySelector(`[name=mod-vote][data-id="${id}"][data-vote-type="${ upvote ? 'downvote' : 'upvote' }"]`); - const inverseUnvoteButton = document.querySelector(`[name=mod-vote][data-id="${id}"][data-vote-type="${ upvote ? 'downvote' : 'upvote' }"]`); - - switch (action) { - case 'vote': - button.disabled = true; - button.dataset.action = 'unvote'; - - inverseVoteButton.disabled = false; - inverseVoteButton.dataset.action = 'unvote'; - break; - case 'unvote': - button.disabled = false; - button.dataset.action = 'vote'; - - inverseUnvoteButton.disabled = false; - inverseUnvoteButton.dataset.action = 'vote'; - break; - } - } - } - }); -} \ No newline at end of file