Skip to content

Commit

Permalink
♻️ mildly improve request.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
krmax44 committed Oct 28, 2024
1 parent 42e1ee1 commit 6e32fcd
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions frontend/javascript/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLElement>('#correspondence')!
const messages: Message[] = parseMessageContainers()
if (messages.length === 0) return

Expand All @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})

Expand Down Expand Up @@ -266,7 +263,7 @@ const applyMarkToMessage = (
span[1] - charIndex,
content.length
)
// eslint-disable-next-line no-new

new Tooltip(mark, {
html: true,
title: '<i class="fa fa-info-circle"></i>'
Expand Down Expand Up @@ -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<HTMLElement>('.alpha-tabs')
const tabCollection = container?.querySelectorAll('a')
tabCollection?.forEach((tab) => {
new Tab(tab)
})

Expand Down Expand Up @@ -373,11 +369,11 @@ const initCorrespondenceTopMenu = (
messagesContainer: HTMLElement,
messages: Message[]
): void => {
const expandAllLink = document.querySelector(
const expandAllLink = document.querySelector<HTMLElement>(
'.js-trigger-expand-all-messages'
) as HTMLElement
)

expandAllLink.addEventListener('click', (e: MouseEvent) => {
expandAllLink?.addEventListener('click', (e: MouseEvent) => {
e.preventDefault()
expandAll(messagesContainer, messages)
})
Expand Down Expand Up @@ -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<HTMLElement>('.status-refusal')
if (container !== null) {
const resolutionElement =
document.querySelector<HTMLInputElement>('#id_resolution')
Expand All @@ -473,13 +469,12 @@ const initReplyForm = (): void => {
return
}

const replyContainerHelper = document.getElementById(
'reply-form-helper'
) as HTMLElement
const replyContainerHelper =
document.querySelector<HTMLElement>('#reply-form-helper')!
const replyContainerOffsetTop = replyContainerHelper.offsetTop
const stickyButton = replyContainer.querySelector(
const stickyButton = replyContainer.querySelector<HTMLElement>(
'.reply-form__toggle-sticky-btn'
) as HTMLElement
)!
let stickyModeEnabled = false
let userScrolledPastEnd = false

Expand Down

0 comments on commit 6e32fcd

Please sign in to comment.