From 50070d9afceccc0ffd3fb024aaf60a28f7e1c56d Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 8 Jan 2022 02:51:23 +0100 Subject: [PATCH] Setup TypeScript moderation feature --- app/javascript/packs/application.ts | 4 +++- .../features/moderation/comment/index.ts | 14 ++++++++++++++ .../retrospring/features/moderation/index.ts | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 app/javascript/retrospring/features/moderation/comment/index.ts create mode 100644 app/javascript/retrospring/features/moderation/index.ts diff --git a/app/javascript/packs/application.ts b/app/javascript/packs/application.ts index 7770be0c..cf9c3bcd 100644 --- a/app/javascript/packs/application.ts +++ b/app/javascript/packs/application.ts @@ -6,6 +6,7 @@ import initSettings from 'retrospring/features/settings/index'; import initLists from 'retrospring/features/lists'; import initQuestionbox from 'retrospring/features/questionbox'; import initQuestion from 'retrospring/features/question'; +import initModeration from 'retrospring/features/moderation'; start(); document.addEventListener('turbolinks:load', initAnswerbox); @@ -14,4 +15,5 @@ document.addEventListener('DOMContentLoaded', initUser); document.addEventListener('turbolinks:load', initSettings); document.addEventListener('DOMContentLoaded', initLists); document.addEventListener('DOMContentLoaded', initQuestionbox); -document.addEventListener('DOMContentLoaded', initQuestion); \ No newline at end of file +document.addEventListener('DOMContentLoaded', initQuestion); +document.addEventListener('DOMContentLoaded', initModeration); \ No newline at end of file diff --git a/app/javascript/retrospring/features/moderation/comment/index.ts b/app/javascript/retrospring/features/moderation/comment/index.ts new file mode 100644 index 00000000..7268c40a --- /dev/null +++ b/app/javascript/retrospring/features/moderation/comment/index.ts @@ -0,0 +1,14 @@ +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 } + ]); +} \ No newline at end of file diff --git a/app/javascript/retrospring/features/moderation/index.ts b/app/javascript/retrospring/features/moderation/index.ts new file mode 100644 index 00000000..53bcbedb --- /dev/null +++ b/app/javascript/retrospring/features/moderation/index.ts @@ -0,0 +1,19 @@ +import registerEvents from 'utilities/registerEvents'; +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 }, + { type: 'change', target: '[name="permaban"][type="checkbox"]', handler: permanentBanCheckboxHandler, global: true }, + { type: 'submit', target: '#modal-ban form', handler: banFormHandler, global: true } + ]); + + registerCommentEvents(); +} \ No newline at end of file