diff --git a/app/javascript/retrospring/features/settings/index.ts b/app/javascript/retrospring/features/settings/index.ts index 138d756c..cbcc219c 100644 --- a/app/javascript/retrospring/features/settings/index.ts +++ b/app/javascript/retrospring/features/settings/index.ts @@ -1,18 +1,17 @@ -import {createDeleteEvent, createSubmitEvent} from "retrospring/features/settings/mute"; +import registerEvents from "utilities/registerEvents"; +import { muteDocumentHandler } from "./mute"; +import { profileHeaderChangeHandler, profilePictureChangeHandler } from "./crop"; +import { themeDocumentHandler, themeSubmitHandler } from "./theme"; +import { userSubmitHandler } from "./password"; export default (): void => { - const submit: HTMLButtonElement = document.getElementById('new-rule-submit') as HTMLButtonElement; - if (!submit || submit.classList.contains('js-initialized')) return; + muteDocumentHandler(); + themeDocumentHandler(); - const rulesList = document.querySelector('.js-rules-list'); - rulesList.querySelectorAll('.form-group:not(.js-initalized)').forEach(entry => { - const button = entry.querySelector('button') - button.onclick = createDeleteEvent(entry, button) - }); - const textEntry: HTMLButtonElement = document.getElementById('new-rule-text') as HTMLButtonElement; - const template: HTMLTemplateElement = document.getElementById('rule-template') as HTMLTemplateElement; - - submit.form.onsubmit = createSubmitEvent(submit, rulesList, textEntry, template) - - submit.classList.add('js-initialized') + registerEvents([ + { type: 'submit', target: document.querySelector('#update_theme'), handler: themeSubmitHandler }, + { type: 'submit', target: document.querySelector('#edit_user'), handler: userSubmitHandler }, + { type: 'change', target: document.querySelector('#user_profile_picture[type=file]'), handler: profilePictureChangeHandler }, + { type: 'change', target: document.querySelector('#user_profile_header[type=file]'), handler: profileHeaderChangeHandler } + ]); } \ No newline at end of file diff --git a/app/javascript/retrospring/features/settings/mute.ts b/app/javascript/retrospring/features/settings/mute.ts index a402538d..961cee0c 100644 --- a/app/javascript/retrospring/features/settings/mute.ts +++ b/app/javascript/retrospring/features/settings/mute.ts @@ -1,6 +1,6 @@ import Rails from '@rails/ujs'; -export function createSubmitEvent( +function createSubmitEvent( submit: HTMLButtonElement, rulesList: HTMLDivElement, textEntry: HTMLButtonElement, @@ -36,7 +36,7 @@ export function createSubmitEvent( }; } -export function createDeleteEvent( +function createDeleteEvent( entry: HTMLDivElement, deleteButton: HTMLButtonElement ): () => void { @@ -56,4 +56,21 @@ export function createDeleteEvent( } }) } +} + +export function muteDocumentHandler() { + const submit: HTMLButtonElement = document.getElementById('new-rule-submit') as HTMLButtonElement; + if (!submit || submit.classList.contains('js-initialized')) return; + + const rulesList = document.querySelector('.js-rules-list'); + rulesList.querySelectorAll('.form-group:not(.js-initalized)').forEach(entry => { + const button = entry.querySelector('button') + button.onclick = createDeleteEvent(entry, button) + }); + const textEntry: HTMLButtonElement = document.getElementById('new-rule-text') as HTMLButtonElement; + const template: HTMLTemplateElement = document.getElementById('rule-template') as HTMLTemplateElement; + + submit.form.onsubmit = createSubmitEvent(submit, rulesList, textEntry, template) + + submit.classList.add('js-initialized'); } \ No newline at end of file