From 1d21fb650bc7e922018ce83012e969124a9b458f Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sun, 9 Jan 2022 00:54:11 +0100 Subject: [PATCH] Setup TypeScript answerbox feature --- .../features/answerbox/comment/index.ts | 18 ++++++++++++++++++ .../retrospring/features/answerbox/index.ts | 19 ++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 app/javascript/retrospring/features/answerbox/comment/index.ts diff --git a/app/javascript/retrospring/features/answerbox/comment/index.ts b/app/javascript/retrospring/features/answerbox/comment/index.ts new file mode 100644 index 00000000..29604203 --- /dev/null +++ b/app/javascript/retrospring/features/answerbox/comment/index.ts @@ -0,0 +1,18 @@ +import registerEvents from "retrospring/utilities/registerEvents" +import { commentCharacterCountHandler } from "./count"; +import { commentDestroyHandler } from "./destroy"; +import { commentCreateHandler } from "./new"; +import { commentReportHandler } from "./report"; +import { commentSmileHandler } from "./smile"; +import { commentToggleHandler } from "./toggle"; + +export default (): void => { + registerEvents([ + { type: 'click', target: '[name=ab-comments]', handler: commentToggleHandler, 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: 'keyup', target: '[name=ab-comment-new]', handler: commentCreateHandler, global: true }, + { type: 'input', target: '[name=ab-comment-new]', handler: commentCharacterCountHandler, global: true } + ]); +} \ 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 846a1ca8..c67de9e7 100644 --- a/app/javascript/retrospring/features/answerbox/index.ts +++ b/app/javascript/retrospring/features/answerbox/index.ts @@ -1,10 +1,23 @@ -import { on } from 'retrospring/utilities/on'; +import registerEvents from 'utilities/registerEvents'; +import registerAnswerboxCommentEvents from './comment'; +import { answerboxDestroyHandler } from './destroy'; +import { answerboxReportHandler } from './report'; import { shareEventHandler } from './share'; +import { answerboxSmileHandler } from './smile'; +import { answerboxSubscribeHandler } from './subscribe'; export default (): void => { if ('share' in navigator) { document.body.classList.add('cap-web-share'); - - on('click', '[name=ab-share]', shareEventHandler); } + + registerEvents([ + { type: 'click', target: '[name=ab-share]', handler: shareEventHandler, global: true }, + { type: 'click', target: '[data-action=ab-submarine]', handler: answerboxSubscribeHandler, global: true }, + { 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(); }