From 6e32fcd05c5193b3f963c66e64bc4d4bcea3b60d Mon Sep 17 00:00:00 2001 From: krmax44 Date: Thu, 17 Oct 2024 16:03:04 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20mildly=20improve=20request?= =?UTF-8?q?.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/javascript/request.ts | 37 +++++++++++++++------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/frontend/javascript/request.ts b/frontend/javascript/request.ts index 398d46ffa..48315f22b 100644 --- a/frontend/javascript/request.ts +++ b/frontend/javascript/request.ts @@ -14,9 +14,8 @@ const initRequestPage = (): void => { console.debug('Init request page...') // init message containers - const messagesContainer = document.getElementById( - 'correspondence' - ) as HTMLElement + const messagesContainer = + document.querySelector('#correspondence')! const messages: Message[] = parseMessageContainers() if (messages.length === 0) return @@ -31,11 +30,9 @@ const initRequestPage = (): void => { } // init timeline - // eslint-disable-next-line no-new new Timeline(messagesContainer, messages) // init ScrollIndicator on mobile view - // eslint-disable-next-line no-new new ScrollIndicator(messagesContainer) initTabs() @@ -65,7 +62,7 @@ const initRequestPage = (): void => { }) const tabLinks = document.querySelectorAll('a[data-tabgo]') - Array.from(tabLinks).forEach((tabLink) => { + tabLinks.forEach((tabLink) => { tabLink.addEventListener('click', function (this: HTMLElement) { const hrefAttr = this.attributes.getNamedItem('href') if (hrefAttr === null) { @@ -95,7 +92,7 @@ const initRequestPage = (): void => { } const fieldFillLinks = document.querySelectorAll('[data-fieldname]') - Array.from(fieldFillLinks).forEach((el) => { + fieldFillLinks.forEach((el) => { el.addEventListener('click', fieldFillLinkClick) }) @@ -266,7 +263,7 @@ const applyMarkToMessage = ( span[1] - charIndex, content.length ) - // eslint-disable-next-line no-new + new Tooltip(mark, { html: true, title: '' @@ -339,10 +336,9 @@ const scrollToAnchor = (messages: Message[]): void => { } const initTabs = (): void => { - const container = document.querySelector('.alpha-tabs') as HTMLElement - const tabCollection = container.getElementsByTagName('A') - Array.from(tabCollection).forEach((tab) => { - // eslint-disable-next-line no-new + const container = document.querySelector('.alpha-tabs') + const tabCollection = container?.querySelectorAll('a') + tabCollection?.forEach((tab) => { new Tab(tab) }) @@ -373,11 +369,11 @@ const initCorrespondenceTopMenu = ( messagesContainer: HTMLElement, messages: Message[] ): void => { - const expandAllLink = document.querySelector( + const expandAllLink = document.querySelector( '.js-trigger-expand-all-messages' - ) as HTMLElement + ) - expandAllLink.addEventListener('click', (e: MouseEvent) => { + expandAllLink?.addEventListener('click', (e: MouseEvent) => { e.preventDefault() expandAll(messagesContainer, messages) }) @@ -446,7 +442,7 @@ const initSetStatusForm = (): void => { let refusalInputIsVisible = false const setStatus = (): void => { - const container = document.querySelector('.status-refusal') as HTMLElement + const container = document.querySelector('.status-refusal') if (container !== null) { const resolutionElement = document.querySelector('#id_resolution') @@ -473,13 +469,12 @@ const initReplyForm = (): void => { return } - const replyContainerHelper = document.getElementById( - 'reply-form-helper' - ) as HTMLElement + const replyContainerHelper = + document.querySelector('#reply-form-helper')! const replyContainerOffsetTop = replyContainerHelper.offsetTop - const stickyButton = replyContainer.querySelector( + const stickyButton = replyContainer.querySelector( '.reply-form__toggle-sticky-btn' - ) as HTMLElement + )! let stickyModeEnabled = false let userScrolledPastEnd = false