Merge pull request #281 from philomena-dev/ts-misc

Convert miscellaneous scripts to TypeScript
This commit is contained in:
liamwhite 2024-06-09 13:03:31 -04:00 committed by GitHub
commit dfbe3dbc84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 12 additions and 15 deletions

View file

@ -4,11 +4,11 @@
* Warn users that their PM will be reviewed. * Warn users that their PM will be reviewed.
*/ */
import { $ } from './utils/dom'; import { $, hideEl, showEl } from './utils/dom';
function warnAboutPMs() { export function warnAboutPMs() {
const textarea = $('.js-toolbar-input'); const textarea = $<HTMLTextAreaElement>('.js-toolbar-input');
const warning = $('.js-hidden-warning'); const warning = $<HTMLDivElement>('.js-hidden-warning');
const imageEmbedRegex = /!+\[/g; const imageEmbedRegex = /!+\[/g;
if (!warning || !textarea) return; if (!warning || !textarea) return;
@ -17,12 +17,10 @@ function warnAboutPMs() {
const value = textarea.value; const value = textarea.value;
if (value.match(imageEmbedRegex)) { if (value.match(imageEmbedRegex)) {
warning.classList.remove('hidden'); showEl(warning);
} }
else if (!warning.classList.contains('hidden')) { else if (!warning.classList.contains('hidden')) {
warning.classList.add('hidden'); hideEl(warning);
} }
}); });
} }
export { warnAboutPMs };

View file

@ -1,6 +1,6 @@
import { inputDuplicatorCreator } from './input-duplicator'; import { inputDuplicatorCreator } from './input-duplicator';
function pollOptionCreator() { export function pollOptionCreator() {
inputDuplicatorCreator({ inputDuplicatorCreator({
addButtonSelector: '.js-poll-add-option', addButtonSelector: '.js-poll-add-option',
fieldSelector: '.js-poll-option', fieldSelector: '.js-poll-option',
@ -8,5 +8,3 @@ function pollOptionCreator() {
removeButtonSelector: '.js-option-remove', removeButtonSelector: '.js-option-remove',
}); });
} }
export { pollOptionCreator };

View file

@ -2,6 +2,7 @@
* Settings. * Settings.
*/ */
import { assertNotNull, assertNotUndefined } from './utils/assert';
import { $, $$ } from './utils/dom'; import { $, $$ } from './utils/dom';
import store from './utils/store'; import store from './utils/store';
@ -9,9 +10,9 @@ export function setupSettings() {
if (!$('#js-setting-table')) return; if (!$('#js-setting-table')) return;
const localCheckboxes = $$('[data-tab="local"] input[type="checkbox"]'); const localCheckboxes = $$<HTMLInputElement>('[data-tab="local"] input[type="checkbox"]');
const themeSelect = $('#user_theme'); const themeSelect = assertNotNull($<HTMLSelectElement>('#user_theme'));
const styleSheet = $('head link[rel="stylesheet"]'); const styleSheet = assertNotNull($<HTMLLinkElement>('head link[rel="stylesheet"]'));
// Local settings // Local settings
localCheckboxes.forEach(checkbox => { localCheckboxes.forEach(checkbox => {
@ -22,7 +23,7 @@ export function setupSettings() {
// Theme preview // Theme preview
themeSelect && themeSelect.addEventListener('change', () => { themeSelect && themeSelect.addEventListener('change', () => {
styleSheet.href = themeSelect.options[themeSelect.selectedIndex].dataset.themePath; styleSheet.href = assertNotUndefined(themeSelect.options[themeSelect.selectedIndex].dataset.themePath);
}); });
} }